void PiWars::run() { struct pollfd fds[2]; // We are now running _running = true; // Query the file descriptor for the InputDevice so we can correctly wait for events fds[0].fd = _inputQueue->getFD(); fds[0].events = POLLIN; fds[0].revents = 0; while(_running) { // Wait for up to a second for input int result = poll(fds, 1, 1000); if(-1 == result) { std::cerr << __func__ << ": Poll returned error, ignoring" << std::endl; continue; } else if(0 == result) { // A timeout occured. // Do we need to dismiss the menu or Info? std::chrono::duration<float> duration = std::chrono::system_clock::now() - _lastInput; // After 5 seconds of inactivity we dismiss the menu if(duration.count() >= 5.0f) { // Ensure the meuu and info are dismissed _currentMenu = nullptr; _displayingInfo = false; } // And update the display updateDisplay(); } else { // Anything else should be from the input device if(fds[0].revents & POLLIN) { int rc; InputEvent event(0,0); // Tell poll that we have processed the event fds[0].revents = 0; // Process all queued up input events while(!_inputQueue->empty()) { _inputQueue->pop(event); // We're only interested in button presses if(InputEventType::BUTTON == event.getType()) { processButton(event); } } } } } }
static void processButtons() { bool isPressed[3]; isPressed[BTN_UP] = !pinRead(BTN_UP_P); isPressed[BTN_SELECT] = !pinRead(BTN_SELECT_P); isPressed[BTN_DOWN] = !pinRead(BTN_DOWN_P); LOOPR(BTN_COUNT, i) processButton(&buttons[i], isPressed[i]); }
void Visualight::update(){ if(isServer){ processServer(); } else{ processClient(); } processButton(); //TODO: test to see how much blockage this has... if(alerting && (millis() % 5)==0) alert(); }
task main() { time1[T1] = 0; while (true) { ++nCycles; processButton(); nErrorValue = getLineErrorPosition(); nDerivative = nErrorValue - nLastError; nAdjustment = ((nErrorValue * nPFactor) + (nDerivative * nDFactor))/ 100; nLastError = nErrorValue; if (nAdjustment > 0) { nLeftMotor = nMaxSpeed + 8 * nAdjustment / 2; //4 nRightMotor = nMaxSpeed - 10 * nAdjustment / 2; //10 } else { nLeftMotor = nMaxSpeed + 10 * nAdjustment / 2; nRightMotor = nMaxSpeed - 4 * nAdjustment / 2; } if (bMotorsDisabled) { motor[leftMotor] = 0; motor[rightMotor] = 0; } else { motor[leftMotor] = nLeftMotor; motor[rightMotor] = nRightMotor; } static int nLastVexSPIMsgCounts = 0; int nCurrVexSPIMsgCounts = 0; while (true) { nCurrVexSPIMsgCounts = nVexSPIMsgCounts; if (nCurrVexSPIMsgCounts != nLastVexSPIMsgCounts) { nLastVexSPIMsgCounts = nVexSPIMsgCounts; break; } } time1[T1] = 0; while (time1[T1] < 13) {} } return; }
boolean Visualight::connectToServer(){ VPRINTLN(F("-CONNECTTOSERVER-")); // wifly.reboot(); // delay(1000); processButton(); //check for reset press if(reconnectCount > 4){ VPRINTLN(F("rebooting wifly...")); // set debug LEDs to ON setWiFlyLeds(1, false); //wifly.save(); wifly.reboot(); //wiflyHardReset(); delay(1000); reconnectCount = 0; } wifly.flushRx(); if(!wifly.isAssociated()) { // VPRINTLN(F("Joining")); if(!wifly.join()){ VPRINTLN(F("Join Failed")); VPRINTLN(wifly.isAssociated()); return false; } } else{ VPRINTLN(F("Already Assoc")); } VPRINTLN(F("Connecting")); if (wifly.open(URL, PORT)) { VPRINTLN(F("Connected")); wifly.print("{\"mac\":\""); wifly.print(MAC); wifly.println("\"}"); //reconnect = false; connectTime = millis(); lastHeartbeat = millis(); return true; } else { VPRINTLN(F("Failed to open")); return false; } }
int GUI_v2::processButtonList(Button *buttonList, uint16 inputFlag, int8 mouseWheel) { if (!buttonList) return inputFlag & 0x7FFF; if (_backUpButtonList != buttonList || _buttonListChanged) { _specialProcessButton = 0; //flagsModifier |= 0x2200; _backUpButtonList = buttonList; _buttonListChanged = false; while (buttonList) { processButton(buttonList); buttonList = buttonList->nextButton; } } Common::Point p = _vm->getMousePos(); int mouseX = _vm->_mouseX = p.x; int mouseY = _vm->_mouseY = p.y; uint16 flags = 0; if (1/*!_screen_cursorDisable*/) { uint16 inFlags = inputFlag & 0xFF; uint16 temp = 0; // HACK: inFlags == 200 is our left button (up) if (inFlags == 199 || inFlags == 200) temp = 0x1000; if (inFlags == 198) temp = 0x100; if (inputFlag & 0x800) temp <<= 2; flags |= temp; _flagsModifier &= ~((temp & 0x4400) >> 1); _flagsModifier |= (temp & 0x1100) * 2; flags |= _flagsModifier; flags |= (_flagsModifier << 2) ^ 0x8800; }
void GUI::updateButton(Button *button) { if (!button || (button->flags & 8)) return; if (button->flags2 & 1) button->flags2 &= 0xFFF7; else button->flags2 |= 8; button->flags2 &= 0xFFFC; if (button->flags2 & 4) button->flags2 |= 0x10; else button->flags2 &= 0xEEEF; button->flags2 &= 0xFFFB; processButton(button); }
void WeatherStation::run() { uint8_t dataType; int16_t data; boolean ret; /*event*/ if (g_RTCIntFlag) //it must be at the front of processRTCAlarm() { g_RTCIntFlag = false; RTCObj.clearINTStatus(); } if ( EVENT_STATE_SET == eventRTCState ) { processRTCAlarm(); eventRTCState = EVENT_STATE_DOING; } if ( EVENT_STATE_SET == eventButtonState ) { processButton(); eventButtonState = EVENT_STATE_DOING; } if ( SYS_STATE_WAITING == systemState ) { if ( STATE_DOING == getActionState()) //high priority { systemState = SYS_STATE_ACTION; } else if ( (uint8_t)((millis()/1000) - startTime) >= overTime ) { systemState = SYS_STATE_GOTOSLEEP; DBG_PRINTLN("goto sleep"); /**to minimize the time to sleep state, so there is not sleep state case **/ if ( (SW_RUN == digitalRead(PALETTE_PIN_SW)) && (SW_MAKE == switchState) ) { #if !_DEBUG dettachUSB(); #endif switchState = SW_RUN; } disableBeforeSleep(); wakeFlag = false; sleep(); enableAfterSleep(); systemState = SYS_STATE_WAITING; DBG_PRINTLN_VAR(systemState,DEC); } else { //nothing } } else if ( SYS_STATE_ACTION == systemState ) { /*action*/ if ( STATE_DOING == a_actionList[ACTION_SAMPLE_DATA].state ) { DBG_PRINTLN("**Sample"); ret = sensorMgt.run(); if ( ret ) { a_actionList[ACTION_SAMPLE_DATA].state = STATE_DONE; } else { delay(10); } } if ( STATE_DOING == a_actionList[ACTION_SAVE_DATA].state ) { if ( STATE_DONE == a_actionList[ACTION_SAMPLE_DATA].state ) { DBG_PRINTLN("**Save"); for ( uint8_t i = 0; i < DATA_TYPE_MAXNUM; i++ ) { if ( false == a_measureData[i].valid ) { break; } dataType = a_measureData[i].dataType; data = a_measureData[i].p_sensor->getValue( dataType ); dataHouse.putData( data, dataType, currentHour ); } a_actionList[ACTION_SAVE_DATA].state = STATE_DONE; } } if ( STATE_DOING == a_actionList[ACTION_DISPLAY].state ) { if (STATE_DONE == a_actionList[ACTION_SAMPLE_DATA].state) { displayMgt.state = DISPLAY_STATE_NEXT; } if ( DISPLAY_STATE_NEXT == displayMgt.state ) { DBG_PRINTLN("**Display"); displayNext(); a_actionList[ACTION_DISPLAY].state = STATE_DONE; } } if ( STATE_DONE == getActionState() ) { startTime = millis()/1000; if( (END_HOURTIME_ONEDAY == currentHour) && (EVENT_STATE_DOING == eventRTCState) ) { //todo: muti thread DBG_PRINTLN_VAR(currentHour,DEC); dataHouse.updateDate( currentYear, currentMonth, currentDate ); } eventRTCState = EVENT_STATE_DONE; eventButtonState = EVENT_STATE_DONE; for ( uint8_t i = 0; i < ACTION_NUMBER; i++ ) //todo { a_actionList[i].state = STATE_INIT; } systemState = SYS_STATE_WAITING; DBG_PRINTLN_VAR(systemState,DEC); } } #if 0 DateTime now = RTCObj.now(); Serial.println(now.minute(), DEC); Serial.print(now.year(), DEC); Serial.print('/'); Serial.print(now.month(), DEC); Serial.print('/'); Serial.print(now.date(), DEC); Serial.print(' '); Serial.print(now.hour(), DEC); Serial.print(':'); Serial.print(now.minute(), DEC); Serial.print(':'); Serial.print(now.second(), DEC); Serial.println(' '); Serial.println(RTCObj.getTemperature()); #endif }
Swall::Swall(QWidget *parent) : QWidget(parent) { //sndt_key = new QString(""); //sndf_key = new QString(""); // think I don't need playplay due to g_playmode // m_playplay = true; // this does not seem to have the right or any effect. why? /* QMap<QString, QString>::const_iterator ii = cfgmap.constBegin(); while (ii != cfgmap.constEnd()) { qDebug() << ii.key() << ": " << ii.value(); ++ii; } */ QGridLayout *grid = new QGridLayout(this); grid->setSpacing(2); QPushButton *quit = new QPushButton("Quit", this); grid->addWidget(quit, 11,0); connect(quit, SIGNAL(clicked()), qApp, SLOT(quit())); QPushButton *savecfg = new QPushButton("Save Config", this); grid->addWidget(savecfg, 11,2); connect(savecfg, SIGNAL(clicked()), this, SLOT(saveconfig())); QPushButton *loadcfg = new QPushButton("Load Config", this); grid->addWidget(loadcfg, 11,3); connect(loadcfg, SIGNAL(clicked()), this, SLOT(loadconfig())); QPushButton *playmode = new QPushButton("Play Mode", this); playmode->setCheckable(1); playmode->setChecked(1); grid->addWidget(playmode, 11,5); connect(playmode, SIGNAL(clicked()), this, SLOT(processplaymode())); QPushButton *editmode = new QPushButton("Edit Mode", this); editmode->setCheckable(1); grid->addWidget(editmode, 11,6); connect(editmode, SIGNAL(clicked()), this, SLOT(processeditmode())); QButtonGroup* buttonGroup = new QButtonGroup(this) ; buttonGroup->addButton(playmode); buttonGroup->addButton(editmode); QPushButton *help = new QPushButton("Help", this); grid->addWidget(help, 11,7); connect(help, SIGNAL(clicked()), this, SLOT(help())); QPushButton *about = new QPushButton("About", this); grid->addWidget(about, 11,8); connect(about, SIGNAL(clicked()), this, SLOT(about())); QPushButton *notes = new QPushButton("Notes", this); grid->addWidget(notes, 11,9); connect(notes, SIGNAL(clicked()), this, SLOT(notes())); QPalette pal; pal.setColor( QPalette::Active, QPalette::Button, "Blue" ); pal.setColor( QPalette::Active, QPalette::ButtonText, "Yellow" ); pal.setColor( QPalette::Inactive, QPalette::Button, "Cyan" ); pal.setColor( QPalette::Inactive, QPalette::ButtonText, "Green" ); // QButtonGroup* gridGroup = new QButtonGroup(this) ; // gridGroup->setExclusive(0); for (int row=0; row<10; row++) { for (int col=0; col<10; col++) { SPushButton *btn = new SPushButton("", this); // qDebug() << "Making SPushButtons for the grid."; btn->setFixedSize(115, 80); btn->setCheckable(1); // btn->setAutoDefault(false); btn->setPalette( pal ); QString sndt_key; QString some_sndt; QString some_butid; // sndt_key = new QString(""); some_sndt.append(QString("Cut::R")); some_sndt.append(QString("%1").arg(row)); some_sndt.append(QString(":C")); some_sndt.append(QString("%1").arg(col)); sndt_key.append(QString("sndt")); sndt_key.append(QString("%1").arg(row)); sndt_key.append(QString("%1").arg(col)); some_butid.append(QString("%1").arg(row)); some_butid.append(QString("%1").arg(col)); some_sndt = cfgmap[sndt_key]; QString sndf_key; QString some_sndf; // sndf_key = new QString(""); some_sndf.append(QString("cut_r")); some_sndf.append(QString("%1").arg(row)); some_sndf.append(QString("_c")); some_sndf.append(QString("%1").arg(col)); some_sndf.append(QString(".mp3")); sndf_key.append(QString("sndf")); sndf_key.append(QString("%1").arg(row)); sndf_key.append(QString("%1").arg(col)); some_sndf = cfgmap[sndf_key]; btn->setSndf(some_sndf); btn->setSndfKey(sndf_key); btn->setSndt(some_sndt); btn->setSndtKey(sndt_key); btn->setButId(some_butid); btn->setProcId("00"); btn->setText(btn->getSndt()); btn->setPlayb(false); btn->setSndLoop(false); connect(btn, SIGNAL(clicked()), btn, SLOT(processButton())); connect(this, SIGNAL(sbutconfig(QString, QString, QString)), btn, SLOT(updateButConfig(QString, QString, QString))); grid->addWidget(btn, row, col); } } setLayout(grid); }
void Visualight::joinWifi(){ VPRINTLN(F("-JOINWIFI-")); /* Setup the WiFly to connect to a wifi network */ processButton(); //check button for reset VPRINT("network: "); VPRINTLN(network); VPRINT("password: "******"security: "); VPRINTLN(security); wifly.reboot(); wifly.setSSID(network); wifly.setAuth(0); if (security[0] == '1'){ //WPA2 VPRINTLN(F("type: WPA2")); wifly.setPassphrase(password); } else if (security[0] == '2'){ VPRINTLN(F("type: WEP-128")); wifly.setKey(password); } else if (security[0] == '3'){ VPRINTLN(F("type: OPEN")); // no setKey / passphrase } else if(security[0] == '4'){ //WEP-64 VPRINTLN(F("CONFIGURE WEP-64")); wifly.setAuth(8); wifly.setKey(password); } else { VPRINT(F("type UNKNOWN: ")); VPRINTLN(security[0]); } wifly.setJoin(WIFLY_WLAN_JOIN_AUTO); wifly.save(); //saving in setWiFlyLeds setWiFlyLeds(wiflyLedFlag, false); wifly.reboot(); if(!wifly.isAssociated()){ //-- not currently on a wifi network VPRINTLN(F("Joining network")); if (wifly.join()) { //-- joined VPRINTLN(F("Joined wifi network")); if(!connectToServer()){ reconnectCount++; } } else { //-- not able to join wifi network VPRINTLN(F("Failed to join wifi network")); delay(1000); for (int i=0; i<5; i++){ digitalWrite(_red, HIGH); delay(100); digitalWrite(_red, LOW); delay(100); } reconnectCount++; if(reconnectCount > 2){ reconnectCount = 0; wifiReset(); // sets light to server mode after wifi fail 3x // most likely bad WiFi credentials/security } else joinWifi(); } } else{ //-- associated with wifi network, continue on as normal if(isServer){ VPRINTLN(F("Switching to Client Mode")); EEPROM.write(0, 0); alerting = false; isServer = false; fadeOn(); // turn on LEDs to startColor (in EEPROM, white from factoryRestore) } if(!connectToServer()){ reconnectCount++; } } }