Skip to content
This repository has been archived by the owner on Dec 23, 2021. It is now read-only.

Telemetry for CLUE on Python Side #301

Merged
merged 3 commits into from
Apr 8, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion src/adafruit_circuitplayground/express.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
from .pixel import Pixel
from . import constants as CONSTANTS
from collections import namedtuple
from applicationinsights import TelemetryClient
import common

Acceleration = namedtuple("acceleration", ["x", "y", "z"])
Expand Down
4 changes: 4 additions & 0 deletions src/base_circuitpython/displayio/tile_grid.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import threading
import queue
from common import utils
from common.telemetry import telemetry_py
from common.telemetry_events import TelemetryEvent

# TileGrid implementation loosely based on the
# displayio.TileGrid class in Adafruit CircuitPython
Expand Down Expand Up @@ -106,6 +108,8 @@ def __init__(
self.__flip_y = False
self.__transpose_xy = False

telemetry_py.send_telemetry(TelemetryEvent.CLUE_API_TILE_GRID)

@property
def flip_x(self):
"""
Expand Down
32 changes: 32 additions & 0 deletions src/clue/adafruit_clue.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@
import neopixel
from base_circuitpython import base_cp_constants as CONSTANTS
from common import utils
from common.telemetry import telemetry_py
from common.telemetry_events import TelemetryEvent

# REVISED VERSION OF THE ADAFRUIT CLUE LIBRARY FOR DSX

Expand Down Expand Up @@ -241,6 +243,7 @@ def button_a(self):
if clue.button_a:
print("Button A pressed")
"""
telemetry_py.send_telemetry(TelemetryEvent.CLUE_API_BUTTON_A)
return self.__state[CONSTANTS.CLUE_STATE.BUTTON_A]

@property
Expand All @@ -254,6 +257,7 @@ def button_b(self):
if clue.button_b:
print("Button B pressed")
"""
telemetry_py.send_telemetry(TelemetryEvent.CLUE_API_BUTTON_B)
return self.__state[CONSTANTS.CLUE_STATE.BUTTON_B]

@property
Expand All @@ -265,6 +269,7 @@ def were_pressed(self):
while True:
print(clue.were_pressed)
"""
telemetry_py.send_telemetry(TelemetryEvent.CLUE_API_WERE_PRESSED)
ret = self.__state[CONSTANTS.CLUE_STATE.PRESSED_BUTTONS].copy()
self.__state[CONSTANTS.CLUE_STATE.PRESSED_BUTTONS].clear()
return ret
Expand All @@ -279,6 +284,7 @@ def acceleration(self):
while True:
print("Accel: {:.2f} {:.2f} {:.2f}".format(*clue.acceleration))
"""
telemetry_py.send_telemetry(TelemetryEvent.CLUE_API_ACCELERATION)
return (
self.__state[CONSTANTS.CLUE_STATE.MOTION_X],
self.__state[CONSTANTS.CLUE_STATE.MOTION_Y],
Expand All @@ -297,6 +303,7 @@ def shake(self, shake_threshold=30, avg_count=10, total_delay=0.1):
:param total_delay: The total time in seconds it takes to obtain avg_count
readings from acceleration. (Default 0.1)
"""
telemetry_py.send_telemetry(TelemetryEvent.CLUE_API_SHAKE)
is_shaken = self.__state[CONSTANTS.CLUE_STATE.GESTURE] == CONSTANTS.SHAKE
return is_shaken

Expand All @@ -311,6 +318,7 @@ def color(self):
while True:
print("Color: R: {} G: {} B: {} C: {}".format(*clue.color))
"""
telemetry_py.send_telemetry(TelemetryEvent.CLUE_API_COLOR)
return (
self.__state[CONSTANTS.CLUE_STATE.LIGHT_R],
self.__state[CONSTANTS.CLUE_STATE.LIGHT_G],
Expand All @@ -327,6 +335,7 @@ def temperature(self):
from adafruit_clue import clue
print("Temperature: {:.1f}C".format(clue.temperature))
"""
telemetry_py.send_telemetry(TelemetryEvent.CLUE_API_TEMPERATURE)
return self.__state[CONSTANTS.CLUE_STATE.TEMPERATURE]

@property
Expand All @@ -339,6 +348,7 @@ def magnetic(self):
while True:
print("Magnetic: {:.3f} {:.3f} {:.3f}".format(*clue.magnetic))
"""
telemetry_py.send_telemetry(TelemetryEvent.CLUE_API_MAGNETIC)
return (
self.__state[CONSTANTS.CLUE_STATE.MAGNET_X],
self.__state[CONSTANTS.CLUE_STATE.MAGNET_Y],
Expand All @@ -356,6 +366,7 @@ def proximity(self):
while True:
print("Proximity: {}".format(clue.proximity))
"""
telemetry_py.send_telemetry(TelemetryEvent.CLUE_API_PROXIMITY)
return self.__state[CONSTANTS.CLUE_STATE.PROXIMITY]

@property
Expand All @@ -364,6 +375,7 @@ def gyro(self):
This example prints the values. Try moving the board to see how the printed values change.
print("Gyro: {:.2f} {:.2f} {:.2f}".format(*clue.gyro))
"""
telemetry_py.send_telemetry(TelemetryEvent.CLUE_API_GYRO)
return (
self.__state[CONSTANTS.CLUE_STATE.GYRO_X],
self.__state[CONSTANTS.CLUE_STATE.GYRO_Y],
Expand All @@ -382,6 +394,7 @@ def gesture(self):
while True:
print("Gesture: {}".format(clue.gesture))
"""
telemetry_py.send_telemetry(TelemetryEvent.CLUE_API_GESTURE)
gesture_mapping = {"": 0, "up": 1, "down": 2, "left": 3, "right": 4}
return gesture_mapping.get(self.__state[CONSTANTS.CLUE_STATE.GESTURE], 0)

Expand All @@ -395,6 +408,7 @@ def humidity(self):
while True:
print("Humidity: {:.1f}%".format(clue.humidity))
"""
telemetry_py.send_telemetry(TelemetryEvent.CLUE_API_HUMIDITY)
return self.__state[CONSTANTS.CLUE_STATE.HUMIDITY]

@property
Expand All @@ -406,6 +420,7 @@ def pressure(self):
from adafruit_clue import clue
print("Pressure: {:.3f}hPa".format(clue.pressure))
"""
telemetry_py.send_telemetry(TelemetryEvent.CLUE_API_PRESSURE)
return self.__state[CONSTANTS.CLUE_STATE.PRESSURE]

@property
Expand All @@ -431,6 +446,7 @@ def altitude(self):
POWER_CONSTANT,
)
)
telemetry_py.send_telemetry(TelemetryEvent.CLUE_API_ALTITUDE)
return altitude

