Created
September 5, 2018 02:33
-
-
Save drewhoener/2ee4c69581cddadf3f9dc45ac6057f52 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import json | |
from enum import Enum | |
def as_color_packet(packet_dict): | |
if '__type__' in packet_dict and packet_dict['__type__'] == 'ColorPacket': | |
return ColorPacket(packet_dict['color_mode'], packet_dict['rainbow_mode'], packet_dict['color'], | |
packet_dict['decay'], packet_dict['twinkle_ratio'], | |
packet_dict['min_scale'], packet_dict['max_scale'], packet_dict['delay_ms']) | |
def decode_packet(json_data): | |
try: | |
return json.loads(json_data, object_hook=as_color_packet) | |
except ValueError: | |
print("Excepted Value: ({0})".format(json_data)) | |
class ColorPacket: | |
def __init__(self, color_mode=0, rainbow_mode=0, color=0, decay=0, twinkle_ratio=30, min_scale=0, max_scale=255, delay_ms=15): | |
self.color_mode = color_mode | |
self.rainbow_mode = rainbow_mode | |
self.decay = decay | |
self.twinkle_ratio = twinkle_ratio | |
self.color = color | |
self.min_scale = min_scale | |
self.max_scale = max_scale | |
self.delay_ms = delay_ms | |
class ColorMode(Enum): | |
PULSE = 1 | |
WIPE = 2 | |
CHASE = 3 | |
TWINKLE = 4 | |
SOLID = 5 | |
FLARE = 6 | |
METEOR = 7 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment