void BluetoothSensor::run() { bool updateDB = false; bool scan = false; print("Running, CTRL+C to quit..."); // index of the device currently scanned unsigned int deviceIndex = 0; while(!quit) { // update device db if previous update didn't succeed if (m_updateDBNeeded) m_updateDBNeeded = !updateDeviceData(); // make sure that current device index is valid. // this also guarantees that no scanning is made when there are no devices. if (deviceIndex < m_devices.size()) { checkDevice(deviceIndex); } // move to next device, start from beginning when at the end deviceIndex++; if (deviceIndex >= m_devices.size()) deviceIndex = 0; // check if there are arrived mqtt messages (commands) do { processIncomingMessages(updateDB, scan); if (updateDB) { m_updateDBNeeded = !updateDeviceData(); } if (scan) { discoverDevices(); } } // check arrived messages again after database update or device discovery, // so that a possible request for those is processed before continuing while ((updateDB || scan) && !quit); // check that Mosquitto is still connected. // if Mosquitto disconnects there can be messages from this iteration // which aren't sent at all, but missing some outgoing messages // shouldn't be too big of a problem. if (!m_mosquitto->isConnected()) { printError("Mosquitto disconnected"); if (connectMosquitto()) { // update device db and send hello after mosquitto reconnect m_updateDBNeeded = !updateDeviceData(); sendHello(); } } } }
void LANSensor::run() { bool updateDB = false; bool scan = false; print("Running, CTRL+C to quit..."); while(!quit) { // update device db if previous update didn't succeed if (m_updateDBNeeded) m_updateDBNeeded = !updateDeviceData(); checkDevices(); std::stringstream ss; ss << "Waiting scan interval (" << m_scanInterval << " sec)..."; print(ss.str()); // wait scan interval, check for incoming messages every second while doing so for (int timer = 0; timer < m_scanInterval; timer++) { sleep(1); // check if there are arrived mqtt messages (commands) do { processIncomingMessages(updateDB, scan); if (updateDB) { m_updateDBNeeded = !updateDeviceData(); // exit from wait loop timer = m_scanInterval; } if (scan) { discoverDevices(); // exit from wait loop timer = m_scanInterval; } } // check arrived messages again after database update or device discovery, // so that a possible request for those is processed before continuing while ((updateDB || scan) && !quit); // check that Mosquitto is still connected. // if Mosquitto disconnects there can be messages from this iteration // which aren't sent at all, but missing some outgoing messages // shouldn't be too big of a problem. if (!m_mosquitto->isConnected()) { printError("Mosquitto disconnected"); if (connectMosquitto()) { // update device db and send hello after mosquitto reconnect m_updateDBNeeded = !updateDeviceData(); sendHello(); } break; } if (quit) break; } } }
int main(int argc, char **argv) { errStatus status = ERR_OK; char deviceAddress[50]; t_videoResolution newResolution; status = discoverDevices(deviceAddress); if(status != ERR_OK) goto exitLabel; printf("Received probe matches %s\n", deviceAddress); status = connectCamera(deviceAddress); if(status != ERR_OK) goto exitLabel; //printf("Media URL set to %s\n", mediaEP); status = getSupportedResolutions(); if(status != ERR_OK) goto exitLabel; newResolution.Encoding = tt__VideoEncoding__H264; newResolution.width = 1280; newResolution.height = 720; status = setResolution(newResolution); if(status == ERR_RESOLUTION_NOT_SUPPORTED) printf("Resolution not supported\n"); else printf("Resolution supported\n"); if(status != ERR_OK) goto exitLabel; #if 0 struct _trt__GetVideoSourceConfiguration getVideoSourceConfigurationRequest; getVideoSourceConfigurationRequest.ConfigurationToken = (char *)malloc(sizeof(videoSrcToken)); strcpy(getVideoSourceConfigurationRequest.ConfigurationToken, videoSrcToken); struct _trt__GetVideoSourceConfigurationResponse getVideoSourceConfigurationResponse; soap_call___trt__GetVideoSourceConfiguration(&soap, mediaEP, NULL, &getVideoSourceConfigurationRequest, &getVideoSourceConfigurationResponse); if(getVideoSourceConfigurationResponse.Configuration == NULL) { printf("No video src config for %s\n", videoSrcToken); status = 1; goto exit; } else { printf("Video config available\n"); } struct _trt__SetVideoSourceConfiguration setVideoSourceConfigurationRequest; getVideoSourceConfigurationResponse.Configuration->Bounds->width = 1280;//640; getVideoSourceConfigurationResponse.Configuration->Bounds->height = 720;//360; getVideoSourceConfigurationResponse.Configuration->Bounds->x = 0; getVideoSourceConfigurationResponse.Configuration->Bounds->y = 0; setVideoSourceConfigurationRequest.Configuration = getVideoSourceConfigurationResponse.Configuration; struct _trt__SetVideoSourceConfigurationResponse setVideoSourceConfigurationResponse; soap_call___trt__SetVideoSourceConfiguration(&soap, mediaEP, NULL, &setVideoSourceConfigurationRequest, &setVideoSourceConfigurationResponse); #endif exitLabel: cleanup(); return status; }
AlsaEngine::AlsaEngine(QObject *parent) : AudioEngine(parent) { discoverDevices(); m_instance = this; }
void CUpnpBrowserGui::selectDevice() { bool loop = true; bool refresh = true; neutrino_msg_t msg; neutrino_msg_data_t data; if (!discoverDevices()) return; CAudioMute::getInstance()->enableMuteIcon(false); while (loop) { if (refresh) { paintDevices(); refresh=false; } g_RCInput->getMsg(&msg, &data, 10); // 1 sec timeout to update play/stop state display neutrino_msg_t msg_repeatok = msg & ~CRCInput::RC_Repeat; if (msg == CRCInput::RC_timeout) { // nothing } else if (msg == CRCInput::RC_home) { loop=false; } else if (msg_repeatok == (neutrino_msg_t) g_settings.key_list_start) { updateDeviceSelection(0); } else if (msg_repeatok == (neutrino_msg_t) g_settings.key_list_end) { updateDeviceSelection(m_devices.size()-1); } else if (msg_repeatok == CRCInput::RC_up || (int) msg == g_settings.key_pageup) { int step = ((int) msg == g_settings.key_pageup) ? m_listmaxshow : 1; // browse or step 1 int new_selected = m_selecteddevice - step; if (new_selected < 0) { if (m_selecteddevice != 0 && step != 1) new_selected = 0; else new_selected = m_devices.size() - 1; } updateDeviceSelection(new_selected); } else if (msg_repeatok == CRCInput::RC_down || (int) msg == g_settings.key_pagedown) { int step = ((int) msg == g_settings.key_pagedown) ? m_listmaxshow : 1; // browse or step 1 int new_selected = m_selecteddevice + step; if (new_selected >= (int) m_devices.size()) { if (((m_devices.size() - m_listmaxshow -1 < m_selecteddevice) && (step != 1)) || (m_selecteddevice != (m_devices.size() - 1))) new_selected = m_devices.size() - 1; else if (((m_devices.size() / m_listmaxshow) + 1) * m_listmaxshow == m_devices.size() + m_listmaxshow) // last page has full entries new_selected = 0; else new_selected = ((step == (int) m_listmaxshow) && (new_selected < (int) (((m_devices.size() / m_listmaxshow)+1) * m_listmaxshow))) ? (m_devices.size() - 1) : 0; } updateDeviceSelection(new_selected); } else if (msg == CRCInput::RC_right || msg == CRCInput::RC_ok) { m_folderplay = false; selectItem("0"); refresh=true; } else if (msg == CRCInput::RC_blue) { m_devices.clear(); if (!discoverDevices()) return; refresh=true; } else if (msg == NeutrinoMessages::RECORD_START || msg == NeutrinoMessages::ZAPTO || msg == NeutrinoMessages::STANDBY_ON || msg == NeutrinoMessages::SHUTDOWN || msg == NeutrinoMessages::SLEEPTIMER) { loop=false; g_RCInput->postMsg(msg, data); } #if 0 else if (msg == NeutrinoMessages::EVT_TIMER) { CNeutrinoApp::getInstance()->handleMsg(msg, data); } else if (msg > CRCInput::RC_MaxRC) #endif else { printf("msg: %x\n", (int) msg); if (CNeutrinoApp::getInstance()->handleMsg(msg, data) & messages_return::cancel_all) loop = false; } } CAudioMute::getInstance()->enableMuteIcon(true); }