@property
Expand All @@ -444,10 +460,12 @@ def sea_level_pressure(self):
clue.sea_level_pressure = 1015
print("Pressure: {:.3f}hPa".format(clue.pressure))
"""
telemetry_py.send_telemetry(TelemetryEvent.CLUE_API_SEA_LEVEL_PRESSURE)
return self.__state[CONSTANTS.CLUE_STATE.SEA_LEVEL_PRESSURE]

@sea_level_pressure.setter
def sea_level_pressure(self, value):
telemetry_py.send_telemetry(TelemetryEvent.CLUE_API_SEA_LEVEL_PRESSURE)
self.__state[CONSTANTS.CLUE_STATE.SEA_LEVEL_PRESSURE] = value

@property
Expand All @@ -460,6 +478,7 @@ def pixel(self):
while True:
clue.pixel.fill((255, 0, 255))
"""
telemetry_py.send_telemetry(TelemetryEvent.CLUE_API_PIXEL)
return self.__state[CONSTANTS.CLUE_STATE.PIXEL]

@property
Expand All @@ -477,6 +496,7 @@ def touch_0(self):
if clue.touch_0:
print("Touched pad 0")
"""
telemetry_py.send_telemetry(TelemetryEvent.CLUE_API_TOUCH)
utils.print_for_unimplemented_functions(Clue.touch_0.__name__)

@property
Expand All @@ -494,6 +514,7 @@ def touch_1(self):
if clue.touch_1:
print("Touched pad 1")
"""
telemetry_py.send_telemetry(TelemetryEvent.CLUE_API_TOUCH)
utils.print_for_unimplemented_functions(Clue.touch_1.__name__)

@property
Expand All @@ -511,6 +532,7 @@ def touch_2(self):
if clue.touch_2:
print("Touched pad 2")
"""
telemetry_py.send_telemetry(TelemetryEvent.CLUE_API_TOUCH)
utils.print_for_unimplemented_functions(Clue.touch_2.__name__)

@property
Expand All @@ -526,11 +548,13 @@ def white_leds(self):
from adafruit_clue import clue
clue.white_leds = True
"""
telemetry_py.send_telemetry(TelemetryEvent.CLUE_API_WHITE_LEDS)
utils.print_for_unimplemented_functions(Clue.white_leds.__name__)

@white_leds.setter
def white_leds(self, value):
"""Not Implemented!"""
telemetry_py.send_telemetry(TelemetryEvent.CLUE_API_WHITE_LEDS)
utils.print_for_unimplemented_functions(Clue.white_leds.__name__)

@property
Expand All @@ -546,11 +570,13 @@ def red_led(self):
from adafruit_clue import clue
clue.red_led = True
"""
telemetry_py.send_telemetry(TelemetryEvent.CLUE_API_RED_LED)
utils.print_for_unimplemented_functions(Clue.red_led.__name__)

@red_led.setter
def red_led(self, value):
"""Not Implemented!"""
telemetry_py.send_telemetry(TelemetryEvent.CLUE_API_RED_LED)
utils.print_for_unimplemented_functions(Clue.red_led.__name__)

def play_tone(self, frequency, duration):
Expand All @@ -567,6 +593,7 @@ def play_tone(self, frequency, duration):
from adafruit_clue import clue
clue.play_tone(880, 1)
"""
telemetry_py.send_telemetry(TelemetryEvent.CLUE_API_SOUND)
utils.print_for_unimplemented_functions(Clue.play_tone.__name__)

