X-Git-Url: http://git.maemo.org/git/?a=blobdiff_plain;f=src%2Fled-pattern-rx51.vala;h=fe2dc79181e84f6d6e862b5d4321de4fcedcf7d7;hb=2ca525350da9f795e89901010a6ed44a4ef5fa4e;hp=84c7ca8b594a3becec055adfaa5c4ae8cbccba50;hpb=2aa86ffa70e4ce9848989513d26a41435189a46e;p=led-pattern-ed diff --git a/src/led-pattern-rx51.vala b/src/led-pattern-rx51.vala index 84c7ca8..fe2dc79 100644 --- a/src/led-pattern-rx51.vala +++ b/src/led-pattern-rx51.vala @@ -158,6 +158,8 @@ class LedPatternRX51 : LedPattern { } class LedCommandRX51 : LedCommand { + private const double CYCLE_TIME_MS = 1000.0 / 32768.0; + public uint16 code; public LedCommandRX51 () { @@ -165,17 +167,18 @@ class LedCommandRX51 : LedCommand { public LedCommandRX51.with_code (uint16 _code) { code = _code; + duration = 16 * CYCLE_TIME_MS; if ((code & 0x8000) == 0) { if (code == 0x0000) { - type = CommandType.REPEAT; + type = CommandType.GO_TO_START; } else if ((code & 0x3e00) != 0) { type = CommandType.RAMP_WAIT; steps = code & 0xff; step_time = code >> 9; if ((code & 0x4000) == 0) - step_time = (code >> 9) * 0.49; + step_time = (code >> 9) * 16 * CYCLE_TIME_MS; else { - step_time = ((code & 0x3e00) >> 9) * 15.6; + step_time = ((code & 0x3e00) >> 9) * 512 * CYCLE_TIME_MS; } duration = step_time * (steps + 1); if ((code & 0x100) != 0) @@ -185,12 +188,24 @@ class LedCommandRX51 : LedCommand { level = code & 0xff; } } else { - if (code == 0x9d80) + if (code == 0x9d80) { type = CommandType.RESET_MUX; - if (code == 0xc000) - type = CommandType.STOP; - //if (code == 0xe0??) - // type = CommandType.TRIGGER_WAIT; + } else if ((code & ~0x1f8f) == 0xa000) { + type = CommandType.BRANCH; + // 0x1f80: (loop count - 1) << 7 + // 0x000f: step number + } else if ((code & ~0x1800) == 0xc000) { + type = CommandType.END; + // 0x1000: interrupt + if ((code & 0x0800) != 0) // Reset + steps = -255; + } else if ((code & ~ 0x13f0) == 0xe000) { + type = CommandType.TRIGGER; + // 0x1000: wait ext + // 0x0380: wait B G R + // 0x0040: set ext + // ??: set B G R + } } } @@ -199,16 +214,16 @@ class LedCommandRX51 : LedCommand { base.set_pwm (_level); } - public override void ramp_wait (double _step_time, int _steps) requires (_step_time >= 0.49) { + public override void ramp_wait (double _step_time, int _steps) requires (_step_time >= (16 * CYCLE_TIME_MS)) { int step_time; - if (_step_time <= 31*0.49) { - step_time = (int) ((_step_time + 0.001) / 0.49); + if (_step_time <= 31 * (16 * CYCLE_TIME_MS)) { + step_time = (int) ((_step_time + 0.001) / (16 * CYCLE_TIME_MS)); code = (uint16) step_time << 9; - _step_time = step_time * 0.49; - } else if (_step_time <= 31*15.6) { - step_time = (int) ((_step_time + 0.01) / 15.6); + _step_time = step_time * (16 * CYCLE_TIME_MS); + } else if (_step_time <= 31*(512 * CYCLE_TIME_MS)) { + step_time = (int) ((_step_time + 0.01) / (512 * CYCLE_TIME_MS)); code = 0x4000 | (step_time << 9); - _step_time = step_time * 15.6; + _step_time = step_time * (512 * CYCLE_TIME_MS); } else { return; }