|  | @ -11,6 +11,8 @@ | 
														
													
														
															
																|  |  |  |  |  |  | 
														
													
														
															
																|  |  | #define LOOP_SLEEP_TIME_S 5 |  |  | #define LOOP_SLEEP_TIME_S 5 | 
														
													
														
															
																|  |  |  |  |  |  | 
														
													
														
															
																|  |  |  |  |  | #include "mqttclient.h" | 
														
													
														
															
																|  |  |  |  |  | #include "settings.h" | 
														
													
														
															
																|  |  | #include "backgroundloop.h" |  |  | #include "backgroundloop.h" | 
														
													
														
															
																|  |  |  |  |  |  | 
														
													
														
															
																|  |  |  |  |  |  | 
														
													
												
													
														
															
																|  | @ -20,9 +22,44 @@ BackgroundLoop::BackgroundLoop() { | 
														
													
														
															
																|  |  | BackgroundLoop::~BackgroundLoop() { |  |  | BackgroundLoop::~BackgroundLoop() { | 
														
													
														
															
																|  |  | } |  |  | } | 
														
													
														
															
																|  |  |  |  |  |  | 
														
													
														
															
																|  |  |  |  |  | void BackgroundLoop::onNewPowerState(enum power_states state) | 
														
													
														
															
																|  |  |  |  |  | { | 
														
													
														
															
																|  |  |  |  |  | m_pwr_state = state; | 
														
													
														
															
																|  |  |  |  |  | } | 
														
													
														
															
																|  |  |  |  |  |  | 
														
													
														
															
																|  |  |  |  |  | void BackgroundLoop::allHeatersOn(bool on) { | 
														
													
														
															
																|  |  |  |  |  | MQTTClient *mc = MQTTClient::getInstance(); | 
														
													
														
															
																|  |  |  |  |  | Settings *s = Settings::getInstance(); | 
														
													
														
															
																|  |  |  |  |  |  | 
														
													
														
															
																|  |  |  |  |  | QString payload = on ? QString("on") : QString("off"); | 
														
													
														
															
																|  |  |  |  |  |  | 
														
													
														
															
																|  |  |  |  |  | for (int i = 0; i < s->nbZones(); i++) { | 
														
													
														
															
																|  |  |  |  |  | const struct Room *r = &(s->m_rooms.at(i)); | 
														
													
														
															
																|  |  |  |  |  | for (int j = 0; j < r->heaters.count(); j++) { | 
														
													
														
															
																|  |  |  |  |  | const struct Heater *h = &(r->heaters.at(j)); | 
														
													
														
															
																|  |  |  |  |  |  | 
														
													
														
															
																|  |  |  |  |  | mc->publish_msg(h->ctrl_topic, payload); | 
														
													
														
															
																|  |  |  |  |  | } | 
														
													
														
															
																|  |  |  |  |  | } | 
														
													
														
															
																|  |  |  |  |  | } | 
														
													
														
															
																|  |  |  |  |  |  | 
														
													
														
															
																|  |  | void BackgroundLoop::run() |  |  | void BackgroundLoop::run() | 
														
													
														
															
																|  |  | { |  |  | { | 
														
													
														
															
																|  |  | while(!isInterruptionRequested()) { |  |  |  | 
														
													
														
															
																|  |  |  |  |  |  | 
														
													
														
															
																|  |  |  |  |  | while (!isInterruptionRequested()) { | 
														
													
														
															
																|  |  |  |  |  | switch (m_pwr_state) { | 
														
													
														
															
																|  |  |  |  |  | case ON: | 
														
													
														
															
																|  |  |  |  |  | allHeatersOn(true); | 
														
													
														
															
																|  |  |  |  |  | break; | 
														
													
														
															
																|  |  |  |  |  | case AUTO: | 
														
													
														
															
																|  |  |  |  |  | /* TODO */ | 
														
													
														
															
																|  |  |  |  |  | break; | 
														
													
														
															
																|  |  |  |  |  | case OFF: | 
														
													
														
															
																|  |  |  |  |  | /* fall */ | 
														
													
														
															
																|  |  |  |  |  | default: | 
														
													
														
															
																|  |  |  |  |  | allHeatersOn(false); | 
														
													
														
															
																|  |  |  |  |  | break; | 
														
													
														
															
																|  |  |  |  |  | } | 
														
													
														
															
																|  |  | this->sleep(LOOP_SLEEP_TIME_S); |  |  | this->sleep(LOOP_SLEEP_TIME_S); | 
														
													
														
															
																|  |  | } |  |  | } | 
														
													
														
															
																|  |  | } |  |  | } | 
														
													
												
													
														
															
																|  | 
 |