void KMahjongg::gameOver( unsigned short numRemoved, unsigned short cheats) { int time; int score; gameTimer->pause(); long gameNum = bw->getGameNum(); KMessageBox::information(this, i18n("You have won!")); bw->animateMoveList(); int elapsed = gameTimer->toInt(); time = score = 0; // get the time in milli secs // subtract from 20 minutes to get bonus. if longer than 20 then ignore time = (60*20) - gameTimer->toInt(); if (time <0) time =0; // conv back to secs (max bonus = 60*20 = 1200 // points per removed tile bonus (for deragon max = 144*10 = 1440 score += (numRemoved * 20); // time bonus one point per second under one hour score += time; // points per cheat penalty (max penalty = 1440 for dragon) score -= (cheats *20); if (score < 0) score = 0; theHighScores->checkHighScore(score, elapsed, gameNum, bw->getBoardName()); timerReset(); }
static int luaModelResetTimer(lua_State *L) { unsigned int idx = luaL_checkunsigned(L, 1); if (idx < MAX_TIMERS) { timerReset(idx); } return 0; }
/** Constructor. */ KMahjongg::KMahjongg( QWidget* parent, const char *name) : KMainWindow(parent, name) { boardEditor = 0; // init board widget bw = new BoardWidget( this ); setCentralWidget( bw ); previewLoad = new Preview(this); setupStatusBar(); setupKAction(); gameTimer = new GameTimer(toolBar()); toolBar()->insertWidget(ID_GAME_TIMER, gameTimer->width() , gameTimer); toolBar()->alignItemRight( ID_GAME_TIMER, true ); theHighScores = new HighScore(this); bDemoModeActive = false; connect( bw, SIGNAL( statusTextChanged(const QString&, long) ), SLOT( showStatusText(const QString&, long) ) ); connect( bw, SIGNAL( tileNumberChanged(int,int,int) ), SLOT( showTileNumber(int,int,int) ) ); connect( bw, SIGNAL( demoModeChanged(bool) ), SLOT( demoModeChanged(bool) ) ); connect( bw, SIGNAL( gameOver(unsigned short , unsigned short)), this, SLOT( gameOver(unsigned short , unsigned short))); connect(bw, SIGNAL(gameCalculated()), this, SLOT(timerReset())); // Make connections for the preview load dialog connect( previewLoad, SIGNAL( boardRedraw(bool) ), bw, SLOT( drawBoard(bool) ) ); connect( previewLoad, SIGNAL( layoutChange() ), this, SLOT( newGame() ) ); connect( previewLoad, SIGNAL( loadBackground(const QString&, bool) ), bw, SLOT(loadBackground(const QString&, bool) ) ); connect( previewLoad, SIGNAL( loadTileset(const QString &) ), bw, SLOT(loadTileset(const QString&) ) ); connect( previewLoad, SIGNAL( loadBoard(const QString&) ), SLOT(loadBoardLayout(const QString&) ) ); startNewGame( ); }
void onMainViewMenu(const char *result) { if (result == STR_RESET_TIMER1) { timerReset(0); } else if (result == STR_RESET_TIMER2) { timerReset(1); } #if TIMERS > 2 else if (result == STR_RESET_TIMER3) { timerReset(2); } #endif #if defined(CPUARM) else if (result == STR_VIEW_NOTES) { pushModelNotes(); } else if (result == STR_RESET_SUBMENU) { MENU_ADD_ITEM(STR_RESET_FLIGHT); MENU_ADD_ITEM(STR_RESET_TIMER1); MENU_ADD_ITEM(STR_RESET_TIMER2); MENU_ADD_ITEM(STR_RESET_TIMER3); #if defined(FRSKY) MENU_ADD_ITEM(STR_RESET_TELEMETRY); #endif } #endif #if defined(FRSKY) else if (result == STR_RESET_TELEMETRY) { telemetryReset(); } #endif else if (result == STR_RESET_FLIGHT) { flightReset(); } else if (result == STR_STATISTICS) { chainMenu(menuStatisticsView); } #if defined(CPUARM) else if (result == STR_ABOUT_US) { chainMenu(menuAboutView); } #endif }
void timerExit(void) { Timer *timer; timerReset(); while (freeTimers != NULL) { timer = freeTimers; freeTimers = timer->next; free(timer); } }
void timerInit(void) { Timer *timer; int i; for (i = 0; i < NUMBER_TIMERS; i++) { timer = malloc(sizeof(Timer)); if (timer == NULL) { error("cannot allocate simulation timers"); } timer->next = freeTimers; freeTimers = timer; } timerReset(); }
// --------------------------------------------------------- void KMahjongg::startNewGame( int item ) { if( ! bDemoModeActive ) { bw->calculateNewGame(item); // initialise button states bw->Game.allow_redo = bw->Game.allow_undo = 0; timerReset(); // update the initial enabled/disabled state for // the menu and the tool bar. demoModeChanged(false); } }
int rcxWakeupTower (void* port, int timeout_ms) { // wake up message char msg[] = { 0x10, 0xfe, 0x10, 0xfe }; // keep alive message char keepalive[] = { 0xff }; // receive buffer char buf[BUFFERSIZE]; // timer timeval timer; // received bytes int count = 0; // First, I send a KeepAlive Byte to settle IR Tower... rcxReset(port); rcxWrite(port, &keepalive, 1); rcxReset(port); timerReset(&timer); do { // write message int written = rcxWrite(port, msg, sizeof(msg)); if (written != sizeof(msg)) { rcxPerror("write"); return RCX_WRITE_FAIL; } // read response int read = rcxRead(port, buf, BUFFERSIZE, 50); count += read; if (__comm_debug) printf("read = %d\n", read); if (__comm_debug) hexdump("R", buf, read); // test response if (read == sizeof(msg) && !memcmp(buf, msg, sizeof(msg))) { return RCX_OK; } rcxReset(port); } while (timerRead(&timer) < timeout_ms); return count == 0? RCX_NO_TOWER : RCX_BAD_LINK; }
void KMahjongg::restartGame() { if( ! bDemoModeActive ) { bw->calculateNewGame(bw->getGameNum()); // initialise button states bw->Game.allow_redo = bw->Game.allow_undo = 0; timerReset(); // update the initial enabled/disabled state for // the menu and the tool bar. demoModeChanged(false); if (is_paused) { pauseAction->setChecked(false); is_paused = false; bw->pause(); } } }
void usb::poll() { USB_USBTask(); Endpoint_SelectEndpoint(VENDOR_OUT_EPADDR); if (Endpoint_IsOUTReceived()) { led::setState(led::YELLOW, true); timerReset(); usb::InputBuff.length = USB_SETTINGS_HOST_TO_DEVICE_DATAPACKET_SIZE; Endpoint_Read_Stream_LE(usb::InputBuff.data, VENDOR_OUT_EPSIZE, NULL); Endpoint_Read_Stream_LE(usb::InputBuff.data + VENDOR_OUT_EPSIZE, VENDOR_OUT_EPSIZE, NULL); Endpoint_ClearOUT(); usb::executeCommandsFromUSB(); Endpoint_SelectEndpoint(VENDOR_IN_EPADDR); Endpoint_Write_Stream_LE(usb::OutputBuff.data, VENDOR_IN_EPSIZE, NULL); Endpoint_ClearIN(); led::setState(led::YELLOW, false); } }
void menuMainView(uint8_t event) { STICK_SCROLL_DISABLE(); uint8_t view = g_eeGeneral.view; uint8_t view_base = view & 0x0f; switch(event) { case EVT_ENTRY: killEvents(KEY_EXIT); killEvents(KEY_UP); killEvents(KEY_DOWN); break; /* TODO if timer2 is OFF, it's possible to use this timer2 as in er9x... case EVT_KEY_BREAK(KEY_MENU): if (view_base == VIEW_TIMER2) { Timer2_running = !Timer2_running; AUDIO_KEYPAD_UP(); } break; */ case EVT_KEY_BREAK(KEY_RIGHT): case EVT_KEY_BREAK(KEY_LEFT): if (view_base <= VIEW_INPUTS) { #if defined(PCBSKY9X) if (view_base == VIEW_INPUTS) g_eeGeneral.view ^= ALTERNATE_VIEW; else g_eeGeneral.view = (g_eeGeneral.view + (4*ALTERNATE_VIEW) + ((event==EVT_KEY_BREAK(KEY_LEFT)) ? -ALTERNATE_VIEW : ALTERNATE_VIEW)) % (4*ALTERNATE_VIEW); #else g_eeGeneral.view ^= ALTERNATE_VIEW; #endif eeDirty(EE_GENERAL); AUDIO_KEYPAD_UP(); } break; #if defined(NAVIGATION_MENUS) case EVT_KEY_CONTEXT_MENU: killEvents(event); #if defined(CPUARM) if (modelHasNotes()) { MENU_ADD_ITEM(STR_VIEW_NOTES); } #endif #if defined(CPUARM) MENU_ADD_ITEM(STR_RESET_SUBMENU); #else MENU_ADD_ITEM(STR_RESET_TIMER1); MENU_ADD_ITEM(STR_RESET_TIMER2); #if defined(FRSKY) MENU_ADD_ITEM(STR_RESET_TELEMETRY); #endif MENU_ADD_ITEM(STR_RESET_FLIGHT); #endif MENU_ADD_ITEM(STR_STATISTICS); #if defined(CPUARM) MENU_ADD_ITEM(STR_ABOUT_US); #endif menuHandler = onMainViewMenu; break; #endif #if MENUS_LOCK != 2 /*no menus*/ case EVT_KEY_LONG(KEY_MENU):// go to last menu pushMenu(lastPopMenu()); killEvents(event); break; CASE_EVT_ROTARY_BREAK case EVT_KEY_MODEL_MENU: pushMenu(menuModelSelect); killEvents(event); break; CASE_EVT_ROTARY_LONG case EVT_KEY_GENERAL_MENU: pushMenu(menuGeneralSetup); killEvents(event); break; #endif case EVT_KEY_BREAK(KEY_UP): case EVT_KEY_BREAK(KEY_DOWN): g_eeGeneral.view = (event == EVT_KEY_BREAK(KEY_UP) ? (view_base == VIEW_COUNT-1 ? 0 : view_base+1) : (view_base == 0 ? VIEW_COUNT-1 : view_base-1)); eeDirty(EE_GENERAL); AUDIO_KEYPAD_UP(); break; case EVT_KEY_STATISTICS: chainMenu(menuStatisticsView); killEvents(event); break; case EVT_KEY_TELEMETRY: #if defined(FRSKY) if (!IS_FAI_ENABLED()) chainMenu(menuTelemetryFrsky); #elif defined(JETI) JETI_EnableRXD(); // enable JETI-Telemetry reception chainMenu(menuTelemetryJeti); #elif defined(ARDUPILOT) ARDUPILOT_EnableRXD(); // enable ArduPilot-Telemetry reception chainMenu(menuTelemetryArduPilot); #elif defined(NMEA) NMEA_EnableRXD(); // enable NMEA-Telemetry reception chainMenu(menuTelemetryNMEA); #elif defined(MAVLINK) chainMenu(menuTelemetryMavlink); #else chainMenu(menuStatisticsDebug); #endif killEvents(event); break; case EVT_KEY_FIRST(KEY_EXIT): #if defined(GVARS) && !defined(PCBSTD) if (s_gvar_timer > 0) { s_gvar_timer = 0; } #endif if (view == VIEW_TIMER2) { timerReset(1); } AUDIO_KEYPAD_UP(); break; #if !defined(NAVIGATION_MENUS) case EVT_KEY_LONG(KEY_EXIT): flightReset(); AUDIO_KEYPAD_UP(); break; #endif } { // Flight Mode Name uint8_t mode = mixerCurrentFlightMode; lcd_putsnAtt(PHASE_X, PHASE_Y, g_model.flightModeData[mode].name, sizeof(g_model.flightModeData[mode].name), ZCHAR|PHASE_FLAGS); // Model Name putsModelName(MODELNAME_X, MODELNAME_Y, g_model.header.name, g_eeGeneral.currModel, BIGSIZE); // Main Voltage (or alarm if any) displayVoltageOrAlarm(); // Timers displayTimers(); // Trims sliders displayTrims(mode); } if (view_base < VIEW_INPUTS) { // scroll bar lcd_hlineStip(38, 34, 54, DOTTED); #if defined(PCBSKY9X) lcd_hline(38 + (g_eeGeneral.view / ALTERNATE_VIEW) * 13, 34, 13, SOLID); #else lcd_hline((g_eeGeneral.view & ALTERNATE_VIEW) ? 64 : 38, 34, 26, SOLID); #endif for (uint8_t i=0; i<8; i++) { uint8_t x0,y0; #if defined(PCBSKY9X) uint8_t chan = 8*(g_eeGeneral.view / ALTERNATE_VIEW) + i; #else uint8_t chan = (g_eeGeneral.view & ALTERNATE_VIEW) ? 8+i : i; #endif int16_t val = channelOutputs[chan]; switch(view_base) { case VIEW_OUTPUTS_VALUES: x0 = (i%4*9+3)*FW/2; y0 = i/4*FH+40; #if defined(PPM_UNIT_US) lcd_outdezAtt(x0+4*FW , y0, PPM_CH_CENTER(chan)+val/2, 0); #elif defined(PPM_UNIT_PERCENT_PREC1) lcd_outdezAtt(x0+4*FW , y0, calcRESXto1000(val), PREC1); #else lcd_outdezAtt(x0+4*FW , y0, calcRESXto1000(val)/10, 0); // G: Don't like the decimal part* #endif break; case VIEW_OUTPUTS_BARS: #define WBAR2 (50/2) x0 = i<4 ? LCD_W/4+2 : LCD_W*3/4-2; y0 = 38+(i%4)*5; uint16_t lim = g_model.extendedLimits ? 640*2 : 512*2; int8_t len = (abs(val) * WBAR2 + lim/2) / lim; if(len>WBAR2) len = WBAR2; // prevent bars from going over the end - comment for debugging lcd_hlineStip(x0-WBAR2, y0, WBAR2*2+1, DOTTED); lcd_vline(x0,y0-2,5); if (val>0) x0+=1; else x0-=len; lcd_hline(x0,y0+1,len); lcd_hline(x0,y0-1,len); break; } } } else if (view_base == VIEW_INPUTS) { if (view == VIEW_INPUTS) { // Sticks + Pots doMainScreenGraphics(); // Switches for (uint8_t i=SWSRC_THR; i<=SWSRC_TRN; i++) { int8_t sw = (i == SWSRC_TRN ? (switchState(SW_ID0) ? SWSRC_ID0 : (switchState(SW_ID1) ? SWSRC_ID1 : SWSRC_ID2)) : i); uint8_t x = 2*FW-2, y = i*FH+1; if (i>=SWSRC_AIL) { x = 17*FW-1; y -= 3*FH; } putsSwitches(x, y, sw, getSwitch(i) ? INVERS : 0); } } else { #if defined(PCBMEGA2560) && defined(ROTARY_ENCODERS) for (uint8_t i=0; i<NUM_ROTARY_ENCODERS; i++) { int16_t val = getRotaryEncoder(i); int8_t len = limit((int16_t)0, (int16_t)(((val+1024) * BAR_HEIGHT) / 2048), (int16_t)BAR_HEIGHT); #if ROTARY_ENCODERS > 2 #define V_BAR_W 5 V_BAR(LCD_W/2-8+V_BAR_W*i, LCD_H-8, len); #else #define V_BAR_W 5 V_BAR(LCD_W/2-3+V_BAR_W*i, LCD_H-8, len); #endif } #endif // PCBGRUVIN9X && ROTARY_ENCODERS // Logical Switches #if defined(PCBSKY9X) for (uint8_t i=0; i<NUM_LOGICAL_SWITCH; i++) { int8_t len = getSwitch(SWSRC_SW1+i) ? BAR_HEIGHT : 1; uint8_t x = VSWITCH_X(i); lcd_vline(x-1, VSWITCH_Y-len, len); lcd_vline(x, VSWITCH_Y-len, len); } #elif defined(CPUM2560) for (uint8_t i=0; i<NUM_LOGICAL_SWITCH; i++) putsSwitches(2*FW-3 + (i/3)*(i/3>2 ? 3*FW+2 : (3*FW-1)) + (i/3>2 ? 2*FW : 0), 4*FH+1 + (i%3)*FH, SWSRC_SW1+i, getSwitch(SWSRC_SW1+i) ? INVERS : 0); #elif !defined(PCBSTD) for (uint8_t i=0; i<NUM_LOGICAL_SWITCH; i++) putsSwitches(2*FW-2 + (i/3)*(4*FW-1), 4*FH+1 + (i%3)*FH, SWSRC_SW1+i, getSwitch(SWSRC_SW1+i) ? INVERS : 0); #else for (uint8_t i=0; i<NUM_LOGICAL_SWITCH; i++) putsSwitches(2*FW-3 + (i/3)*(4*FW), 4*FH+1 + (i%3)*FH, SWSRC_SW1+i, getSwitch(SWSRC_SW1+i) ? INVERS : 0); #endif } } else { // timer2 #if defined(TRANSLATIONS_CZ) #define TMR2_LBL_COL (20-FW/2+1) #else #define TMR2_LBL_COL (20-FW/2+5) #endif putsTimer(33+FW+2+10*FWNUM-4, FH*5, timersStates[1].val, DBLSIZE, DBLSIZE); putsTimerMode(timersStates[1].val >= 0 ? TMR2_LBL_COL : TMR2_LBL_COL-7, FH*6, g_model.timers[1].mode); // lcd_outdezNAtt(33+11*FW, FH*6, s_timerVal_10ms[1], LEADING0, 2); // 1/100s } // And ! in case of unexpected shutdown if (unexpectedShutdown) { lcd_putcAtt(REBOOT_X, 0*FH, '!', INVERS); } #if defined(GVARS) && !defined(PCBSTD) if (s_gvar_timer > 0) { s_gvar_timer--; s_warning = STR_GLOBAL_VAR; displayBox(); lcd_putsnAtt(16, 5*FH, g_model.gvars[s_gvar_last].name, LEN_GVAR_NAME, ZCHAR); lcd_putsAtt(16+7*FW, 5*FH, PSTR("[\010]"), BOLD); lcd_outdezAtt(16+7*FW+4*FW+FW/2, 5*FH, GVAR_VALUE(s_gvar_last, getGVarFlightPhase(mixerCurrentFlightMode, s_gvar_last)), BOLD); s_warning = NULL; } #endif #if defined(DSM2) if (moduleFlag[0] == MODULE_BIND) { // Issue 98 lcd_putsAtt(15*FW, 0, PSTR("BIND"), 0); } #endif }
void menuTelemetryFrsky(uint8_t event) { if (event == EVT_KEY_FIRST(KEY_EXIT)) { chainMenu(menuMainView); return; } switch (event) { case EVT_KEY_BREAK(KEY_UP): if (s_frsky_view-- == 0) s_frsky_view = FRSKY_VIEW_MAX; break; #if defined(PCBTARANIS) case EVT_KEY_BREAK(KEY_PAGE): #endif case EVT_KEY_BREAK(KEY_DOWN): if (s_frsky_view++ == FRSKY_VIEW_MAX) s_frsky_view = 0; break; #if defined(PCBTARANIS) case EVT_KEY_LONG(KEY_ENTER): killEvents(event); MENU_ADD_ITEM(STR_RESET_TELEMETRY); MENU_ADD_ITEM(STR_RESET_FLIGHT); menuHandler = onMainViewMenu; break; #else case EVT_KEY_FIRST(KEY_ENTER): resetTelemetry(); timerReset(0); break; #endif } lcdDrawTelemetryTopBar(); if (s_frsky_view < MAX_FRSKY_SCREENS) { FrSkyScreenData & screen = g_model.frsky.screens[s_frsky_view]; #if defined(GAUGES) if (g_model.frsky.screensType & (1<<s_frsky_view)) { // Custom Screen with gauges uint8_t barHeight = 5; for (int8_t i=3; i>=0; i--) { FrSkyBarData & bar = screen.bars[i]; uint8_t source = bar.source; getvalue_t barMin = convertTelemValue(source, bar.barMin); getvalue_t barMax = convertTelemValue(source, 255-bar.barMax); if (source && barMax > barMin) { uint8_t y = barHeight+6+i*(barHeight+6); lcd_putsiAtt(0, y+barHeight-5, STR_VTELEMCHNS, source, 0); lcd_rect(25, y, BAR_WIDTH+1, barHeight+2); getvalue_t value = getValue(MIXSRC_FIRST_TELEM+source-2); #if LCD_W >= 212 putsTelemetryChannel(27+BAR_WIDTH, y+barHeight-6, source-1, value, LEFT); #endif getvalue_t threshold = 0; uint8_t thresholdX = 0; if (source <= TELEM_TM2) threshold = 0; else if (source <= TELEM_RSSI_RX) threshold = getRssiAlarmValue(source-TELEM_RSSI_TX); else if (source <= TELEM_A2) threshold = g_model.frsky.channels[source-TELEM_A1].alarms_value[0]; #if defined(FRSKY_HUB) else threshold = convertTelemValue(source, barsThresholds[source-TELEM_ALT]); #endif if (threshold) { thresholdX = barCoord(threshold, barMin, barMax); if (thresholdX == 100) thresholdX = 0; } uint8_t width = barCoord(value, barMin, barMax); // reversed barshade for T1/T2 uint8_t barShade = ((threshold > value) ? DOTTED : SOLID); if (source == TELEM_T1 || source == TELEM_T2) barShade = -barShade; lcd_filled_rect(26, y+1, width, barHeight, barShade); for (uint8_t j=24; j<99; j+=25) if (j>thresholdX || j>width) lcd_vline(j*BAR_WIDTH/100+26, y+1, barHeight); if (thresholdX) { lcd_vlineStip(26+thresholdX, y-2, barHeight+3, DOTTED); lcd_hline(25+thresholdX, y-2, 3); } } else { barHeight += 2; } } displayRssiLine(); lcd_status_line(); } else #endif { // Custom Screen with numbers uint8_t fields_count = 0; for (uint8_t i=0; i<4; i++) { for (uint8_t j=0; j<NUM_LINE_ITEMS; j++) { uint8_t field = screen.lines[i].sources[j]; if (i==3 && j==0) { #if LCD_W >= 212 lcd_vline(69, 8, 48); lcd_vline(141, 8, 48); #else lcd_vline(63, 8, 48); #endif if (TELEMETRY_STREAMING()) { #if defined(FRSKY_HUB) if (field == TELEM_ACC) { lcd_putsLeft(STATUS_BAR_Y, STR_ACCEL); lcd_outdezNAtt(4*FW, STATUS_BAR_Y, frskyData.hub.accelX, LEFT|PREC2); lcd_outdezNAtt(10*FW, STATUS_BAR_Y, frskyData.hub.accelY, LEFT|PREC2); lcd_outdezNAtt(16*FW, STATUS_BAR_Y, frskyData.hub.accelZ, LEFT|PREC2); break; } #if defined(GPS) else if (field == TELEM_GPS_TIME) { displayGpsTime(); return; } #endif #endif } else { displayRssiLine(); lcd_status_line(); return; } } if (field) { fields_count++; getvalue_t value = getValue(MIXSRC_FIRST_TELEM+field-2); uint8_t att = (i==3 ? NO_UNIT : DBLSIZE|NO_UNIT); #if LCD_W >= 212 xcoord_t pos[] = {0, 71, 143, 214}; #else xcoord_t pos[] = {0, 65, 130}; #endif putsTelemetryChannel(pos[j+1]-2, 1+FH+2*FH*i, field-1, value, att); if (field >= TELEM_TM1 && field <= TELEM_TM2 && i!=3) { // there is not enough space on LCD for displaying "Tmr1" or "Tmr2" and still see the - sign, we write "T1" or "T2" instead field = field-TELEM_TM1+TELEM_T1; } if (field == TELEM_TX_VOLTAGE){ lcd_putsAtt(pos[j], 1+FH+2*FH*i,PSTR("TxBat"), 0); // Print "TxBat" instead of TBat. } else {lcd_putsiAtt(pos[j], 1+FH+2*FH*i, STR_VTELEMCHNS, field, 0); } } } } lcd_status_line(); if (fields_count == 0) putEvent(event == EVT_KEY_BREAK(KEY_UP) ? event : EVT_KEY_BREAK(KEY_DOWN)); } } // else if ( s_frsky_view == e_frsky_voltages ) { // // Volts / Amps / Watts / mAh // uint8_t analog = 0; // //lcd_putsiAtt(0, 2*FH, STR_VOLTSRC, g_model.frsky.voltsSource+1, 0); // switch(g_model.frsky.voltsSource) { // case 0: // case 1: // displayVoltageScreenLine(2*FH, g_model.frsky.voltsSource); // analog = 1+g_model.frsky.voltsSource; // break; //#if defined(FRSKY_HUB) // case 2: // lcd_puts(0,2*FH, PSTR("Batt:")); // putsTelemetryChannel(3*FW+6*FW+4, FH+1, TELEM_VFAS-1, frskyData.hub.vfas, DBLSIZE); // break; // case 3: // putsTelemetryChannel(3*FW+6*FW+4, FH+1, TELEM_CELLS_SUM-1, frskyData.hub.cellsSum, DBLSIZE); // break; //#endif // } // if (g_model.frsky.currentSource) { // // lcd_putsiAtt(0, 4*FH, STR_VOLTSRC, g_model.frsky.currentSource, 0); // switch(g_model.frsky.currentSource) { // case 1: // case 2: // displayVoltageScreenLine(4*FH, g_model.frsky.currentSource-1); // break; //#if defined(FRSKY_HUB) // case 3: // lcd_puts(0,4*FH, PSTR("Curr:")); // putsTelemetryChannel(3*FW+6*FW+4, 3*FH+1, TELEM_CURRENT-1, frskyData.hub.current, DBLSIZE); // break; //#endif // } // putsTelemetryChannel(4, 5*FH+1, TELEM_POWER-1, frskyData.hub.power, LEFT|DBLSIZE); // putsTelemetryChannel(3*FW+4+4*FW+6*FW+FW, 5*FH+1, TELEM_CONSUMPTION-1, frskyData.hub.currentConsumption, DBLSIZE); // } // else { // displayVoltageScreenLine(analog > 0 ? 5*FH : 4*FH, analog ? 2-analog : 0); // if (analog == 0) displayVoltageScreenLine(6*FH, 1); // } //#if defined(FRSKY_HUB) // // Cells voltage // if (frskyData.hub.cellsCount > 0) { // uint8_t y = 1*FH; // for (uint8_t k=0; k<frskyData.hub.cellsCount && k<6; k++) { //#if defined(GAUGES) // uint8_t attr = (barsThresholds[THLD_CELL] && frskyData.hub.cellVolts[k] < barsThresholds[THLD_CELL]) ? BLINK|PREC2 : PREC2; //#else // uint8_t attr = PREC2; //#endif // lcd_outdezNAtt(LCD_W, y, frskyData.hub.cellVolts[k] * 2, attr, 4); // y += 1*FH; // } // lcd_vline(LCD_W-3*FW-2, 8, 47); // } //#endif // displayRssiLine(); // lcd_status_line(); // } #if defined(FRSKY_HUB) else if (s_frsky_view == e_frsky_after_flight) { uint8_t line=1*FH+1; if (IS_GPS_AVAILABLE()) { // Latitude lcd_putsLeft(line, STR_LATITUDE); displayGpsCoord(line, frskyData.hub.gpsLatitudeNS, frskyData.hub.gpsLatitude_bp, frskyData.hub.gpsLatitude_ap); // Longitude line+=1*FH+1; lcd_putsLeft(line, STR_LONGITUDE); displayGpsCoord(line, frskyData.hub.gpsLongitudeEW, frskyData.hub.gpsLongitude_bp, frskyData.hub.gpsLongitude_ap); // displayGpsTime(); //lcd_status_line(); line+=1*FH+1; } lcd_putsLeft(line, PSTR("Altitude ")); putsTelemetryChannel(14*FW, line, TELEM_ALT-1, frskyData.hub.baroAltitude_bp, SMLSIZE); displayRssiLine(); lcd_status_line(); // Rssi // lcd_putsLeft(line, STR_MINRSSI); // #if defined(PCBTARANIS) // lcd_outdezNAtt(TELEM_2ND_COLUMN, line, frskyData.rssi[0].min, LEFT|LEADING0, 2); //#else // lcd_puts(TELEM_2ND_COLUMN, line, STR_TX); // lcd_outdezNAtt(TELEM_2ND_COLUMN+3*FW, line, frskyData.rssi[1].min, LEFT|LEADING0, 2); // lcd_puts(TELEM_2ND_COLUMN+6*FW, line, STR_RX); // lcd_outdezNAtt(TELEM_2ND_COLUMN+9*FW, line, frskyData.rssi[0].min, LEFT|LEADING0, 2); //#endif } #endif }
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) { // gui independent initialization // app specific const QString appversion="2.0.2"; const QString appdate="04.07.2016"; const QString appname="PIHK"; const QString appauthor="Frank Zimmermann"; const QString appemail="*****@*****.**"; // Timer related isTimerStarted=false; timerValue=0; offset=0; const QString version = appname + " (V" +appversion +", vom " + appdate + ")"; timer = new QTimer(this); ui->setupUi(this); // gui dependent initialization #ifdef Q_OS_OSX // OSX--- setWindowIcon(QIcon("pihk2.icns")); #else // Windows Q_OS_WIN setWindowIcon(QIcon("pihk2.ico")); #endif statusLabel = new QLabel(this); statusLabel->setText(appemail); this->setFixedSize(this->geometry().width(),this->geometry().height()); ui->listViewPRFG->setStyleSheet("background-color:lightgray;"); ui->listViewMEPR->setStyleSheet("background-color:lightgray;"); // gui stuff ui->pDate->setDate(QDate::currentDate()); // set current Date ui->lcdNumber->setPalette(Qt::black); // set color for LCD this->setWindowTitle(version); // set title ui->statusBar->addPermanentWidget(statusLabel); makeFilename(); // construct basic file name ui->labelGradeA->setStyleSheet("QLabel { color : red; }"); ui->labelGradeB->setStyleSheet("QLabel { color : red; }"); ui->labelGradeResultA->setStyleSheet("QLabel { color : red; }"); ui->labelGradeResultB->setStyleSheet("QLabel { color : red; }"); ui->labelGradeResult->setStyleSheet("QLabel { color : red; }"); ui->spinboxGa1E->setEnabled(false); ui->spinboxGa1E->hide(); ui->spinboxGa1E->setValue(0); ui->spinboxGa2E->setEnabled(false); ui->spinboxGa2E->hide(); ui->spinboxGa2E->setValue(0); ui->spinboxWisoE->setEnabled(false); ui->spinboxWisoE->hide(); ui->spinboxWisoE->setValue(0); ui->radioButton1->setEnabled(false); ui->radioButton2->setEnabled(false); ui->radioButton3->setEnabled(false); // Connections connect(timer,SIGNAL(timeout()),this,SLOT(updateProgressBar())); connect(ui->startTimer,SIGNAL(clicked()),this,SLOT(toggleStartStop())); connect(ui->resetTimer,SIGNAL(clicked()),this,SLOT(timerReset())); connect(ui->pname,SIGNAL(textChanged(QString)),this,SLOT(makeFilename())); connect(ui->pnummer,SIGNAL(textChanged(QString)),this,SLOT(makeFilename())); connect(ui->pDate,SIGNAL(dateChanged(QDate)),this,SLOT(makeFilename())); connect(ui->folder,SIGNAL(textChanged(QString)),this,SLOT(makeFilename())); connect(ui->spinboxDocumentation,SIGNAL(valueChanged(double)),this,SLOT(writeResults())); connect(ui->spinboxExamination,SIGNAL(valueChanged(double)),this,SLOT(writeResults())); connect(ui->spinboxGa1,SIGNAL(valueChanged(double)),this,SLOT(writeResults())); connect(ui->spinboxGa2,SIGNAL(valueChanged(double)),this,SLOT(writeResults())); connect(ui->spinboxWiso,SIGNAL(valueChanged(double)),this,SLOT(writeResults())); connect(ui->spinboxGa1E,SIGNAL(valueChanged(double)),this,SLOT(writeResults())); connect(ui->spinboxGa2E,SIGNAL(valueChanged(double)),this,SLOT(writeResults())); connect(ui->spinboxWisoE,SIGNAL(valueChanged(double)),this,SLOT(writeResults())); connect(ui->radioButton1,SIGNAL(toggled(bool)),this,SLOT(writeResults())); connect(ui->radioButton2,SIGNAL(toggled(bool)),this,SLOT(writeResults())); connect(ui->radioButton3,SIGNAL(toggled(bool)),this,SLOT(writeResults())); connect(ui->saveFile,SIGNAL(clicked(bool)),this,SLOT(saveData())); connect(ui->buttonSimPRFG,SIGNAL(clicked()),this,SLOT(fillPRFG())); connect(ui->buttonSimMEPR,SIGNAL(clicked()),this,SLOT(fillMEPR())); connect(ui->listViewPRFG,SIGNAL(clicked(const QModelIndex &)),this,SLOT(setPointsPRFG(const QModelIndex &))); connect(ui->listViewMEPR,SIGNAL(clicked(const QModelIndex &)),this,SLOT(setPointsMEPR(const QModelIndex &))); }
void evalFunctions() #endif { MASK_FUNC_TYPE newActiveFunctions = 0; MASK_CFN_TYPE newActiveSwitches = 0; #if defined(ROTARY_ENCODERS) && defined(GVARS) static rotenc_t rePreviousValues[ROTARY_ENCODERS]; #endif #if defined(OVERRIDE_CHANNEL_FUNCTION) for (uint8_t i=0; i<NUM_CHNOUT; i++) { safetyCh[i] = OVERRIDE_CHANNEL_UNDEFINED; } #endif #if defined(GVARS) for (uint8_t i=0; i<NUM_STICKS; i++) { trimGvar[i] = -1; } #endif for (uint8_t i=0; i<NUM_CFN; i++) { const CustomFunctionData *cfn = &functions[i]; int8_t swtch = CFN_SWITCH(cfn); if (swtch) { MASK_CFN_TYPE switch_mask = ((MASK_CFN_TYPE)1 << i); #if defined(CPUARM) bool active = getSwitch(swtch, IS_PLAY_FUNC(CFN_FUNC(cfn)) ? GETSWITCH_MIDPOS_DELAY : 0); #else bool active = getSwitch(swtch); #endif if (HAS_ENABLE_PARAM(CFN_FUNC(cfn))) { active &= (bool)CFN_ACTIVE(cfn); } if (active || IS_PLAY_BOTH_FUNC(CFN_FUNC(cfn))) { switch (CFN_FUNC(cfn)) { #if defined(OVERRIDE_CHANNEL_FUNCTION) case FUNC_OVERRIDE_CHANNEL: safetyCh[CFN_CH_INDEX(cfn)] = CFN_PARAM(cfn); break; #endif case FUNC_TRAINER: { uint8_t mask = 0x0f; if (CFN_CH_INDEX(cfn) > 0) { mask = (1<<(CFN_CH_INDEX(cfn)-1)); } newActiveFunctions |= mask; break; } case FUNC_INSTANT_TRIM: newActiveFunctions |= (1 << FUNCTION_INSTANT_TRIM); if (!isFunctionActive(FUNCTION_INSTANT_TRIM)) { #if defined(GUI) if (g_menuStack[0] == menuMainView #if defined(FRSKY) || g_menuStack[0] == menuTelemetryFrsky #endif #if defined(PCBTARANIS) || g_menuStack[0] == menuMainViewChannelsMonitor || g_menuStack[0] == menuChannelsView #endif ) #endif { instantTrim(); } } break; case FUNC_RESET: switch (CFN_PARAM(cfn)) { case FUNC_RESET_TIMER1: case FUNC_RESET_TIMER2: #if defined(CPUARM) case FUNC_RESET_TIMER3: #endif timerReset(CFN_PARAM(cfn)); break; case FUNC_RESET_FLIGHT: flightReset(); break; #if defined(FRSKY) case FUNC_RESET_TELEMETRY: telemetryReset(); break; #endif #if ROTARY_ENCODERS > 0 case FUNC_RESET_ROTENC1: #if ROTARY_ENCODERS > 1 case FUNC_RESET_ROTENC2: #endif g_rotenc[CFN_PARAM(cfn)-FUNC_RESET_ROTENC1] = 0; break; #endif } #if defined(CPUARM) if (CFN_PARAM(cfn)>=FUNC_RESET_PARAM_FIRST_TELEM) { TelemetryItem * telemetryItem = & telemetryItems[CFN_PARAM(cfn)-FUNC_RESET_PARAM_FIRST_TELEM]; telemetryItem->clear(); } #endif break; #if defined(CPUARM) case FUNC_SET_TIMER: { timerSet(CFN_TIMER_INDEX(cfn), CFN_PARAM(cfn)); break; } #endif #if 0 //defined(DANGEROUS_MODULE_FUNCTIONS) case FUNC_RANGECHECK: case FUNC_BIND: case FUNC_MODULE_OFF: { unsigned int moduleIndex = CFN_PARAM(cfn); if (moduleIndex < NUM_MODULES) { moduleFlag[moduleIndex] = 1 + CFN_FUNC(cfn) - FUNC_RANGECHECK; } break; } #endif #if defined(GVARS) case FUNC_ADJUST_GVAR: if (CFN_GVAR_MODE(cfn) == 0) { SET_GVAR(CFN_GVAR_INDEX(cfn), CFN_PARAM(cfn), mixerCurrentFlightMode); } else if (CFN_GVAR_MODE(cfn) == 2) { SET_GVAR(CFN_GVAR_INDEX(cfn), GVAR_VALUE(CFN_PARAM(cfn), mixerCurrentFlightMode), mixerCurrentFlightMode); } else if (CFN_GVAR_MODE(cfn) == 3) { if (!(functionsContext.activeSwitches & switch_mask)) { SET_GVAR(CFN_GVAR_INDEX(cfn), GVAR_VALUE(CFN_GVAR_INDEX(cfn), getGVarFlightPhase(mixerCurrentFlightMode, CFN_GVAR_INDEX(cfn))) + (CFN_PARAM(cfn) ? +1 : -1), mixerCurrentFlightMode); } } else if (CFN_PARAM(cfn) >= MIXSRC_TrimRud && CFN_PARAM(cfn) <= MIXSRC_TrimAil) { trimGvar[CFN_PARAM(cfn)-MIXSRC_TrimRud] = CFN_GVAR_INDEX(cfn); } #if defined(ROTARY_ENCODERS) else if (CFN_PARAM(cfn) >= MIXSRC_REa && CFN_PARAM(cfn) < MIXSRC_TrimRud) { int8_t scroll = rePreviousValues[CFN_PARAM(cfn)-MIXSRC_REa] - (g_rotenc[CFN_PARAM(cfn)-MIXSRC_REa] / ROTARY_ENCODER_GRANULARITY); if (scroll) { SET_GVAR(CFN_GVAR_INDEX(cfn), GVAR_VALUE(CFN_GVAR_INDEX(cfn), getGVarFlightPhase(mixerCurrentFlightMode, CFN_GVAR_INDEX(cfn))) + scroll, mixerCurrentFlightMode); } } #endif else { SET_GVAR(CFN_GVAR_INDEX(cfn), calcRESXto100(getValue(CFN_PARAM(cfn))), mixerCurrentFlightMode); } break; #endif #if defined(CPUARM) && defined(SDCARD) case FUNC_VOLUME: { getvalue_t raw = getValue(CFN_PARAM(cfn)); //only set volume if input changed more than hysteresis if (abs(requiredSpeakerVolumeRawLast - raw) > VOLUME_HYSTERESIS) { requiredSpeakerVolumeRawLast = raw; } requiredSpeakerVolume = ((1024 + requiredSpeakerVolumeRawLast) * VOLUME_LEVEL_MAX) / 2048; break; } #endif #if defined(CPUARM) && defined(SDCARD) case FUNC_PLAY_SOUND: case FUNC_PLAY_TRACK: case FUNC_PLAY_VALUE: #if defined(HAPTIC) case FUNC_HAPTIC: #endif { tmr10ms_t tmr10ms = get_tmr10ms(); uint8_t repeatParam = CFN_PLAY_REPEAT(cfn); if (!IS_SILENCE_PERIOD_ELAPSED() && repeatParam == CFN_PLAY_REPEAT_NOSTART) { functionsContext.lastFunctionTime[i] = tmr10ms; } if (!functionsContext.lastFunctionTime[i] || (repeatParam && repeatParam!=CFN_PLAY_REPEAT_NOSTART && (signed)(tmr10ms-functionsContext.lastFunctionTime[i])>=100*repeatParam)) { if (!IS_PLAYING(i+1)) { functionsContext.lastFunctionTime[i] = tmr10ms; if (CFN_FUNC(cfn) == FUNC_PLAY_SOUND) { AUDIO_PLAY(AU_FRSKY_FIRST+CFN_PARAM(cfn)); } else if (CFN_FUNC(cfn) == FUNC_PLAY_VALUE) { PLAY_VALUE(CFN_PARAM(cfn), i+1); } #if defined(HAPTIC) else if (CFN_FUNC(cfn) == FUNC_HAPTIC) { haptic.event(AU_FRSKY_LAST+CFN_PARAM(cfn)); } #endif else { playCustomFunctionFile(cfn, i+1); } } } break; } case FUNC_BACKGND_MUSIC: newActiveFunctions |= (1 << FUNCTION_BACKGND_MUSIC); if (!IS_PLAYING(i+1)) { playCustomFunctionFile(cfn, i+1); } break; case FUNC_BACKGND_MUSIC_PAUSE: newActiveFunctions |= (1 << FUNCTION_BACKGND_MUSIC_PAUSE); break; #elif defined(VOICE) case FUNC_PLAY_SOUND: case FUNC_PLAY_TRACK: case FUNC_PLAY_BOTH: case FUNC_PLAY_VALUE: { tmr10ms_t tmr10ms = get_tmr10ms(); uint8_t repeatParam = CFN_PLAY_REPEAT(cfn); if (!functionsContext.lastFunctionTime[i] || (CFN_FUNC(cfn)==FUNC_PLAY_BOTH && active!=(bool)(functionsContext.activeSwitches&switch_mask)) || (repeatParam && (signed)(tmr10ms-functionsContext.lastFunctionTime[i])>=1000*repeatParam)) { functionsContext.lastFunctionTime[i] = tmr10ms; uint8_t param = CFN_PARAM(cfn); if (CFN_FUNC(cfn) == FUNC_PLAY_SOUND) { AUDIO_PLAY(AU_FRSKY_FIRST+param); } else if (CFN_FUNC(cfn) == FUNC_PLAY_VALUE) { PLAY_VALUE(param, i+1); } else { #if defined(GVARS) if (CFN_FUNC(cfn) == FUNC_PLAY_TRACK && param > 250) param = GVAR_VALUE(param-251, getGVarFlightPhase(mixerCurrentFlightMode, param-251)); #endif PUSH_CUSTOM_PROMPT(active ? param : param+1, i+1); } } if (!active) { // PLAY_BOTH would change activeFnSwitches otherwise switch_mask = 0; } break; } #else case FUNC_PLAY_SOUND: { tmr10ms_t tmr10ms = get_tmr10ms(); uint8_t repeatParam = CFN_PLAY_REPEAT(cfn); if (!functionsContext.lastFunctionTime[i] || (repeatParam && (signed)(tmr10ms-functionsContext.lastFunctionTime[i])>=1000*repeatParam)) { functionsContext.lastFunctionTime[i] = tmr10ms; AUDIO_PLAY(AU_FRSKY_FIRST+CFN_PARAM(cfn)); } break; } #endif #if defined(FRSKY) && defined(VARIO) case FUNC_VARIO: newActiveFunctions |= (1 << FUNCTION_VARIO); break; #endif #if defined(HAPTIC) && !defined(CPUARM) case FUNC_HAPTIC: { tmr10ms_t tmr10ms = get_tmr10ms(); uint8_t repeatParam = CFN_PLAY_REPEAT(cfn); if (!functionsContext.lastFunctionTime[i] || (repeatParam && (signed)(tmr10ms-functionsContext.lastFunctionTime[i])>=1000*repeatParam)) { functionsContext.lastFunctionTime[i] = tmr10ms; haptic.event(AU_FRSKY_LAST+CFN_PARAM(cfn)); } break; } #endif #if defined(SDCARD) case FUNC_LOGS: if (CFN_PARAM(cfn)) { newActiveFunctions |= (1 << FUNCTION_LOGS); logDelay = CFN_PARAM(cfn); } break; #endif case FUNC_BACKLIGHT: newActiveFunctions |= (1 << FUNCTION_BACKLIGHT); break; #if defined(PCBTARANIS) case FUNC_SCREENSHOT: if (!(functionsContext.activeSwitches & switch_mask)) { requestScreenshot = true; } break; #endif #if defined(DEBUG) case FUNC_TEST: testFunc(); break; #endif } newActiveSwitches |= switch_mask; } else { functionsContext.lastFunctionTime[i] = 0; } } } functionsContext.activeSwitches = newActiveSwitches; functionsContext.activeFunctions = newActiveFunctions; #if defined(ROTARY_ENCODERS) && defined(GVARS) for (uint8_t i=0; i<ROTARY_ENCODERS; i++) { rePreviousValues[i] = (g_rotenc[i] / ROTARY_ENCODER_GRANULARITY); } #endif }