}
class LedCommandRX51 : LedCommand {
+ private const double CYCLE_TIME_MS = 1000.0 / 32768.0;
+
public uint16 code;
public LedCommandRX51 () {
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)
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
+ }
}
}
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;
}