summary |
shortlog |
log |
commit | commitdiff |
tree
raw |
patch |
inline | side by side (from parent 1:
6887e5c)
It may happen that a locomotive gets re-enumerated, e.g. after visiting
another layout. Since they are identified by their address, it's useful
to keep the same address.
+ArduControl::MfxInfo *ArduControl::find_mfx_info(unsigned id)
+{
+ for(MfxInfoArray::iterator i=mfx_info.begin(); i!=mfx_info.end(); ++i)
+ if(i->id==id)
+ return &*i;
+ return 0;
+}
+
void ArduControl::remove_loco(unsigned id)
{
Locomotive &loco = get_item(locomotives, id);
void ArduControl::remove_loco(unsigned id)
{
Locomotive &loco = get_item(locomotives, id);
+ unsigned address = 0;
+ if(MfxInfo *existing = control.find_mfx_info(bits))
+ address = existing->address;
+ else
+ address = next_address++;
+
- IO::print("Assigning MFX address %d to decoder %08X\n", next_address, bits);
+ IO::print("Assigning MFX address %d to decoder %08X\n", address, bits);
pending_info = new MfxInfo;
pending_info->protocol = "MFX";
pending_info = new MfxInfo;
pending_info->protocol = "MFX";
- pending_info->address = next_address;
+ pending_info->address = address;
pending_info->name = format("%08X", bits);
pending_info->id = bits;
cmd.command[0] = MFX_ASSIGN_ADDRESS;
pending_info->name = format("%08X", bits);
pending_info->id = bits;
cmd.command[0] = MFX_ASSIGN_ADDRESS;
- cmd.command[1] = next_address>>8;
- cmd.command[2] = next_address;
+ cmd.command[1] = address>>8;
+ cmd.command[2] = address;
for(unsigned i=0; i<4; ++i)
cmd.command[3+i] = bits>>(24-i*8);
cmd.length = 7;
for(unsigned i=0; i<4; ++i)
cmd.command[3+i] = bits>>(24-i*8);
cmd.length = 7;
size = 0;
bits = 0;
misses = 0;
size = 0;
bits = 0;
misses = 0;
read_array = 0;
read_offset = 0;
read_array = 0;
read_offset = 0;
virtual unsigned add_loco(unsigned, const std::string &, const VehicleType &);
private:
MfxInfoArray::iterator add_mfx_info(const MfxInfo &);
virtual unsigned add_loco(unsigned, const std::string &, const VehicleType &);
private:
MfxInfoArray::iterator add_mfx_info(const MfxInfo &);
+ MfxInfo *find_mfx_info(unsigned);
public:
virtual void remove_loco(unsigned);
virtual void set_loco_speed(unsigned, unsigned);
public:
virtual void remove_loco(unsigned);
virtual void set_loco_speed(unsigned, unsigned);