/*..........................................................................*/ void BSP_terminate(int16_t result) { (void)result; #ifdef Q_SPY l_running = (uint8_t)0; /* stop the QS output thread */ #endif QF_stop(); /* stop the main "ticker thread" */ }
/*..........................................................................*/ QState Ped_wait(Ped *me) { switch (Q_SIG(me)) { case Q_ENTRY_SIG: { BSP_showState(me->super.prio, "wait"); me->retryCtr = N_ATTEMPTS; QActive_arm((QActive *)me, WAIT_TOUT); return Q_HANDLED(); } case Q_TIMEOUT_SIG: { if ((--me->retryCtr) != 0) { QActive_arm((QActive *)me, WAIT_TOUT); QActive_post((QActive *)&AO_Pelican, PEDS_WAITING_SIG, 0); } else { return Q_TRAN(&Ped_off); } return Q_HANDLED(); } case TERMINATE_SIG: { QF_stop(); return Q_HANDLED(); } } return Q_SUPER(&QHsm_top); }
/*..........................................................................*/ static DWORD WINAPI idleThread(LPVOID par) {/* signature for CreateThread() */ (void)par; l_running = (uint8_t)1; while (l_running) { Sleep(10); /* wait for a while */ if (_kbhit()) { /* any key pressed? */ char payload[1024]; if(!gets_s(payload, sizeof(payload))) { // EOF reached printf("EOF received; exiting\n"); QF_stop(); } else { uint16_t len = strlen(payload); onPacket(payload, len, BSPConsole_print, NULL); } } #ifdef Q_SPY { uint16_t nBytes = 1024; uint8_t const *block; QF_CRIT_ENTRY(dummy); block = QS_getBlock(&nBytes); QF_CRIT_EXIT(dummy); if (block != (uint8_t *)0) { send(l_sock, (char const *)block, nBytes, 0); } } #endif } return 0; /* return success */ }
/*..........................................................................*/ QState UI_top_final(UI_top *me, QEvt const *e) { switch (e->sig) { case Q_ENTRY_SIG: { QF_stop(); /* stop QF and cleanup */ return Q_HANDLED(); } } return Q_SUPER(&QHsm_top); }
/*..........................................................................*/ QState UI_top_final(UI_top *me) { switch (Q_SIG(me)) { case Q_ENTRY_SIG: { QF_stop(); /* cleanup and exit */ return Q_HANDLED(); } } return Q_SUPER(&QHsm_top); }
/*--------------------------------------------------------------------------*/ void Q_onAssert(char const Q_ROM * const file, int line) { Video_clearRect(0, 24, 80, 25, VIDEO_BGND_RED); Video_printStrAt(0, 24, VIDEO_FGND_WHITE, "ASSERTION FAILED in file:"); Video_printStrAt(26, 24, VIDEO_FGND_YELLOW, file); Video_printStrAt(57, 24, VIDEO_FGND_WHITE, "line:"); Video_printNumAt(62, 24, VIDEO_FGND_YELLOW, line); QF_stop(); /* stop QF and cleanup */ }
/*..........................................................................*/ void Q_onAssert(char const * const module, int_t loc) { char message[80]; QF_stop(); /* stop ticking */ QS_ASSERTION(module, loc, (uint32_t)10000U); /* report assertion to QS */ SNPRINTF_S(message, Q_DIM(message) - 1, "Assertion failed in module %s location %d", module, loc); MessageBox(l_hWnd, message, "!!! ASSERTION !!!", MB_OK | MB_ICONEXCLAMATION | MB_APPLMODAL); BSP_terminate(-1); }
/*..........................................................................*/ QState Sensor_final(Sensor *me) { switch (Q_SIG(me)) { case Q_ENTRY_SIG: { printf("-> final\n"); printf("\nBye!Bye!\n"); QF_stop(); /* terminate the application */ return Q_HANDLED(); } } return Q_SUPER(&QHsm_top); }
/*..........................................................................*/ void QF_onClockTick(void) { QF_TICK_X(0U, (void *)0); /* perform the QF clock tick processing */ if (_kbhit()) { /* any key pressed? */ switch (_getch()) { case '\33': { /* ESC pressed? */ QF_stop(); break; } } } }
/*..........................................................................*/ QState AlarmClock_final(AlarmClock *me, QEvent const *e) { (void)me; /* avoid the compiler warning about unused parameter */ switch (e->sig) { case Q_ENTRY_SIG: { printf("-> final\nBye!Bye!\n"); QF_stop(); /* terminate the application */ return Q_HANDLED(); } } return Q_SUPER(&QHsm_top); }
/*..........................................................................*/ void BSP_terminate(int16_t result) { (void)result; #ifdef Q_SPY if (l_sock != INVALID_SOCKET) { closesocket(l_sock); l_sock = INVALID_SOCKET; } #endif QF_stop(); PostQuitMessage(result); OwnerDrawnButton_xtor(&l_pauseBtn); /* cleanup the l_pauseBtn resources */ SegmentDisplay_xtor(&l_philos); /* cleanup the l_philos resources */ }
/*..........................................................................*/ QState Tunnel_final(Tunnel *me, QEvt const *e) { (void)me; /* avoid compiler warning */ switch (e->sig) { case Q_ENTRY_SIG: { /* clear the screen */ memset(l_frame, (uint8_t)0, (GAME_SCREEN_WIDTH * GAME_SCREEN_HEIGHT/8)); BSP_drawBitmap(l_frame, GAME_SCREEN_WIDTH, GAME_SCREEN_HEIGHT); QF_stop(); /* stop QF and cleanup */ return Q_HANDLED(); } } return Q_SUPER(&QHsm_top); }
/*..........................................................................*/ QState Cruncher_final(Cruncher * const me) { QState status; switch (Q_SIG(me)) { case Q_ENTRY_SIG: { QF_stop(); /* terminate the application */ status = Q_HANDLED(); break; } default: { status = Q_SUPER(&QHsm_top); break; } } return status; }
/*..........................................................................*/ void BSP_terminate(int16_t result) { #ifdef Q_SPY if (l_sock != INVALID_SOCKET) { closesocket(l_sock); l_sock = INVALID_SOCKET; } #endif QF_stop(); /* stop the main QF application and the ticker thread */ PostQuitMessage(result); /* post the Quit message to the GUI */ GraphicDisplay_xtor(&l_oled); /* cleanup the l_oled resources */ OwnerDrawnButton_xtor(&l_userBtn); /* cleanup the l_userBtn resources */ SegmentDisplay_xtor(&l_userLED); /* cleanup the l_userLED resources */ SegmentDisplay_xtor(&l_scoreBoard); /* cleanup the scoreBoard resources */ }
/*..........................................................................*/ QState AlarmClock_final(AlarmClock * const me) { QState status; switch (Q_SIG(me)) { case Q_ENTRY_SIG: { printf("-> final\n"); QF_stop(); /* terminate the application */ status = Q_HANDLED(); break; } default: { status = Q_SUPER(&QHsm_top); break; } } return status; }
/*..........................................................................*/ QState Cruncher_final(Cruncher * const me, QEvt const * const e) { QState status; switch (e->sig) { case Q_ENTRY_SIG: { printf("final-ENTRY;\nBye!Bye!\n"); QF_stop(); /* terminate the application */ status = Q_HANDLED(); break; } default: { status = Q_SUPER(&QHsm_top); break; } } return status; }
/*..........................................................................*/ void QF_onClockTick(void) { struct timeval timeout = { 0, 0 }; /* timeout for select() */ fd_set con; /* FD set representing the console */ QF_TICK_X(0U, (void *)0); /* process all QF time events at rate 0 */ FD_ZERO(&con); FD_SET(0, &con); /* check if a console input is available, returns immediately */ if (0 != select(1, &con, 0, 0, &timeout)) { /* any descriptor set? */ char ch; read(0, &ch, 1); if (ch == '\33') { /* ESC pressed? */ QF_stop(); } } }
/*..........................................................................*/ QState Ped_off(Ped *me) { switch (Q_SIG(me)) { case Q_ENTRY_SIG: { BSP_showState(me->super.prio, "off"); QActive_arm((QActive *)me, OFF_TOUT); QActive_post((QActive *)&AO_Pelican, OFF_SIG, 0); return Q_HANDLED(); } case Q_TIMEOUT_SIG: { QActive_post((QActive *)&AO_Pelican, ON_SIG, 0); return Q_TRAN(&Ped_wait); } case TERMINATE_SIG: { QF_stop(); return Q_HANDLED(); } } return Q_SUPER(&QHsm_top); }
/*..........................................................................*/ static QState ModIo2Mgr_running(ModIo2Mgr *me, QEvent const *e) { switch (e->sig) { case TERMINATE_SIG: { QF_stop(); return Q_HANDLED(); } case ENABLE_RELAY_SIG: { modIo2Mgr_enableRelay(((Uint8Evt*)e)->data); //omxEval_led_on(LED_4); /* for debugging purposes */ return Q_HANDLED(); } case DISABLE_RELAY_SIG: { /* TODO: disable the relay here, relay number can be obtained from event data */ modIo2Mgr_disableRelay(((Uint8Evt*)e)->data); //omxEval_led_off(LED_4); /* for debugging purposes */ return Q_HANDLED(); } } return Q_SUPER(&QHsm_top); }
/*..........................................................................*/ void Q_onAssert(char const Q_ROM * const file, int line) { fprintf(stderr, "Assertion failed in %s, line %d", file, line); QF_stop(); }
/*..........................................................................*/ void BSP_terminate(int16_t result) { printf("\nBye! Bye!\n"); QF_stop(); (void)result; }
/*..........................................................................*/ void BSP_terminate(int16_t result) { (void)result; QF_stop(); }