public static LedTimer FromBytes(byte[] bytes) { LedTimer timer; if (bytes[13] == 0x0f) { return(new TurnOffLedTimer(bytes)); } byte pattern_code = bytes[8]; switch (pattern_code) { case 0x00: timer = new LedTimer(bytes); break; case 0x61: timer = new ColorLedTimer(bytes); break; case 0xA1: timer = new BuiltinTimerLedTimer(bytes); break; case 0xA2: timer = new BuiltinTimerLedTimer(bytes); break; default: { if (Enum.IsDefined(typeof(PresetPattern), pattern_code)) { timer = new PresetPatternLedTimer(bytes); } else if (bytes[12] != 0) { timer = new WarmWhiteLedTimer(bytes); } else { //TODO: Custom exception throw new Exception(); } } break; } return(timer); }
public LedTimer[] GetTimers() { SendMsg(GET_TIMERS_MSG); int resp_len = 88; byte[] response = ReadMsg(88); if (response.Length < resp_len) { throw new Exception("Response too short"); } LedTimer[] timers = new LedTimer[6]; byte[] timer_bytes = new byte[14]; for (int i = 0; i < 6; ++i) { Array.Copy(response, (i * 14) + 2, timer_bytes, 0, 14); timers[i] = LedTimer.FromBytes(timer_bytes); } return(timers); }