void Intellibox::set_loco_speed(unsigned addr, unsigned speed)
{
Locomotive &loco = locos[addr];
+ if(speed==loco.speed)
+ return;
+
loco.speed = speed;
loco_command(addr, speed, loco.reverse, loco.funcs|0x100);
- signal_loco_speed.emit(addr, speed, loco.reverse);
}
void Intellibox::set_loco_reverse(unsigned addr, bool rev)
{
Locomotive &loco = locos[addr];
+ if(rev==loco.reverse)
+ return;
+
loco.reverse = rev;
loco_command(addr, loco.speed, rev, loco.funcs|0x100);
- signal_loco_speed.emit(addr, loco.speed, rev);
}
void Intellibox::set_loco_function(unsigned addr, unsigned func, bool state)
void Intellibox::flush()
{
+ Time::TimeStamp t = Time::now();
for(list<CommandSlot>::iterator i=queue.begin(); i!=queue.end(); ++i)
+ {
write(serial_fd, i->data, i->length);
+ pollfd pfd = { serial_fd, POLLIN, 0 };
+ bool first = true;
+ while(poll(&pfd, 1, (first ? -1 : 0))>0)
+ {
+ char data[16];
+ read(serial_fd, data, 16);
+ first = false;
+ }
+ }
+
+ queue.clear();
+ command_sent = false;
}
void Intellibox::command(Command cmd)
}
}
}
+ else if(cmd==CMD_LOK)
+ {
+ unsigned char err;
+ read_all(&err, 1);
+
+ if(err==ERR_NO_ERROR)
+ {
+ unsigned addr = queue.front().addr;
+ Locomotive &loco = locos[addr];
+ signal_loco_speed.emit(addr, loco.speed, loco.reverse);
+ }
+ }
else if(cmd==CMD_TURNOUT)
{
unsigned char err;