5656 https://github.com/adafruit/Adafruit_CircuitPython_NeoPixel
5757"""
5858
59+ from common .telemetry_events import TelemetryEvent
60+ from common .telemetry import telemetry_py
61+ from common import utils
62+ from base_circuitpython import base_cp_constants as CONSTANTS
63+ import neopixel
5964import time
6065import array
6166import math
6772
6873abs_path = pathlib .Path (__file__ ).parent .absolute ()
6974sys .path .insert (0 , os .path .join (abs_path ))
70- import neopixel
71- from base_circuitpython import base_cp_constants as CONSTANTS
72- from common import utils
73- from common .telemetry import telemetry_py
74- from common .telemetry_events import TelemetryEvent
7575
7676# REVISED VERSION OF THE ADAFRUIT CLUE LIBRARY FOR DSX
7777
@@ -227,6 +227,10 @@ def __init__(self):
227227 self .__state [CONSTANTS .CLUE_STATE .GYRO_X ] = 0
228228 self .__state [CONSTANTS .CLUE_STATE .GYRO_Y ] = 0
229229 self .__state [CONSTANTS .CLUE_STATE .GYRO_Z ] = 0
230+ # LEDs
231+ self .__state [CONSTANTS .CLUE_STATE .RED_LED ] = False
232+ self .__state [CONSTANTS .CLUE_STATE .WHITE_LEDS ] = False
233+
230234 self .button_mapping = {
231235 CONSTANTS .CLUE_STATE .BUTTON_A : "A" ,
232236 CONSTANTS .CLUE_STATE .BUTTON_B : "B" ,
@@ -502,7 +506,7 @@ def touch_0(self):
502506 @property
503507 def touch_1 (self ):
504508 """Not Implemented!
505-
509+
506510 Detect touch on capacitive touch pad 1.
507511 .. image :: ../docs/_static/pad_1.jpg
508512 :alt: Pad 1
@@ -520,7 +524,7 @@ def touch_1(self):
520524 @property
521525 def touch_2 (self ):
522526 """Not Implemented!
523-
527+
524528 Detect touch on capacitive touch pad 2.
525529 .. image :: ../docs/_static/pad_2.jpg
526530 :alt: Pad 2
@@ -537,9 +541,7 @@ def touch_2(self):
537541
538542 @property
539543 def white_leds (self ):
540- """Not Implemented!
541-
542- The red led next to the USB plug labeled LED.
544+ """The red led next to the USB plug labeled LED.
543545 .. image :: ../docs/_static/white_leds.jpg
544546 :alt: White LEDs
545547 This example turns on the white LEDs.
@@ -549,19 +551,16 @@ def white_leds(self):
549551 clue.white_leds = True
550552 """
551553 telemetry_py .send_telemetry (TelemetryEvent .CLUE_API_WHITE_LEDS )
552- utils . print_for_unimplemented_functions ( Clue . white_leds . __name__ )
554+ return self . __state [ CONSTANTS . CLUE_STATE . WHITE_LEDS ]
553555
554556 @white_leds .setter
555557 def white_leds (self , value ):
556- """Not Implemented!"""
557558 telemetry_py .send_telemetry (TelemetryEvent .CLUE_API_WHITE_LEDS )
558- utils . print_for_unimplemented_functions ( Clue . white_leds . __name__ )
559+ self . __set_leds ( CONSTANTS . CLUE_STATE . WHITE_LEDS , value )
559560
560561 @property
561562 def red_led (self ):
562- """Not Implemented!
563-
564- The red led next to the USB plug labeled LED.
563+ """The red led next to the USB plug labeled LED.
565564 .. image :: ../docs/_static/red_led.jpg
566565 :alt: Red LED
567566 This example turns on the red LED.
@@ -571,13 +570,12 @@ def red_led(self):
571570 clue.red_led = True
572571 """
573572 telemetry_py .send_telemetry (TelemetryEvent .CLUE_API_RED_LED )
574- utils . print_for_unimplemented_functions ( Clue . red_led . __name__ )
573+ return self . __state [ CONSTANTS . CLUE_STATE . RED_LED ]
575574
576575 @red_led .setter
577576 def red_led (self , value ):
578- """Not Implemented!"""
579577 telemetry_py .send_telemetry (TelemetryEvent .CLUE_API_RED_LED )
580- utils . print_for_unimplemented_functions ( Clue . red_led . __name__ )
578+ self . __set_leds ( CONSTANTS . CLUE_STATE . RED_LED , value )
581579
582580 def play_tone (self , frequency , duration ):
583581 """ Not Implemented!
@@ -773,6 +771,12 @@ def __update_button(self, button, value):
773771 )
774772 self .__state [button ] = value
775773
774+ def __set_leds (self , led , value ):
775+ value = bool (value )
776+ self .__state [led ] = value
777+ sendable_json = {led : value }
778+ utils .send_to_simulator (sendable_json , CONSTANTS .CLUE )
779+
776780
777781clue = Clue () # pylint: disable=invalid-name
778782"""Object that is automatically created on import.
0 commit comments