ind_on->set_active(true);
else
ind_off->set_active(true);
+
+ engineer.get_control().signal_power_event.connect(sigc::mem_fun(this, &MainPanel::power_event));
}
void MainPanel::set_status_text(const string &txt)
{
engineer.quit();
}
+
+void MainPanel::power_event(bool p)
+{
+ ind_on->set_active(p);
+ ind_off->set_active(!p);
+}
command(string(1, CMD_POWER_ON));
else
command(string(1, CMD_POWER_OFF));
+
+ signal_power_event.emit(power);
}
void Control::set_debug(bool d)
break;
}
}
+
if(!ok)
throw Exception("IB not detected");
+
+ command(string(1, CMD_STATUS)).signal_done.connect(sigc::mem_fun(this, &Control::status_done));
}
Command &Control::command(const string &cmd)
if(t>next_event_query)
{
- next_event_query=t+300*Time::msec;
+ next_event_query=t+200*Time::msec;
command(string(1, CMD_EVENT)).signal_done.connect(sigc::mem_fun(this, &Control::event_query_done));
}
}
else
{
+ if(cmd==CMD_STATUS)
+ result+=ERR_NO_ERROR;
+
unsigned expected_bytes=1;
if(cmd==CMD_FUNC_STATUS || cmd==CMD_TURNOUT_STATUS)
expected_bytes=2;
return result;
}
+void Control::status_done(Error, const string &resp)
+{
+ power=((resp[0]&0x08)!=0);
+ signal_power_event.emit(power);
+}
+
void Control::event_query_done(Error, const string &resp)
{
if(resp[0]&0x20)
command(string(1, CMD_EVENT_TURNOUT)).signal_done.connect(sigc::mem_fun(this, &Control::turnout_event_done));
if(resp[0]&0x04)
command(string(1, CMD_EVENT_SENSOR)).signal_done.connect(sigc::mem_fun(this, &Control::sensor_event_done));
+ if(resp.size()>1 && (resp[1]&0x40))
+ command(string(1, CMD_STATUS)).signal_done.connect(sigc::mem_fun(this, &Control::status_done));
}
void Control::turnout_event_done(Error, const string &resp)
Msp::Time::Timer timer;
public:
+ sigc::signal<void, bool> signal_power_event;
sigc::signal<void, unsigned, bool> signal_turnout_event;
sigc::signal<void, unsigned, bool> signal_sensor_event;
private:
void read_all(int, char *, int);
std::string read_reply(Cmd);
+ void status_done(Error, const std::string &);
void event_query_done(Error, const std::string &);
void turnout_event_done(Error, const std::string &);
void sensor_event_done(Error, const std::string &);