@@ -333,23 +333,6 @@ def _notify_sensory_device_data_changed(self):
333333 def _notify_motoring_device_data_changed (self ):
334334 self ._roboid ._notify_motoring_device_data_changed ()
335335
336- def led_on (self , port : str , brightness : str ):
337- if isinstance (port , str ) and isinstance (brightness , int ):
338- if port .lower () == 'out1' :
339- self .write (Neosoco .OUTPUT_1 , Util .round (brightness ))
340- elif port .lower () == 'out2' :
341- self .write (Neosoco .OUTPUT_2 , Util .round (brightness ))
342- elif port .lower () == 'out3' :
343- self .write (Neosoco .OUTPUT_3 , Util .round (brightness ))
344- elif port .lower () == 'all' :
345- self .write (Neosoco .OUTPUT_1 , Util .round (brightness ))
346- self .write (Neosoco .OUTPUT_2 , Util .round (brightness ))
347- self .write (Neosoco .OUTPUT_3 , Util .round (brightness ))
348- else :
349- raise ValueError
350- else :
351- raise TypeError
352-
353336 def get_value (self , port : str ):
354337 if isinstance (port , str ):
355338 if port .lower () == 'in1' :
@@ -363,6 +346,42 @@ def get_value(self, port: str):
363346 elif port .lower () == 'bat' :
364347 return self .read (Neosoco .BATTERY )
365348 else :
349+ Util .print_error ('Wrong value of port' )
350+ raise ValueError
351+ else :
352+ raise TypeError
353+
354+ def led_on (self , port : str , brightness : str ):
355+ try :
356+ cvt_dic = {
357+ '100' : 255 ,
358+ '90' : 230 ,
359+ '80' : 204 ,
360+ '70' : 179 ,
361+ '60' : 153 ,
362+ '50' : 128 ,
363+ '40' : 102 ,
364+ '30' : 77 ,
365+ '20' : 51 ,
366+ '10' : 26
367+ }
368+ cvt_val = cvt_dic [brightness ]
369+ except KeyError :
370+ Util .print_error ('Wrong value of percentage' )
371+ raise ValueError
372+ if isinstance (port , str ):
373+ if port .lower () == 'out1' :
374+ self .write (Neosoco .OUTPUT_1 , cvt_val )
375+ elif port .lower () == 'out2' :
376+ self .write (Neosoco .OUTPUT_2 , cvt_val )
377+ elif port .lower () == 'out3' :
378+ self .write (Neosoco .OUTPUT_3 , cvt_val )
379+ elif port .lower () == 'all' :
380+ self .write (Neosoco .OUTPUT_1 , cvt_val )
381+ self .write (Neosoco .OUTPUT_2 , cvt_val )
382+ self .write (Neosoco .OUTPUT_3 , cvt_val )
383+ else :
384+ Util .print_error ('Wrong value of port' )
366385 raise ValueError
367386 else :
368387 raise TypeError
0 commit comments