@@ -214,10 +214,10 @@ class FFReplay(object):
214214
215215 def __init__ (self ,length = 500 , delay = 1 ):
216216 #: duration of the effect (ms)
217- self .length = length
217+ self .length = int ( length )
218218
219219 #: delay before effect should start playing
220- self .delay = delay
220+ self .delay = int ( delay )
221221
222222
223223 def __str__ (s ):
@@ -235,10 +235,10 @@ class FFTrigger(object):
235235
236236 def __init__ (self ,button = 0 , interval = 0 ):
237237 #: number of the button triggering the effect
238- self .button = button
238+ self .button = int ( button )
239239
240240 #: controls how soon the effect can be re-triggered (ms)
241- self .interval = interval
241+ self .interval = int ( interval )
242242
243243
244244 def __str__ (s ):
@@ -266,23 +266,25 @@ class FFEnvelope(object):
266266
267267 __slots__ = 'attack_length' , 'attack_level' , 'fade_length' , 'fade_level'
268268
269+ MAX_LENGTH = 0x7FFF
270+ MAX_LEVEL = 0x7FFF
269271 def __init__ (self ,attack_length = 150 , attack_level = 0x3fff , fade_length = 1000 , fade_level = 0 ):
270272 #: duration of the attck (ms)
271- self .attack_length = attack_length
273+ self .attack_length = int ( attack_length )
272274
273275 #: level at the beginning of the attack
274- self .attack_level = attack_level
276+ self .attack_level = int ( attack_level )
275277
276278 #: duration of the fade (ms)
277- self .fade_length = fade_length
279+ self .fade_length = int ( fade_length )
278280
279281 #: level at the end of the fade
280- self .fade_level = fade_level
282+ self .fade_level = int ( fade_level )
281283
282284
283285
284286 def __str__ (s ):
285- msg = 'ff_envelope attack level {:d } {:d}ms fade to {:d } over {:d} ms'
287+ msg = 'ff_envelope attack level 0x{:x } {:d}ms fade to 0x{:x } over {:d} ms'
286288 return msg .format (int (s .attack_level ), int (s .attack_length ), int (s .fade_level ), int (s .fade_length ))
287289
288290class FFConstantEffect (object ):
@@ -295,7 +297,7 @@ class FFConstantEffect(object):
295297
296298 def __init__ (self ,level = 0x3ff , envelope = FFEnvelope ()):
297299 #: beginning strength of the effect; may be negative
298- self .level = level
300+ self .level = int ( level )
299301
300302 if type (envelope ) is not FFEnvelope :
301303 raise Exception ("FFConstantEffect: envelope %s is not FFEnvelope" % (envelope ))
@@ -305,7 +307,7 @@ def __init__(self,level=0x3ff, envelope=FFEnvelope()):
305307
306308
307309 def __str__ (s ):
308- msg = 'ff_constant effect start level {:d } envelope {:s}'
310+ msg = 'ff_constant effect start level 0x{:x } envelope {:s}'
309311 return msg .format (s .level , s .envelope )
310312
311313class FFEffect (object ):
@@ -319,6 +321,11 @@ class FFEffect(object):
319321 ff_trigger is FFTrigger object
320322 effect is FFConstant Effect. effect is the 'u' union in the real struct.
321323
324+ Direction of the effect is encoded as follows:
325+ 0 deg -> 0x0000 (down)
326+ 90 deg -> 0x4000 (left)
327+ 180 deg -> 0x8000 (up)
328+ 270 deg -> 0xC000 (right)
322329
323330
324331 '''
@@ -340,11 +347,6 @@ def __init__(self,_type, id,direction,trigger,replay,effect):
340347 self .id = id
341348
342349 #: direction of the effect.
343- # Direction of the effect is encoded as follows:
344- # 0 deg -> 0x0000 (down)
345- # 90 deg -> 0x4000 (left)
346- # 180 deg -> 0x8000 (up)
347- # 270 deg -> 0xC000 (right)
348350 self .direction = direction
349351
350352
@@ -361,60 +363,14 @@ def __init__(self,_type, id,direction,trigger,replay,effect):
361363
362364
363365 # assign the specific effect
364-
366+ if type (effect ) is not FFConstantEffect :
367+ raise Exception ("FFEffect: effect type %s is not supported" % (type (effect )))
365368 self .effect = effect
366369
367370 def __str__ (s ):
368371 msg = 'ff_effect id {:d} type {:s} direction {:s} effect: {:s}'
369372 return msg .format (s .id , FF [s .type ], FFEffect .directions .get (s .direction ,s .direction ),s .effect )
370373
371- class FFEffectTest (object ):
372- '''
373- Parameters for a Forcefeedback effect. This resembles the ``ff_effect`` C struct.
374- This is uploaded/saved to the device using EVIOSFF prior to being played.
375- Currently locked to FF_CONSTANT
376- '''
377-
378- __slots__ = 'fxtype' , 'direction' , 'replay_length' , 'replay_delay' , 'fxid' , 'constant_level' , 'attack_level' , 'attack_length' ,'fade_level' , 'fade_length'
379-
380-
381- # set the pertinent parameters
382- # def __init__(self, fxtype,direction,replay_length,replay_delay,fxid):
383- def __init__ (self , fxtype = FF_CONSTANT ,direction = 0xC000 ,replay_length = 0xFF ,replay_delay = 0x0 ,
384- constant_level = 1200 , attack_level = 0 ,attack_length = 0 , fade_level = 0 , fade_length = 0 ,
385- fxid = - 1 ):
386-
387- # Effect direction (left or right)
388- self .direction = direction
389-
390- #: Effect type - one of ``ecodes.EV_*``
391- self .fxtype = FF_CONSTANT
392-
393- # How long to play the effect
394- self .replay_length = replay_delay
395-
396- # How long to wait before replaying the effect
397- self .replay_delay = replay_delay
398-
399- # the actual strenght parameters
400- self .constant_level = constant_level
401-
402- self .attack_level = attack_level
403-
404- self .attack_length = attack_length
405- self .fade_level = fade_level
406- self .fade_length = fade_length
407-
408- #: ID of the effect. -1 means 'new effect'. Otherwise modify a new one
409- self .fxid = fxid
410-
411- def setEnvelope ():
412- x = 0
413- def __str__ (s ):
414- msg = 'ff_effect id {:2d} {:s} dir {:02d}, length {:02d}, replay delay {:02d}'
415- return msg .format (s .fxid , FF [s .fxtype ],s .direction , s .replay_length , s .replay_delay )
416-
417-
418374#: Used by :func:`evdev.util.categorize()`
419375event_factory = {
420376 EV_KEY : KeyEvent ,
0 commit comments