for(unsigned i=0; i<turnout.bits; ++i)
if((state^turnout.state)&(1<<i))
- turnout_command(addr+i, state&(1<<i), true);
+ turnout_command(addr+i, !(state&(1<<i)), true);
}
unsigned Intellibox::get_turnout(unsigned addr) const
{
i->second.active = false;
i->second.off_timeout = Time::TimeStamp();
- turnout_command(i->first, i->second.state, false);
+ for(unsigned j=0; j<i->second.bits; ++j)
+ turnout_command(i->first+j, !(i->second.state&(1<<j)), false);
}
for(map<unsigned, Sensor>::iterator i=sensors.begin(); i!=sensors.end(); ++i)
read_all(data, 2);
unsigned addr = data[0]+((data[1]&7)<<8);
+ unsigned mask = 1;
+ for(; !turnouts[addr].bits; --addr, mask<<=1) ;
Turnout &turnout = turnouts[addr];
- turnout.state = (data[1]&0x80)!=0;
+
+ unsigned bit = !(data[1]&0x80);
+ turnout.state = (turnout.state&~mask) | (bit*mask);
turnout.pending = turnout.state;
signal_turnout.emit(addr, turnout.state);
}
unsigned addr = queue.front().addr;
unsigned mask = 1;
- while(!turnouts[addr].bits)
- {
- --addr;
- mask <<= 1;
- }
+ for(; !turnouts[addr].bits; --addr, mask<<=1) ;
Turnout &turnout = turnouts[addr];
if(err==ERR_NO_ERROR)
unsigned addr = queue.front().addr;
unsigned mask = 1;
- while(!turnouts[addr].bits)
- {
- --addr;
- mask <<= 1;
- }
+ for(; !turnouts[addr].bits; --addr, mask<<=1) ;
Turnout &turnout = turnouts[addr];
- bool state = data&0x04;
- if(state!=((turnout.state&mask)!=0))
+ bool bit = !(data&0x04);
+ if(bit!=((turnout.state&mask)!=0))
{
- turnout.state = (turnout.state&~mask) | (state ? mask : 0);
+ turnout.state = (turnout.state&~mask) | (bit*mask);
turnout.pending = turnout.state;
signal_turnout.emit(addr, turnout.state);
}