Example #1
0
/*..........................................................................*/
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);
}
Example #2
0
//${HSMs::QHsmTst::SM::s} ....................................................
Q_STATE_DEF(QHsmTst, s) {
    QP::QState status_;
    switch (e->sig) {
        //${HSMs::QHsmTst::SM::s}
        case Q_ENTRY_SIG: {
            BSP_display("s-ENTRY;");
            status_ = Q_RET_HANDLED;
            break;
        }
        //${HSMs::QHsmTst::SM::s}
        case Q_EXIT_SIG: {
            BSP_display("s-EXIT;");
            status_ = Q_RET_HANDLED;
            break;
        }
        //${HSMs::QHsmTst::SM::s::initial}
        case Q_INIT_SIG: {
            BSP_display("s-INIT;");
            status_ = tran(&s11);
            break;
        }
        //${HSMs::QHsmTst::SM::s::I}
        case I_SIG: {
            //${HSMs::QHsmTst::SM::s::I::[m_foo]}
            if (m_foo) {
                m_foo = 0U;
                BSP_display("s-I;");
                status_ = Q_RET_HANDLED;
            }
            else {
                status_ = Q_RET_UNHANDLED;
            }
            break;
        }
        //${HSMs::QHsmTst::SM::s::E}
        case E_SIG: {
            BSP_display("s-E;");
            status_ = tran(&s11);
            break;
        }
        //${HSMs::QHsmTst::SM::s::TERMINATE}
        case TERMINATE_SIG: {
            BSP_terminate(0);
            status_ = Q_RET_HANDLED;
            break;
        }
        default: {
            status_ = super(&top);
            break;
        }
    }
    return status_;
}
Example #3
0
//${AOs::Table::SM::active} ..................................................
Q_STATE_DEF(Table, active) {
    QP::QState status_;
    switch (e->sig) {
        //${AOs::Table::SM::active::TERMINATE}
        case TERMINATE_SIG: {
            BSP_terminate(0);
            status_ = Q_RET_HANDLED;
            break;
        }
        //${AOs::Table::SM::active::EAT}
        case EAT_SIG: {
            Q_ERROR();
            status_ = Q_RET_HANDLED;
            break;
        }
        default: {
            status_ = super(&top);
            break;
        }
    }
    return status_;
}
Example #4
0
// ${AOs::Table::SM::active}
QP::QState Table::active(Table * const me, QP::QEvt const * const e) {
    QP::QState status_;
    switch (e->sig) {
        // ${AOs::Table::SM::active::TERMINATE}
        case TERMINATE_SIG: {
            BSP_terminate(0);
            status_ = QM_HANDLED();
            break;
        }
        // ${AOs::Table::SM::active::EAT}
        case EAT_SIG: {
            Q_ERROR();
            status_ = QM_HANDLED();
            break;
        }
        default: {
            status_ = QM_SUPER();
            break;
        }
    }
    (void)me; // avoid compiler warning in case 'me' is not used
    return status_;
}
Example #5
0
/*..........................................................................*/
static LRESULT CALLBACK WndProc(HWND hWnd, UINT iMsg,
                                WPARAM wParam, LPARAM lParam)
{
    switch (iMsg) {

        /* Perform initialization upon cration of the main dialog window
        * NOTE: Any child-windows are NOT created yet at this time, so
        * the GetDlgItem() function can't be used (it will return NULL).
        */
        case WM_CREATE: {
            l_hWnd = hWnd; /* save the window handle */

            /* initialize the owner-drawn buttons...
            * NOTE: must be done *before* the first drawing of the buttons,
            * so WM_INITDIALOG is too late.
            */
            OwnerDrawnButton_init(&l_userBtn,
                       LoadBitmap(l_hInst, MAKEINTRESOURCE(IDB_BTN_UP)),
                       LoadBitmap(l_hInst, MAKEINTRESOURCE(IDB_BTN_DWN)),
                       LoadCursor(NULL, IDC_HAND));
            return 0;
        }

        /* Perform initialization after all child windows have been created */
        case WM_INITDIALOG: {
            GraphicDisplay_init(&l_oled,
                       BSP_SCREEN_WIDTH,  2U, /* scale horizontally by 2 */
                       BSP_SCREEN_HEIGHT, 2U, /* scale vertically by 2 */
                       GetDlgItem(hWnd, IDC_LCD), c_offColor);

            SegmentDisplay_init(&l_userLED,
                                1U,  /* 1 "segment" (the LED itself) */
                                2U); /* 2 bitmaps (for LED OFF/ON states) */
            SegmentDisplay_initSegment(&l_userLED,
                 0U, GetDlgItem(hWnd, IDC_LED));
            SegmentDisplay_initBitmap(&l_userLED,
                 0U, LoadBitmap(l_hInst, MAKEINTRESOURCE(IDB_LED_OFF)));
            SegmentDisplay_initBitmap(&l_userLED,
                 1U, LoadBitmap(l_hInst, MAKEINTRESOURCE(IDB_LED_ON)));

            SegmentDisplay_init(&l_scoreBoard,
                                4U,   /* 4 "segments" (digits 0-3) */
                                10U); /* 10 bitmaps (for 0-9 states) */
            SegmentDisplay_initSegment(&l_scoreBoard,
                 0U, GetDlgItem(hWnd, IDC_SEG0));
            SegmentDisplay_initSegment(&l_scoreBoard,
                 1U, GetDlgItem(hWnd, IDC_SEG1));
            SegmentDisplay_initSegment(&l_scoreBoard,
                 2U, GetDlgItem(hWnd, IDC_SEG2));
            SegmentDisplay_initSegment(&l_scoreBoard,
                 3U, GetDlgItem(hWnd, IDC_SEG3));
            SegmentDisplay_initBitmap(&l_scoreBoard,
                 0U, LoadBitmap(l_hInst, MAKEINTRESOURCE(IDB_SEG0)));
            SegmentDisplay_initBitmap(&l_scoreBoard,
                 1U, LoadBitmap(l_hInst, MAKEINTRESOURCE(IDB_SEG1)));
            SegmentDisplay_initBitmap(&l_scoreBoard,
                 2U, LoadBitmap(l_hInst, MAKEINTRESOURCE(IDB_SEG2)));
            SegmentDisplay_initBitmap(&l_scoreBoard,
                 3U, LoadBitmap(l_hInst, MAKEINTRESOURCE(IDB_SEG3)));
            SegmentDisplay_initBitmap(&l_scoreBoard,
                 4U, LoadBitmap(l_hInst, MAKEINTRESOURCE(IDB_SEG4)));
            SegmentDisplay_initBitmap(&l_scoreBoard,
                 5U, LoadBitmap(l_hInst, MAKEINTRESOURCE(IDB_SEG5)));
            SegmentDisplay_initBitmap(&l_scoreBoard,
                 6U, LoadBitmap(l_hInst, MAKEINTRESOURCE(IDB_SEG6)));
            SegmentDisplay_initBitmap(&l_scoreBoard,
                 7U, LoadBitmap(l_hInst, MAKEINTRESOURCE(IDB_SEG7)));
            SegmentDisplay_initBitmap(&l_scoreBoard,
                 8U, LoadBitmap(l_hInst, MAKEINTRESOURCE(IDB_SEG8)));
            SegmentDisplay_initBitmap(&l_scoreBoard,
                 9U, LoadBitmap(l_hInst, MAKEINTRESOURCE(IDB_SEG9)));

            BSP_updateScore(0U);

            /* --> QP: spawn the application thread to run main_gui() */
            Q_ALLEGE(CreateThread(NULL, 0, &appThread, NULL, 0, NULL)
                     != (HANDLE)0);
            return 0;
        }

        case WM_DESTROY: {
            BSP_terminate(0);
            return 0;
        }

        /* commands from regular buttons and menus... */
        case WM_COMMAND: {
            SetFocus(hWnd);
            switch (wParam) {
                case IDOK:
                case IDCANCEL: {
                    BSP_terminate(0);
                    break;
                }
            }
            return 0;
        }

        /* owner-drawn buttons... */
        case WM_DRAWITEM: {
            LPDRAWITEMSTRUCT pdis = (LPDRAWITEMSTRUCT)lParam;
            switch (pdis->CtlID) {
                case IDC_USER: {  /* USER owner-drawn button */
                    switch (OwnerDrawnButton_draw(&l_userBtn, pdis)) {
                        case BTN_DEPRESSED: {
                            playerTrigger();
                            SegmentDisplay_setSegment(&l_userLED, 0U, 1U);
                            break;
                        }
                        case BTN_RELEASED: {
                            SegmentDisplay_setSegment(&l_userLED, 0U, 0U);
                            break;
                        }
                        default: {
                            break;
                        }
                    }
                    break;
                }
            }
            return 0;
        }

        /* mouse input... */
        case WM_MOUSEWHEEL: {
            if ((HIWORD(wParam) & 0x8000U) == 0U) {/* wheel turned forward? */
                moveShipUp();
            }
            else { /* the wheel was turned backwards */
                moveShipDown();
            }
            return 0;
        }

        /* keyboard input... */
        case WM_KEYDOWN: {
            switch (wParam) {
                case VK_UP:
                    moveShipUp();
                    break;
                case VK_DOWN:
                    moveShipDown();
                    break;
                case VK_SPACE:
                    playerTrigger();
                    break;
            }
            return 0;
        }

    }
    return DefWindowProc(hWnd, iMsg, wParam, lParam) ;
}
Example #6
0
//............................................................................
static LRESULT CALLBACK WndProc(HWND hWnd, UINT iMsg,
                                    WPARAM wParam, LPARAM lParam)
{
    switch (iMsg) {

        // Perform initialization upon cration of the main dialog window
        // NOTE: Any child-windows are NOT created yet at this time, so
        // the GetDlgItem() function can't be used (it will return NULL).
        //
        case WM_CREATE: {
            l_hWnd = hWnd;                           // save the window handle

            // initialize the owner-drawn buttons
            // NOTE: must be done *before* the first drawing of the buttons,
            // so WM_INITDIALOG is too late.
            //
            l_pauseBtn.init(LoadBitmap(l_hInst, MAKEINTRESOURCE(IDB_BTN_UP)),
                            LoadBitmap(l_hInst, MAKEINTRESOURCE(IDB_BTN_DWN)),
                            LoadCursor(NULL, IDC_HAND));
            return 0;
        }

        // Perform initialization after all child windows have been created
        case WM_INITDIALOG: {

            l_philos.init(N_PHILO,        // N_PHILO "segments" for the Philos
                          3U);       // 3 bitmaps (for thinking/hungry/eating)
            l_philos.initSegment(0U, GetDlgItem(hWnd, IDC_PHILO_0));
            l_philos.initSegment(1U, GetDlgItem(hWnd, IDC_PHILO_1));
            l_philos.initSegment(2U, GetDlgItem(hWnd, IDC_PHILO_2));
            l_philos.initSegment(3U, GetDlgItem(hWnd, IDC_PHILO_3));
            l_philos.initSegment(4U, GetDlgItem(hWnd, IDC_PHILO_4));
            l_philos.initBitmap(0U,
                LoadBitmap(l_hInst, MAKEINTRESOURCE(IDB_THINKING)));
            l_philos.initBitmap(1U,
                LoadBitmap(l_hInst, MAKEINTRESOURCE(IDB_HUNGRY)));
            l_philos.initBitmap(2U,
                LoadBitmap(l_hInst, MAKEINTRESOURCE(IDB_EATING)));

            // --> QP: spawn the application thread to run main()
            Q_ALLEGE(CreateThread(NULL, 0, &appThread, NULL, 0, NULL)
                     != (HANDLE)0);
            return 0;
        }

        case WM_DESTROY: {
            BSP_terminate(0);
            return 0;
        }

        // commands from regular buttons and menus...
        case WM_COMMAND: {
            SetFocus(hWnd);
            switch (wParam) {
                case IDOK:
                case IDCANCEL: {
                    //QP::QF::PUBLISH(Q_NEW(QP::QEvt, TERMINATE_SIG), (void *)0);
                    BSP_terminate(0);
                    break;
                }
            }
            return 0;
        }

        // owner-drawn buttons...
        case WM_DRAWITEM: {
            LPDRAWITEMSTRUCT pdis = (LPDRAWITEMSTRUCT)lParam;
            switch (pdis->CtlID) {
                case IDC_PAUSE: {                  // PAUSE owner-drawn button
                    static QP::QEvt pe = QEVT_INITIALIZER(PAUSE_SIG);
                    switch (l_pauseBtn.draw(pdis)) {
                        case OwnerDrawnButton::BTN_DEPRESSED: {
                            AO_Table->POST(&pe, (void *)0);
                            break;
                        }
                        case OwnerDrawnButton::BTN_RELEASED: {
                            AO_Table->POST(&pe, (void *)0);
                            break;
                        }
                    }
                    break;
                }
            }
            return 0;
        }

        // mouse input...
        case WM_MOUSEWHEEL: {
            return 0;
        }

        // keyboard input...
        case WM_KEYDOWN: {
            return 0;
        }

    }
    return DefWindowProc(hWnd, iMsg, wParam, lParam) ;
}
Example #7
0
//............................................................................
static LRESULT CALLBACK WndProc(HWND hWnd, UINT iMsg,
                                WPARAM wParam, LPARAM lParam)
{
    switch (iMsg) {

        // Perform initialization upon cration of the main dialog window
        // NOTE: Any child-windows are NOT created yet at this time, so
        // the GetDlgItem() function can't be used (it will return NULL).
        //
        case WM_CREATE: {
            l_hWnd = hWnd;                           // save the window handle

            // initialize the owner-drawn buttons...
            // NOTE: must be done *before* the first drawing of the buttons,
            // so WM_INITDIALOG is too late.
            //
            l_userBtn.init(LoadBitmap(l_hInst, MAKEINTRESOURCE(IDB_BTN_UP)),
                           LoadBitmap(l_hInst, MAKEINTRESOURCE(IDB_BTN_DWN)),
                           LoadCursor(NULL, IDC_HAND));
            return 0;
        }

        // Perform initialization after all child windows have been created
        case WM_INITDIALOG: {
            l_oled.init(BSP_SCREEN_WIDTH,  2U,       // scale horizontally by 2
                        BSP_SCREEN_HEIGHT, 2U,         // scale vertically by 2
                        GetDlgItem(hWnd, IDC_LCD), c_offColor);

            l_userLED.init(1U,                  // 1 "segment" (the LED itself)
                           2U);            // 2 bitmaps (for LED OFF/ON states)
            l_userLED.initSegment(0U, GetDlgItem(hWnd, IDC_LED));
            l_userLED.initBitmap(0U,
                LoadBitmap(l_hInst, MAKEINTRESOURCE(IDB_LED_OFF)));
            l_userLED.initBitmap(1U,
                LoadBitmap(l_hInst, MAKEINTRESOURCE(IDB_LED_ON)));

            l_scoreBoard.init(4U,                  // 4 "segments" (digits 0-3)
                              10U);           // 10 bitmaps (for 0-9 states)
            l_scoreBoard.initSegment(0U, GetDlgItem(hWnd, IDC_SEG0));
            l_scoreBoard.initSegment(1U, GetDlgItem(hWnd, IDC_SEG1));
            l_scoreBoard.initSegment(2U, GetDlgItem(hWnd, IDC_SEG2));
            l_scoreBoard.initSegment(3U, GetDlgItem(hWnd, IDC_SEG3));
            l_scoreBoard.initBitmap(0U,
                LoadBitmap(l_hInst, MAKEINTRESOURCE(IDB_SEG0)));
            l_scoreBoard.initBitmap(1U,
                LoadBitmap(l_hInst, MAKEINTRESOURCE(IDB_SEG1)));
            l_scoreBoard.initBitmap(2U,
                LoadBitmap(l_hInst, MAKEINTRESOURCE(IDB_SEG2)));
            l_scoreBoard.initBitmap(3U,
                LoadBitmap(l_hInst, MAKEINTRESOURCE(IDB_SEG3)));
            l_scoreBoard.initBitmap(4U,
                LoadBitmap(l_hInst, MAKEINTRESOURCE(IDB_SEG4)));
            l_scoreBoard.initBitmap(5U,
                LoadBitmap(l_hInst, MAKEINTRESOURCE(IDB_SEG5)));
            l_scoreBoard.initBitmap(6U,
                LoadBitmap(l_hInst, MAKEINTRESOURCE(IDB_SEG6)));
            l_scoreBoard.initBitmap(7U,
                LoadBitmap(l_hInst, MAKEINTRESOURCE(IDB_SEG7)));
            l_scoreBoard.initBitmap(8U,
                LoadBitmap(l_hInst, MAKEINTRESOURCE(IDB_SEG8)));
            l_scoreBoard.initBitmap(9U,
                LoadBitmap(l_hInst, MAKEINTRESOURCE(IDB_SEG9)));

            BSP_updateScore(0U);

            // --> QP: spawn the application thread to run main()
            Q_ALLEGE(CreateThread(NULL, 0, &appThread, NULL, 0, NULL)
                     != (HANDLE)0);
            return 0;
        }

        case WM_DESTROY: {
            BSP_terminate(0);
            return 0;
        }

        // commands from regular buttons and menus...
        case WM_COMMAND: {
            SetFocus(hWnd);
            switch (wParam) {
                case IDOK:
                case IDCANCEL: {
                    BSP_terminate(0);
                    break;
                }
            }
            return 0;
        }

        // owner-drawn buttons...
        case WM_DRAWITEM: {
            LPDRAWITEMSTRUCT pdis = (LPDRAWITEMSTRUCT)lParam;
            switch (pdis->CtlID) {
                case IDC_USER: {                    // USER owner-drawn button
                    switch (l_userBtn.draw(pdis)) {
                        case OwnerDrawnButton::BTN_DEPRESSED: {
                            BSP_playerTrigger();
                            l_userLED.setSegment(0U, 1U);
                            break;
                        }
                        case OwnerDrawnButton::BTN_RELEASED: {
                            l_userLED.setSegment(0U, 0U);
                            break;
                        }
                    }
                    break;
                }
            }
            return 0;
        }

        // mouse input...
        case WM_MOUSEWHEEL: {
            if ((HIWORD(wParam) & 0x8000U) == 0U) {   // wheel turned forward?
                BSP_moveShipUp();
            }
            else {                           // the wheel was turned backwards
                BSP_moveShipDown();
            }
            return 0;
        }

        // keyboard input...
        case WM_KEYDOWN: {
            switch (wParam) {
                case VK_UP:
                    BSP_moveShipUp();
                    break;
                case VK_DOWN:
                    BSP_moveShipDown();
                    break;
                case VK_SPACE:
                    BSP_playerTrigger();
                    break;
            }
            return 0;
        }

    }
    return DefWindowProc(hWnd, iMsg, wParam, lParam) ;
}
Example #8
0
/*--------------------------------------------------------------------------*/
void Q_onAssert(char const Q_ROM * const file, int line) {
    QF_INT_DISABLE();                             /* cut-off all interrupts */
    fprintf(stderr, "Assertion failed in %s, line %d", file, line);
    BSP_terminate(-1);
}
Example #9
0
/*..........................................................................*/
static LRESULT CALLBACK WndProc(HWND hWnd, UINT iMsg,
                                WPARAM wParam, LPARAM lParam)
{
    switch (iMsg) {

        /* Perform initialization upon cration of the main dialog window
        * NOTE: Any child-windows are NOT created yet at this time, so
        * the GetDlgItem() function can't be used (it will return NULL).
        */
        case WM_CREATE: {
            l_hWnd = hWnd; /* save the window handle */

            /* initialize the owner-drawn buttons
            * NOTE: must be done *before* the first drawing of the buttons,
            * so WM_INITDIALOG is too late.
            */
            OwnerDrawnButton_init(&l_pauseBtn,
                       LoadBitmap(l_hInst, MAKEINTRESOURCE(IDB_BTN_UP)),
                       LoadBitmap(l_hInst, MAKEINTRESOURCE(IDB_BTN_DWN)),
                       LoadCursor(NULL, IDC_HAND));
            return 0;
        }

        /* Perform initialization after all child windows have been created */
        case WM_INITDIALOG: {

            SegmentDisplay_init(&l_philos,
                     N_PHILO,          /* N_PHILO "segments" for the Philos */
                     3U);         /* 3 bitmaps (for thinking/hungry/eating) */
            SegmentDisplay_initSegment(&l_philos,
                 0U, GetDlgItem(hWnd, IDC_PHILO_0));
            SegmentDisplay_initSegment(&l_philos,
                 1U, GetDlgItem(hWnd, IDC_PHILO_1));
            SegmentDisplay_initSegment(&l_philos,
                 2U, GetDlgItem(hWnd, IDC_PHILO_2));
            SegmentDisplay_initSegment(&l_philos,
                 3U, GetDlgItem(hWnd, IDC_PHILO_3));
            SegmentDisplay_initSegment(&l_philos,
                 4U, GetDlgItem(hWnd, IDC_PHILO_4));
            SegmentDisplay_initBitmap(&l_philos,
                 0U, LoadBitmap(l_hInst, MAKEINTRESOURCE(IDB_THINKING)));
            SegmentDisplay_initBitmap(&l_philos,
                 1U, LoadBitmap(l_hInst, MAKEINTRESOURCE(IDB_HUNGRY)));
            SegmentDisplay_initBitmap(&l_philos,
                 2U, LoadBitmap(l_hInst, MAKEINTRESOURCE(IDB_EATING)));

            /* --> QP: spawn the application thread to run main() */
            Q_ALLEGE(CreateThread(NULL, 0, &appThread, NULL, 0, NULL)
                     != (HANDLE)0);
            return 0;
        }

        case WM_DESTROY: {
            BSP_terminate(0);
            return 0;
        }

        /* commands from regular buttons and menus... */
        case WM_COMMAND: {
            SetFocus(hWnd);
            switch (wParam) {
                case IDOK:
                case IDCANCEL: {
                    //QF_PUBLISH(Q_NEW(QEvt, TERMINATE_SIG), (void *)0);
                    BSP_terminate(0);
                    break;
                }
            }
            return 0;
        }

        /* owner-drawn buttons... */
        case WM_DRAWITEM: {
            LPDRAWITEMSTRUCT pdis = (LPDRAWITEMSTRUCT)lParam;
            switch (pdis->CtlID) {
                case IDC_PAUSE: { /* PAUSE owner-drawn button */
                    switch (OwnerDrawnButton_draw(&l_pauseBtn,pdis)) {
                        case BTN_DEPRESSED: {
                            static QEvt const pe = { PAUSE_SIG, 0U, 0U };
                            QACTIVE_POST(AO_Table, &pe, (void *)0);
                            break;
                        }
                        case BTN_RELEASED: {
                            static QEvt const se = { SERVE_SIG, 0U, 0U };
                            QACTIVE_POST(AO_Table, &se, (void *)0);
                            break;
                        }
                        default: {
                            break;
                        }
                    }
                    break;
                }
            }
            return 0;
        }

        /* mouse input... */
        case WM_MOUSEWHEEL: {
            return 0;
        }

        /* keyboard input... */
        case WM_KEYDOWN: {
            return 0;
        }
    }
    return DefWindowProc(hWnd, iMsg, wParam, lParam) ;
}