def start_tone(self, frequency):
Expand All @@ -589,6 +616,7 @@ def start_tone(self, frequency):
else:
clue.stop_tone()
"""
telemetry_py.send_telemetry(TelemetryEvent.CLUE_API_SOUND)
utils.print_for_unimplemented_functions(Clue.start_tone.__name__)

def stop_tone(self):
Expand All @@ -609,6 +637,7 @@ def stop_tone(self):
else:
clue.stop_tone()
"""
telemetry_py.send_telemetry(TelemetryEvent.CLUE_API_SOUND)
utils.print_for_unimplemented_functions(Clue.stop_tone.__name__)

@property
Expand All @@ -624,6 +653,7 @@ def sound_level(self):
while True:
print(clue.sound_level)
"""
telemetry_py.send_telemetry(TelemetryEvent.CLUE_API_SOUND)
utils.print_for_unimplemented_functions(Clue.sound_level.__name__)

def loud_sound(self, sound_threshold=200):
Expand Down Expand Up @@ -656,6 +686,7 @@ def loud_sound(self, sound_threshold=200):
else:
clue.pixel.fill(0)
"""
telemetry_py.send_telemetry(TelemetryEvent.CLUE_API_SOUND)
utils.print_for_unimplemented_functions(Clue.loud_sound.__name__)

@staticmethod
Expand Down Expand Up @@ -716,6 +747,7 @@ def simple_text_display(
clue_data[2].text = "Magnetic: {:.3f} {:.3f} {:.3f}".format(*clue.magnetic)
clue_data.show()
"""
telemetry_py.send_telemetry(TelemetryEvent.CLUE_API_TEXT_DISPLAY)
return _ClueSimpleTextDisplay(
title=title,
title_color=title_color,
Expand Down
4 changes: 4 additions & 0 deletions src/clue/adafruit_slideshow.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
import collections
from random import shuffle
from common import utils
from common.telemetry import telemetry_py
from common.telemetry_events import TelemetryEvent
import board

# taken from adafruit
Expand Down Expand Up @@ -173,6 +175,8 @@ def __init__(
# show the first working image
self.advance()

telemetry_py.send_telemetry(TelemetryEvent.CLUE_API_SLIDESHOW)

@property
def current_image_name(self):
"""Returns the current image name."""
Expand Down
23 changes: 23 additions & 0 deletions src/common/telemetry_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,26 @@ class TelemetryEvent(enum.Enum):
MICROBIT_API_RADIO = "MICROBIT.API.RADIO"
MICROBIT_API_SPEECH = "MICROBIT.API.SPEECH"
MICROBIT_API_UTIME = "MICROBIT.API.UTIME"
CLUE_API_ACCELERATION = "CLUE.API.ACCELERATION"
CLUE_API_BUTTON_A = "CLUE.API.BUTTON.A"
CLUE_API_BUTTON_B = "CLUE.API.BUTTON.B"
CLUE_API_WERE_PRESSED = "CLUE.API.WERE.PRESSED"
CLUE_API_SHAKE = "CLUE.API.SHAKE"
CLUE_API_COLOR = "CLUE.API.COLOR"
CLUE_API_TEMPERATURE = "CLUE.API.TEMPERATURE"
CLUE_API_MAGNETIC = "CLUE.API.MAGNETIC"
CLUE_API_PROXIMITY = "CLUE.API.PROXIMITY"
CLUE_API_GYRO = "CLUE.API.GYRO"
CLUE_API_GESTURE = "CLUE.API.GESTURE"
CLUE_API_HUMIDITY = "CLUE.API.HUMIDITY"
CLUE_API_PRESSURE = "CLUE.API.PRESSURE"
CLUE_API_ALTITUDE = "CLUE.API.ALTITUDE"
CLUE_API_SEA_LEVEL_PRESSURE = "CLUE.API.SEA.LEVEL.PRESSURE"
CLUE_API_PIXEL = "CLUE.API.PIXEL"
CLUE_API_TOUCH = "CLUE.API.TOUCH"
CLUE_API_WHITE_LEDS = "CLUE.API.WHITE.LEDS"
CLUE_API_RED_LED = "CLUE.API.RED.LED"
CLUE_API_SOUND = "CLUE.API.SOUND"
CLUE_API_TEXT_DISPLAY = "CLUE.API.TEXT.DISPLAY"
CLUE_API_SLIDESHOW = "CLUE.API.SLIDESHOW"
CLUE_API_TILE_GRID = "CLUE.API.TILE.GRID"