Example #1
0
void BSP_init(void) {
	uint32_t err_code;
    err_code = nrf_drv_timer_init(&TIMER1, NULL, Timer1_handler);
    APP_ERROR_CHECK(err_code);
    nrf_drv_timer_extended_compare(&TIMER1, NRF_TIMER_CC_CHANNEL0
    		, nrf_drv_timer_ms_to_ticks(&TIMER1, 1000/BSP_TICKS_PER_SEC)
			, NRF_TIMER_SHORT_COMPARE0_CLEAR_MASK, true);

    // Configure button 1 for low accuracy (why not high accuracy?)
    Q_ALLEGE(nrf_drv_gpiote_init() == NRF_SUCCESS);

    nrf_drv_gpiote_in_config_t config = GPIOTE_CONFIG_IN_SENSE_TOGGLE(true);
    config.pull = NRF_GPIO_PIN_PULLUP;

    Q_ALLEGE(nrf_drv_gpiote_in_init(BTN_PIN, &config, btn1_event_handler)
    		== NRF_SUCCESS);
    nrf_drv_gpiote_in_event_enable(BTN_PIN, /* int enable = */ true);

    NRF_GPIO->DIRSET = 1 << GPIO_TP;

    /* initialize the QS software tracing... */
    if (QS_INIT((void *)0) == 0) {
        Q_ERROR();
    }
}
Example #2
0
void QActive_postFIFO(QActive *me, QEvent const *e) {
#else
void QActive_postFIFO(QActive *me, QEvent const *e, void const *sender) {
#endif

    QF_INT_LOCK_KEY_
    QF_INT_LOCK_();

    QS_BEGIN_NOLOCK_(QS_QF_ACTIVE_POST_FIFO, QS_aoObj_, me)
        QS_TIME_();                                            /* timestamp */
        QS_OBJ_(sender);                               /* the sender object */
        QS_SIG_(e->sig);                         /* the signal of the event */
        QS_OBJ_(me);                      /* this active object (recipient) */
        QS_U8_(EVT_POOL_ID(e));                 /* the pool Id of the event */
        QS_U8_(EVT_REF_CTR(e));               /* the ref count of the event */
        QS_EQC_(0);                     /* number of free entries (unknown) */
        QS_EQC_(0);                 /* min number of free entries (unknown) */
    QS_END_NOLOCK_()

    if (EVT_POOL_ID(e) != (uint8_t)0) {              /* is it a pool event? */
        EVT_INC_REF_CTR(e);              /* increment the reference counter */
    }
    QF_INT_UNLOCK_();
    Q_ALLEGE(OSQPost((OS_EVENT *)me->eQueue, (void *)e) == OS_NO_ERR);
}
Example #3
0
/*..........................................................................*/
void QFsm_init_(QFsm * const me, QEvt const * const e) {
    QS_CRIT_STAT_

    Q_REQUIRE((me->vptr != (QMsmVtbl const *)0)    /* ctor must be executed */
              && (me->temp.fun != Q_STATE_CAST(0)) /* ctor must be executed */
              && (me->state.fun == Q_STATE_CAST(0)));/*init tran. NOT taken */

    QS_BEGIN_(QS_QEP_STATE_INIT, QS_priv_.smObjFilter, me)
        QS_OBJ_(me);                           /* this state machine object */
        QS_FUN_(Q_STATE_CAST(0));   /* source state (not defined for a FSM) */
        QS_FUN_(me->temp.fun);              /* the target of the transition */
    QS_END_()

                                 /* execute the top-most initial transition */
    Q_ALLEGE((*me->temp.fun)(me, e) == (QState)Q_RET_TRAN);/* must be taken */

    (void)QEP_TRIG_(me->temp.fun, Q_ENTRY_SIG);         /* enter the target */
    me->state.fun = me->temp.fun;            /* record the new active state */

    QS_BEGIN_(QS_QEP_INIT_TRAN, QS_priv_.smObjFilter, me)
        QS_TIME_();                                           /* time stamp */
        QS_OBJ_(me);                           /* this state machine object */
        QS_FUN_(me->state.fun);                     /* the new active state */
    QS_END_()
}
Example #4
0
//............................................................................
void BSP_init(void) {
    // set the system clock as specified in lm3s_config.h (20MHz from PLL)
    SystemInit();

    // enable clock to the peripherals used by the application
    SYSCTL->RCGC2 |= 1U | (1U << 2);              // enable clock to GPIOA & C
    __NOP();                                     // wait after enabling clocks
    __NOP();
    __NOP();

    // configure the LED and push button
    GPIOC->DIR |= USER_LED;                           // set direction: output
    GPIOC->DEN |= USER_LED;                                  // digital enable
    GPIOC->DATA_Bits[USER_LED] = 0U;                  // turn the User LED off

    GPIOC->DIR &= ~PUSH_BUTTON;                       //  set direction: input
    GPIOC->DEN |= PUSH_BUTTON;                               // digital enable

    Display96x16x1Init(1U);                     // initialize the OLED display
    Display96x16x1StringDraw(&"Dining Philos"[0], 0U, 0U);
    Display96x16x1StringDraw(&"0 ,1 ,2 ,3 ,4"[0], 0U, 1U);

    Q_ALLEGE(QS_INIT(static_cast<void *>(0)));
    QS_OBJ_DICTIONARY(&l_SysTick_Handler);
    QS_OBJ_DICTIONARY(&l_GPIOPortA_IRQHandler);
    QS_USR_DICTIONARY(PHILO_STAT);
}
Example #5
0
//............................................................................
void BSP_init(void) {

    Q_ALLEGE(QS_INIT((void *)0));
    QS_RESET();
    QS_OBJ_DICTIONARY(&l_clock_tick);      // must be called *after* QF_init()
    QS_USR_DICTIONARY(PHILO_STAT);
}
Example #6
0
static QState Ble_ancs_enabled(Ble* const me) {
	uint32_t err_code;
	switch(Q_SIG(me)) {
	case Q_ENTRY_SIG:
	    err_code = ble_ancs_c_notif_source_notif_enable(&m_ancs_c);
	    Q_ALLEGE(err_code == NRF_SUCCESS);
#if 0
	    err_code = ble_ancs_c_data_source_notif_enable(&m_ancs_c);
	    Q_ALLEGE(err_code == NRF_SUCCESS);
#endif
	    return Q_HANDLED();

	default:
		return Q_SUPER(&QHsm_top);
	}
}
Example #7
0
/*..........................................................................*/
void QHsm_init(QHsm *me) {
    QStateHandler t;

    Q_ALLEGE((*me->state)(me) == Q_RET_TRAN);/* initial tran. must be taken */

    t = (QStateHandler)&QHsm_top;         /* an HSM starts in the top state */
    do {                              /* drill into the target hierarchy... */
        QStateHandler path[QEP_MAX_NEST_DEPTH_];
        int8_t ip = (int8_t)0;

        path[0] = me->state;
        Q_SIG(me) = (QSignal)QEP_EMPTY_SIG_;
        (void)(*me->state)(me);
        while (me->state != t) {
            ++ip;
            path[ip] = me->state;
            (void)(*me->state)(me);
        }
        me->state = path[0];
                                            /* entry path must not overflow */
        Q_ASSERT(ip < (int8_t)QEP_MAX_NEST_DEPTH_);

        Q_SIG(me) = (QSignal)Q_ENTRY_SIG;
        do {        /* retrace the entry path in reverse (correct) order... */
            (void)(*path[ip])(me);                        /* enter path[ip] */
            --ip;
        } while (ip >= (int8_t)0);

        t = path[0];
        Q_SIG(me) = (QSignal)Q_INIT_SIG;
    } while ((*t)(me) == Q_RET_TRAN);        /* initial transition handled? */
    me->state = t;
}
Example #8
0
bool QActive_post_(QActive * const me, QEvt const * const e,
                   uint_fast16_t const margin, void const * const sender)
#endif /* Q_SPY */
{
    uint_fast16_t nFree;
    bool status;
    QF_CRIT_STAT_

    QF_CRIT_ENTRY_();
    nFree = (uint_fast16_t)(me->eQueue.maxMsg - me->eQueue.nofMsg);

    if (nFree > margin) {
        QS_BEGIN_NOCRIT_(QS_QF_ACTIVE_POST_FIFO, QS_priv_.aoObjFilter, me)
            QS_TIME_();             /* timestamp */
            QS_OBJ_(sender);        /* the sender object */
            QS_SIG_(e->sig);        /* the signal of the event */
            QS_OBJ_(me);            /* this active object (recipient) */
            QS_2U8_(e->poolId_, e->refCtr_); /* pool Id & ref Count */
            QS_EQC_((QEQueueCtr)nFree); /* # free entries available */
            QS_EQC_((QEQueueCtr)0); /* min # free entries (unknown) */
        QS_END_NOCRIT_()

        if (e->poolId_ != (uint8_t)0) { /* is it a pool event? */
            QF_EVT_REF_CTR_INC_(e); /* increment the reference counter */
        }
        /* posting to the embOS mailbox must succeed, see NOTE3 */
        Q_ALLEGE(OS_PutMailCond(&me->eQueue, (OS_CONST_PTR void *)&e)
                 == (char)0);

        status = true; /* return success */
    }
Example #9
0
File: bsp.cpp Project: dgu123/qpcpp
//............................................................................
void BSP_init(void) {
    Q_ALLEGE(QS_INIT((char *)0));
    QS_RESET();
    QS_OBJ_DICTIONARY(&l_time_tick);
    QS_USR_DICTIONARY(PHILO_STAT);

    BSP_randomSeed(1234U);
}
Example #10
0
/*..........................................................................*/
QEvent const *QActive_get_(QActive *me) {
  
	 QEvent const *e;

	 Q_ALLEGE(xQueueReceive(me->eQueue, &e, portMAX_DELAY) == pdPASS);

    return e;
}
Example #11
0
//............................................................................
void QActive::postLIFO(QEvent const *e) {
    QF_INT_LOCK_KEY_
    QF_INT_LOCK_();
    if (e->dynamic_ != (uint8_t)0) {
        ++((QEvent *)e)->dynamic_;
    }
    QF_INT_UNLOCK_();
    Q_ALLEGE(OSQPostFront((OS_EVENT *)m_eQueue, (void *)e) == OS_NO_ERR);
}
Example #12
0
/*..........................................................................*/
void QActive_start_(QActive * const me, uint_fast8_t prio,
                    QEvt const *qSto[], uint_fast16_t qLen,
                    void *stkSto, uint_fast16_t stkSize,
                    QEvt const *ie)
{
    pthread_t thread;
    pthread_attr_t attr;
    struct sched_param param;

    /* p-threads allocate stack internally */
    Q_REQUIRE_ID(600, stkSto == (void *)0);

    QEQueue_init(&me->eQueue, qSto, qLen);
    pthread_cond_init(&me->osObject, 0);

    me->prio = (uint8_t)prio;
    QF_add_(me); /* make QF aware of this active object */

    QMSM_INIT(&me->super, ie); /* take the top-most initial tran. */
    QS_FLUSH(); /* flush the QS trace buffer to the host */

    pthread_attr_init(&attr);

    /* SCHED_FIFO corresponds to real-time preemptive priority-based scheduler
    * NOTE: This scheduling policy requires the superuser privileges
    */
    pthread_attr_setschedpolicy(&attr, SCHED_FIFO);

    /* see NOTE04 */
    param.sched_priority = prio
                           + (sched_get_priority_max(SCHED_FIFO)
                              - QF_MAX_ACTIVE - 3);

    pthread_attr_setschedparam(&attr, &param);
    pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);

    if (stkSize == 0U) {
        /* set the allowed minimum */
        stkSize = (uint_fast16_t)PTHREAD_STACK_MIN;
    }
    pthread_attr_setstacksize(&attr, (size_t)stkSize);

    if (pthread_create(&thread, &attr, &thread_routine, me) != 0) {
        /* Creating the p-thread with the SCHED_FIFO policy failed. Most
        * probably this application has no superuser privileges, so we just
        * fall back to the default SCHED_OTHER policy and priority 0.
        */
        pthread_attr_setschedpolicy(&attr, SCHED_OTHER);
        param.sched_priority = 0;
        pthread_attr_setschedparam(&attr, &param);
        Q_ALLEGE(pthread_create(&thread, &attr, &thread_routine, me)== 0);
    }
    pthread_attr_destroy(&attr);
    me->thread = (uint8_t)1;
}
Example #13
0
//............................................................................
void BSP_init(void) {
    Q_ALLEGE(QS_INIT((char *)0));
    QS_RESET();
    QS_OBJ_DICTIONARY(&l_time_tick);
    QS_USR_DICTIONARY(PHILO_STAT);

    l_stdOutStream << "DPP-Qt console example" << endl
                   << "QP " << QP::QF::getVersion() << endl;

    BSP_randomSeed(1234U);
}
Example #14
0
/**@brief Function for putting the chip into sleep mode.
 *
 * @note This function will not return.
 */
void BSP_stop() {
    uint32_t new_cnf = NRF_GPIO->PIN_CNF[BTN_PIN];
    uint32_t new_sense = GPIO_PIN_CNF_SENSE_Low;
    new_cnf &= ~GPIO_PIN_CNF_SENSE_Msk;
    new_cnf |= (new_sense << GPIO_PIN_CNF_SENSE_Pos);
    NRF_GPIO->PIN_CNF[BTN_PIN] = new_cnf;

    // Go to system-off mode (this function will not return;
    // wakeup will cause a reset).
    Q_ALLEGE(sd_power_system_off() == NRF_SUCCESS);
}
Example #15
0
/*..........................................................................*/
void BSP_init(void) {

    printf("Dining Philosopher Problem example"
           "\nQEP %s\nQF  %s\n"
           "Press 'p' to pause/un-pause\n"
           "Press ESC to quit...\n",
           QEP_getVersion(),
           QF_getVersion());

    BSP_randomSeed(1234U);
    Q_ALLEGE(QS_INIT((void *)0));
    QS_OBJ_DICTIONARY(&l_clock_tick);   /* must be called *after* QF_init() */
    QS_USR_DICTIONARY(PHILO_STAT);
}
Example #16
0
/*..........................................................................*/
void QHsm_init(QHsm * const me, QEvt const * const e) {
    QStateHandler t = me->state.fun;
    QS_CRIT_STAT_

    Q_REQUIRE((me->vptr != (QMsmVtbl const *)0)    /* ctor must be executed */
              && (me->temp.fun != Q_STATE_CAST(0)) /* ctor must be executed */
              && (t == Q_STATE_CAST(&QHsm_top))); /*initial tran. NOT taken */

                           /* the top-most initial transition must be taken */
    Q_ALLEGE((*me->temp.fun)(me, e) == (QState)Q_RET_TRAN);

    do {                                        /* drill into the target... */
        QStateHandler path[QEP_MAX_NEST_DEPTH_];
        int_t ip = (int_t)0;                 /* transition entry path index */

        QS_BEGIN_(QS_QEP_STATE_INIT, QS_priv_.smObjFilter, me)
            QS_OBJ_(me);                       /* this state machine object */
            QS_FUN_(t);                                 /* the source state */
            QS_FUN_(me->temp.fun);  /* the target of the initial transition */
        QS_END_()

        path[0] = me->temp.fun;
        (void)QEP_TRIG_(me->temp.fun, QEP_EMPTY_SIG_);
        while (me->temp.fun != t) {
            ++ip;
            path[ip] = me->temp.fun;
            (void)QEP_TRIG_(me->temp.fun, QEP_EMPTY_SIG_);
        }
        me->temp.fun = path[0];
                                            /* entry path must not overflow */
        Q_ASSERT(ip < (int_t)QEP_MAX_NEST_DEPTH_);

        do {        /* retrace the entry path in reverse (desired) order... */
            QEP_ENTER_(path[ip]);                         /* enter path[ip] */
            --ip;
        } while (ip >= (int_t)0);

        t = path[0];                /* current state becomes the new source */
    } while (QEP_TRIG_(t, Q_INIT_SIG) == (QState)Q_RET_TRAN);

    QS_BEGIN_(QS_QEP_INIT_TRAN, QS_priv_.smObjFilter, me)
        QS_TIME_();                                           /* time stamp */
        QS_OBJ_(me);                           /* this state machine object */
        QS_FUN_(t);                                 /* the new active state */
    QS_END_()

    me->state.fun = t;                   /* change the current active state */
    me->temp.fun  = t;                  /* mark the configuration as stable */
}
Example #17
0
File: bsp.c Project: KnightSch/qpc
/*..........................................................................*/
void BSP_init(int argc, char *argv[]) {

    printf("Dining Philosophers Problem example"
           "\nQP %s\n"
           "Press 'p' to pause\n"
           "Press 's' to serve\n"
           "Press ESC to quit...\n",
           QP_versionStr);

    BSP_randomSeed(1234U);

    Q_ALLEGE(QS_INIT((void *)0));
    QS_OBJ_DICTIONARY(&l_clock_tick); /* must be called *after* QF_init() */
    QS_USR_DICTIONARY(PHILO_STAT);
}
Example #18
0
/*..........................................................................*/
void QActive_start(QActive *me, uint8_t prio,
                  QEvent const *qSto[], uint32_t qLen,
                  void *stkSto, uint32_t stkSize,
                  QEvent const *ie)
{
    pthread_attr_t attr;
    struct sched_param param;

    Q_REQUIRE(stkSto == (void *)0);  /* p-threads allocate stack internally */

    QEQueue_init(&me->eQueue, qSto, (QEQueueCtr)qLen);
    pthread_cond_init(&me->osObject, 0);

    me->prio = prio;
    QF_add_(me);                     /* make QF aware of this active object */
    QF_ACTIVE_INIT_(&me->super, ie);      /* execute the initial transition */

    QS_FLUSH();                       /* flush the trace buffer to the host */

    pthread_attr_init(&attr);

    /* SCHED_FIFO corresponds to real-time preemptive priority-based scheduler
    * NOTE: This scheduling policy requires the superuser privileges
    */
    pthread_attr_setschedpolicy(&attr, SCHED_FIFO);
                                                              /* see NOTE04 */
    param.sched_priority = prio
                           + (sched_get_priority_max(SCHED_FIFO)
                              - QF_MAX_ACTIVE - 3);

    pthread_attr_setschedparam(&attr, &param);
    pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);

    if (pthread_create(&me->thread, &attr, &thread_routine, me) != 0) {
               /* Creating the p-thread with the SCHED_FIFO policy failed.
               * Most probably this application has no superuser privileges,
               * so we just fall back to the default SCHED_OTHER policy
               * and priority 0.
               */
        pthread_attr_setschedpolicy(&attr, SCHED_OTHER);
        param.sched_priority = 0;
        pthread_attr_setschedparam(&attr, &param);
        Q_ALLEGE(pthread_create(&me->thread, &attr, &thread_routine, me)== 0);
    }
    pthread_attr_destroy(&attr);
}
Example #19
0
//............................................................................
void QHsm::init(QEvent const *e) {
    QStateHandler t;
    QS_INT_LOCK_KEY_

                              // the top-most initial transition must be taken
    Q_ALLEGE((*m_state)(this, e) == Q_RET_TRAN);

    t = (QStateHandler)&QHsm::top;              // HSM starts in the top state
    do {                                           // drill into the target...
        QStateHandler path[QEP_MAX_NEST_DEPTH_];
        int8_t ip = (int8_t)0;                  // transition entry path index


        QS_BEGIN_(QS_QEP_STATE_INIT, QS::smObj_, this)
            QS_OBJ_(this);                        // this state machine object
            QS_FUN_(t);                                    // the source state
            QS_FUN_(m_state);          // the target of the initial transition
        QS_END_()

        path[0] = m_state;
        (void)QEP_TRIG_(m_state, QEP_EMPTY_SIG_);
        while (m_state != t) {
            ++ip;
            path[ip] = m_state;
            (void)QEP_TRIG_(m_state, QEP_EMPTY_SIG_);
        }
        m_state = path[0];
                                               // entry path must not overflow
        Q_ASSERT(ip < (int8_t)QEP_MAX_NEST_DEPTH_);

        do {           // retrace the entry path in reverse (desired) order...
            QEP_ENTER_(path[ip]);                            // enter path[ip]
            --ip;
        } while (ip >= (int8_t)0);

        t = path[0];                   // current state becomes the new source
    } while (QEP_TRIG_(t, Q_INIT_SIG) == Q_RET_TRAN);
    m_state = t;

    QS_BEGIN_(QS_QEP_INIT_TRAN, QS::smObj_, this)
        QS_TIME_();                                              // time stamp
        QS_OBJ_(this);                            // this state machine object
        QS_FUN_(m_state);                              // the new active state
    QS_END_()
}
Example #20
0
//............................................................................
void BSP_init(void) {
                                             // Enable the floating-point unit
    SCB->CPACR |= (0xFU << 20);

    // Enable lazy stacking for interrupt handlers. This allows FPU
    // instructions to be used within interrupt handlers, but at the
    // expense of extra stack and CPU usage.
    //
    FPU->FPCCR |= (1U << FPU_FPCCR_ASPEN_Pos) | (1U << FPU_FPCCR_LSPEN_Pos);

    // Set the clocking to run directly from the crystal
    ROM_SysCtlClockSet(SYSCTL_SYSDIV_1 | SYSCTL_USE_OSC
                       | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ);

    // enable clock to the peripherals used by the application
    SYSCTL->RCGC2 |= (1U << 5);                       // enable clock to GPIOF
    __NOP();                                     // wait after enabling clocks
    __NOP();
    __NOP();

    // configure the LEDs and push buttons
    GPIOF->DIR |= (LED_RED | LED_GREEN | LED_BLUE);   // set direction: output
    GPIOF->DEN |= (LED_RED | LED_GREEN | LED_BLUE);          // digital enable
    GPIOF->DATA_Bits[LED_RED]   = 0;                       // turn the LED off
    GPIOF->DATA_Bits[LED_GREEN] = 0;                       // turn the LED off
    GPIOF->DATA_Bits[LED_BLUE]  = 0;                       // turn the LED off

    // configure the User Switches
    GPIOF->DIR &= ~(USR_SW1 | USR_SW2);               //  set direction: input
    ROM_GPIOPadConfigSet(GPIO_PORTF_BASE, (USR_SW1 | USR_SW2),
                         GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD_WPU);

    BSP_randomSeed(1234U);

    Q_ALLEGE(QS_INIT(static_cast<void *>(0)));
    QS_RESET();
    QS_OBJ_DICTIONARY(&l_SysTick_Handler);
    QS_OBJ_DICTIONARY(&l_GPIOPortA_IRQHandler);
    QS_USR_DICTIONARY(PHILO_STAT);
}
Example #21
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 #22
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) ;
}
Example #23
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 #24
0
//............................................................................
void BSP_init(void) {
    Q_ALLEGE(QS_INIT(l_cmdLine));
    QS_RESET();
    QS_OBJ_DICTIONARY(&l_clock_tick);
    QS_USR_DICTIONARY(PLAYER_TRIGGER);
}
Example #25
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) ;
}