Esempio n. 1
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;
}
Esempio n. 2
0
/*..........................................................................*/
QState AlarmClock_mode24hr(AlarmClock * const me) {
    QState status;
    switch (Q_SIG(me)) {
        case Q_ENTRY_SIG: {
            printf("*** 24-hour mode\n");
            status = Q_HANDLED();
            break;
        }
        case Q_TIMEOUT_SIG: {
            /* roll over in 24-hr mode? */
            if (++me->current_time == 24U*60U) {
                me->current_time = 0U;
            }
            printf("%02d:%02d\n",
                   me->current_time / 60U, me->current_time % 60U);

            /* synchronously dispatch to the orthogonal component */
            Q_SIG(&me->alarm) = TIME_SIG;
            Q_PAR(&me->alarm) = me->current_time;
            QHSM_DISPATCH(&me->alarm.super);
            status = Q_HANDLED();
            break;
        }
        default: {
            status = Q_SUPER(&AlarmClock_timekeeping);
            break;
        }
    }
    return status;
}
Esempio n. 3
0
/*..........................................................................*/
QState AlarmClock_mode12hr(AlarmClock * const me) {
    QState status;
    switch (Q_SIG(me)) {
        case Q_ENTRY_SIG: {
            printf("*** 12-hour mode\n");
            status = Q_HANDLED();
            break;
        }
        case Q_TIMEOUT_SIG: {
            uint32_t h; /* temporary variable to hold hour */
            if (++me->current_time == 12U * 60U) {  /* roll over in 12-hr mode? */
                me->current_time = 0U;
            }
            h = me->current_time / 60U;
            printf("%02d:%02d %s\n", (h % 12U) ? (h % 12U) : 12U,
                   me->current_time % 60U, (h / 12U) ? "PM" : "AM");

            /* synchronously dispatch to the orthogonal component */
            Q_SIG(&me->alarm) = TIME_SIG;
            Q_PAR(&me->alarm) = me->current_time;
            QHSM_DISPATCH(&me->alarm.super);
            status = Q_HANDLED();
            break;
        }
        default: {
            status = Q_SUPER(&AlarmClock_timekeeping);
            break;
        }
    }
    return status;
}
Esempio n. 4
0
/*..........................................................................*/
QState AlarmClock_mode24hr(AlarmClock *me) {
    switch (Q_SIG(me)) {
        case Q_ENTRY_SIG: {
            printf("*** 24-hour mode\n");
            return Q_HANDLED();
        }
        case Q_TIMEOUT_SIG: {
                                                   /* timeout in one second */
            QActive_arm((QActive *)me, BSP_TICKS_PER_SEC);

            if (++me->current_time == 24*60) {  /* roll over in 24-hr mode? */
                me->current_time = 0;
            }
            printf("%02d:%02d\n",
                   me->current_time/60, me->current_time%60);

                      /* synchronously dispatch to the orthogonal component */
            Q_SIG(&me->alarm) = TIME_SIG;
            Q_PAR(&me->alarm) = me->current_time;
            Alarm_dispatch(&me->alarm);
            return Q_HANDLED();
        }
    }
    return Q_SUPER(&AlarmClock_timekeeping);
}
Esempio n. 5
0
void main(void) {
    printf("Ultimate Hook pattern\nQP-nano version: %s\n"
           "Press 'a'..'c' to inject signals A..C\n"
           "Press 'd' or ESC to inject signal D and quit\n",
           QP_getVersion());

    UltimateHook_ctor(&l_test);      /* instantiate the UltimateHook object */
    QHsm_init((QHsm *)&l_test);           /* trigger the initial transition */

    for (;;) {
        uint8_t c;

        printf("\n");
        c = (uint8_t)getch();        /* read one character from the console */
        printf("%c: ", c);

        switch (c) {
            case 'a':  Q_SIG(&l_test) = A_SIG;  break;
            case 'b':  Q_SIG(&l_test) = B_SIG;  break;
            case 'c':  Q_SIG(&l_test) = C_SIG;  break;
            case 'd':
            case 0x1B: Q_SIG(&l_test) = D_SIG;  break;         /* terminate */
        }
                               /* dispatch the event into the state machine */
        QHsm_dispatch((QHsm *)&l_test);
    }
}
Esempio n. 6
0
/*..........................................................................*/
QState AlarmClock_mode12hr(AlarmClock *me) {
    switch (Q_SIG(me)) {
        case Q_ENTRY_SIG: {
            printf("*** 12-hour mode\n");
            return Q_HANDLED();
        }
        case Q_TIMEOUT_SIG: {
            uint32_t h;                  /* temporary variable to hold hour */
                                                   /* timeout in one second */
            QActive_arm((QActive *)me, BSP_TICKS_PER_SEC);

            if (++me->current_time == 12*60) {  /* roll over in 12-hr mode? */
                me->current_time = 0;
            }
            h = me->current_time/60;
            printf("%02d:%02d %s\n", (h % 12) ? (h % 12) : 12,
                   me->current_time % 60, (h / 12) ? "PM" : "AM");

                      /* synchronously dispatch to the orthogonal component */
            Q_SIG(&me->alarm) = TIME_SIG;
            Q_PAR(&me->alarm) = me->current_time;
            Alarm_dispatch(&me->alarm);
            return Q_HANDLED();
        }
    }
    return Q_SUPER(&AlarmClock_timekeeping);
}
Esempio n. 7
0
/*..........................................................................*/
QState AlarmClock_timekeeping(AlarmClock * const me) {
    QState status;
    switch (Q_SIG(me)) {
        case Q_ENTRY_SIG: {
            /* timeout in one second and every second */
            QActive_armX(&me->super, 0U,
                         BSP_TICKS_PER_SEC, BSP_TICKS_PER_SEC);
            status = Q_HANDLED();
            break;
        }
        case Q_EXIT_SIG: {
            QActive_disarmX(&me->super, 0U);
            status = Q_HANDLED();
            break;
        }
        case Q_INIT_SIG: {
            status = Q_TRAN(&AlarmClock_mode24hr);
            break;
        }
        case CLOCK_12H_SIG: {
            status = Q_TRAN(&AlarmClock_mode12hr);
            break;
        }
        case CLOCK_24H_SIG: {
            status = Q_TRAN(&AlarmClock_mode24hr);
            break;
        }
        case ALARM_SIG: {
            printf("Wake up!!!\n");
            status = Q_HANDLED();
            break;
        }
        case ALARM_SET_SIG:
        case ALARM_ON_SIG:
        case ALARM_OFF_SIG: {
            /* synchronously dispatch to the orthogonal component */
            Q_SIG(&me->alarm) = Q_SIG(me);
            Q_PAR(&me->alarm) = Q_PAR(me);
            QHSM_DISPATCH(&me->alarm.super);
            status = Q_HANDLED();
            break;
        }
        case TERMINATE_SIG: {
            status = Q_TRAN(&AlarmClock_final);
            break;
        }
        default: {
            status = Q_SUPER(&QHsm_top);
            break;
        }
    }
    return status;
}
Esempio n. 8
0
static QState Philo_hungry(Philo * const me) {
    QState status_;
    switch (Q_SIG(me)) {
        /* @(/1/0/0/2/0) */
        case EAT_SIG: {
            static QActionHandler const act_[] = {
                Q_ACTION_CAST(&Philo_eating_e),
                Q_ACTION_CAST(0)
            };
            status_ = QM_TRAN(&Philo_eating_s, &act_[0]);
            break;
        }
        /* @(/1/0/0/2/1) */
        case DONE_SIG: {
            Q_ERROR(); /* this event should never arrive in this state */
            status_ = QM_HANDLED();
            break;
        }
        default: {
            status_ = QM_SUPER();
            break;
        }
    }
    return status_;
}
Esempio n. 9
0
/* @(/1/0/1/1/5/4/4) .......................................................*/
static QState QHsmTst_s211(QHsmTst * const me) {
    QState status_;
    switch (Q_SIG(me)) {
        /* @(/1/0/1/1/5/4/4) */
        case Q_ENTRY_SIG: {
            BSP_display("s211-ENTRY;");
            status_ = Q_HANDLED();
            break;
        }
        /* @(/1/0/1/1/5/4/4) */
        case Q_EXIT_SIG: {
            BSP_display("s211-EXIT;");
            status_ = Q_HANDLED();
            break;
        }
        /* @(/1/0/1/1/5/4/4/0) */
        case H_SIG: {
            BSP_display("s211-H;");
            status_ = Q_TRAN(&QHsmTst_s);
            break;
        }
        /* @(/1/0/1/1/5/4/4/1) */
        case D_SIG: {
            BSP_display("s211-D;");
            status_ = Q_TRAN(&QHsmTst_s21);
            break;
        }
        default: {
            status_ = Q_SUPER(&QHsmTst_s21);
            break;
        }
    }
    return status_;
}
Esempio n. 10
0
File: ui.c Progetto: russells/hc2
static QState uiMenuSettimeHours(struct UI *me)
{
	switch (Q_SIG(me)) {
	case Q_ENTRY_SIG:
		lcd_buttons(LCD_BUTTONS_ALL);
		me->settime_YmdHM = 'H';
		display_set_time(me, TRUE, TRUE);
		QActive_armX((QActive*)me, 1, 17);
		return Q_HANDLED();
	case Q_TIMEOUT1_SIG:
		return Q_TRAN(uiMenuSettimeHoursFlash);
	case BUTTON_ENTER_PRESS_SIGNAL:
		ACTION();
		return Q_TRAN(uiMenuSettimeMinutes);
	case BUTTON_UP_PRESS_SIGNAL:
	case BUTTON_UP_LONG_PRESS_SIGNAL:
	case BUTTON_UP_REPEAT_SIGNAL:
		ACTION();
		inc_hour(&me->settime);
		display_set_time(me, TRUE, TRUE);
		QActive_armX((QActive*)me, 1, 17);
		return Q_HANDLED();
	case BUTTON_DOWN_PRESS_SIGNAL:
	case BUTTON_DOWN_LONG_PRESS_SIGNAL:
	case BUTTON_DOWN_REPEAT_SIGNAL:
		ACTION();
		dec_hour(&me->settime);
		display_set_time(me, TRUE, TRUE);
		QActive_armX((QActive*)me, 1, 17);
		return Q_HANDLED();
	}
	return Q_SUPER(uiMenu);
}
Esempio n. 11
0
File: ui.c Progetto: russells/hc2
static QState scroll(struct UI *me)
{
	switch (Q_SIG(me)) {
	case Q_ENTRY_SIG:
		SERIALSTR("scroll");
		me->scrollstring = banner;
		me->scrollindex = 0;
		BSP_fast_timer_1(TRUE);
		return Q_HANDLED();
	case BUTTON_ENTER_PRESS_SIGNAL:
	case BUTTON_ENTER_LONG_PRESS_SIGNAL:
	case BUTTON_ENTER_REPEAT_SIGNAL:
	case BUTTON_UP_PRESS_SIGNAL:
	case BUTTON_UP_LONG_PRESS_SIGNAL:
	case BUTTON_UP_REPEAT_SIGNAL:
	case BUTTON_DOWN_PRESS_SIGNAL:
	case BUTTON_DOWN_LONG_PRESS_SIGNAL:
	case BUTTON_DOWN_REPEAT_SIGNAL:
	case BUTTON_CANCEL_PRESS_SIGNAL:
	case BUTTON_CANCEL_LONG_PRESS_SIGNAL:
	case BUTTON_CANCEL_REPEAT_SIGNAL:
		return Q_TRAN(uiRun);
	case Q_EXIT_SIG:
		BSP_fast_timer_1(FALSE);
		/* If we exit here on a button press, the buttons AO (or the
		   Basic Timer 1 ISR) may see the button down immediately, with
		   the result that the UI immediately enters the menu.  Avoid
		   that by telling the buttons to wait. */
		post(&buttons.super, BUTTONS_WAIT_SIGNAL, 0);
		return Q_HANDLED();
	}
	return Q_SUPER(uiTop);
}
Esempio n. 12
0
File: ui.c Progetto: russells/hc2
static QState uiMenuSettimeMinutesFlash(struct UI *me)
{
	switch (Q_SIG(me)) {
	case Q_ENTRY_SIG:
		display_set_time(me, TRUE, FALSE);
		QActive_armX((QActive*)me, 1, 8);
		return Q_HANDLED();
	case Q_TIMEOUT1_SIG:
		display_set_time(me, TRUE, TRUE);
		return Q_TRAN(uiMenuSettimeMinutes);
	case BUTTON_UP_PRESS_SIGNAL:
	case BUTTON_UP_LONG_PRESS_SIGNAL:
	case BUTTON_UP_REPEAT_SIGNAL:
	case BUTTON_DOWN_PRESS_SIGNAL:
	case BUTTON_DOWN_LONG_PRESS_SIGNAL:
	case BUTTON_DOWN_REPEAT_SIGNAL:
		/**
		 * React to the event by re-displaying the time (without the
		 * minutes hidden), but don't handle it.  This makes the time
		 * appear on the display as the button is pressed, which is
		 * move obvious to the user.
		 */
		display_set_time(me, TRUE, TRUE);
		break;
	case Q_EXIT_SIG:
		QActive_armX((QActive*)me, 1, 17);
		return Q_HANDLED();
	}
	return Q_SUPER(uiMenuSettimeMinutes);
}
Esempio n. 13
0
QState QHsmTst_WAITING(QHsmTst *me) {
    switch (Q_SIG(me)) {

    case Q_ENTRY_SIG: {
        if(elevOrders[currentFloor]) {
            arrivedAtFloor(currentFloor,waiting);
            tick5();
            tick5();
            BSP_display("timePassed10;");
            BSP_display("waiting-ENTRY;");
            arrivedAtFloor(currentFloor,waiting);

        }
        return Q_HANDLED();
    }
    case Q_EXIT_SIG: {

        BSP_display("waiting-EXIT;");
        return Q_HANDLED();
    }

    case GO_DOWN: {
        BSP_display("received-go-down;");
        direct = DOWN;
        return Q_TRAN(&QHsmTst_MOVING);
    }
    case GO_UP: {

        BSP_display("received-go-up;");
        direct = UP;
        return Q_TRAN(&QHsmTst_MOVING);
    }
    }
    return Q_SUPER(&QHsmTst_SUPER);
}
Esempio n. 14
0
/*..........................................................................*/
QState Bomb_timing(Bomb *me) {
    switch (Q_SIG(me)) {
        case Q_ENTRY_SIG: {
            QActive_arm((QActive *)me, BSP_TICKS_PER_SEC/4);
            return Q_HANDLED();
        }
        case Q_TIMEOUT_SIG: {
            QActive_arm((QActive *)me, BSP_TICKS_PER_SEC/4);
            if (me->ctr > (uint8_t)0) {
                if ((me->ctr & 0x01) != 0) {
                    LED_on();
                }
                else {
                    LED_off();
                }
                --me->ctr;
            }
            else {                                       /* timeout expired */
                return Q_TRAN(&Bomb_blast);
            }
            return Q_HANDLED();
        }
    }
    return Q_IGNORED();
}
Esempio n. 15
0
/*${AOs::Blink::SM::OFF} ...................................................*/
static QState Blink_OFF(Blink * const me) {
    QState status_;
    switch (Q_SIG(me)) {
        /* ${AOs::Blink::SM::OFF} */
        case Q_ENTRY_SIG: {
            BSP_ledOff();
            QActive_arm((QActive *)me, BLINK_TOUT);
            status_ = Q_HANDLED();
            break;
        }
        /* ${AOs::Blink::SM::OFF} */
        case Q_EXIT_SIG: {
            QActive_disarm((QActive *)me);
            status_ = Q_HANDLED();
            break;
        }
        /* ${AOs::Blink::SM::OFF::Q_TIMEOUT} */
        case Q_TIMEOUT_SIG: {
            status_ = Q_TRAN(&Blink_ON);
            break;
        }
        default: {
            status_ = Q_SUPER(&QHsm_top);
            break;
        }
    }
    return status_;
}
Esempio n. 16
0
/*..........................................................................*/
QState ToasterOven_doorClosed(ToasterOven *me) {
    switch (Q_SIG(me)) {
        case Q_ENTRY_SIG: {
            printf("door-Closed;");
            return Q_HANDLED();
        }
        case Q_EXIT_SIG: {
            me->doorClosed_history = QHsm_state(&me->super);/*<-save HISTORY*/
            return Q_HANDLED();
        }
        case Q_INIT_SIG: {
            return Q_TRAN(&ToasterOven_off);
        }
        case OPEN_SIG: {
            return Q_TRAN(&ToasterOven_doorOpen);
        }
        case TOAST_SIG: {
            return Q_TRAN(&ToasterOven_toasting);
        }
        case BAKE_SIG: {
            return Q_TRAN(&ToasterOven_baking);
        }
        case OFF_SIG: {
            return Q_TRAN(&ToasterOven_off);
        }
        case TERMINATE_SIG: {
            return Q_TRAN(&ToasterOven_final);
        }
    }
    return Q_SUPER(&QHsm_top);
}
Esempio n. 17
0
static QState mmi_busy(struct mmi_ao *me)
{
    static const char busy_char[] = ". ";
    static uint8_t busy_index;

    switch (Q_SIG(me)) {
    case Q_ENTRY_SIG:
        // Print hello message
        lcd_clear();
        lcd_write(0, 0, "Busy ...", 0);
        QActive_arm((QActive *) me, TIMEOUT_BUSY);
        return Q_HANDLED();
    case Q_EXIT_SIG:
        QActive_disarm((QActive *) me);
        return Q_HANDLED();
    case Q_TIMEOUT_SIG:
        lcd_char(15, 0, busy_char[busy_index]);
        busy_index = (busy_index + 1) % (sizeof(busy_char) - 1);
        QActive_arm((QActive *) me, TIMEOUT_BUSY);
        return Q_HANDLED();
    case SIG_KEY_PRESS:
        if (Q_PAR(me) == KEY_LEFT) {
            QActive_post((QActive *) &prog_ao, SIG_PROG_STOP, 0);
            return Q_TRAN(mmi_navigate);
        }
        return Q_HANDLED();
    case SIG_PROG_DONE:
        return Q_TRAN(mmi_navigate);
    }

    return Q_SUPER(&QHsm_top);
}
Esempio n. 18
0
static QState Philo_eating(Philo * const me) {
    QState status_;
    switch (Q_SIG(me)) {
        /* @(/1/0/0/3/0) */
        case Q_TIMEOUT_SIG: {
            static QActionHandler const act_[] = {
                Q_ACTION_CAST(&Philo_eating_x),
                Q_ACTION_CAST(&Philo_thinking_e),
                Q_ACTION_CAST(0)
            };
            status_ = QM_TRAN(&Philo_thinking_s, &act_[0]);
            break;
        }
        /* @(/1/0/0/3/1) */
        case EAT_SIG: /* intentionally fall through */
        case DONE_SIG: {
            Q_ERROR(); /* these events should never arrive in this state */
            status_ = QM_HANDLED();
            break;
        }
        default: {
            status_ = QM_SUPER();
            break;
        }
    }
    return status_;
}
Esempio n. 19
0
File: ui.c Progetto: russells/hc2
static QState uiMenuSettimeHoursFlash(struct UI *me)
{
	switch (Q_SIG(me)) {
	case Q_ENTRY_SIG:
		display_set_time(me, FALSE, TRUE);
		QActive_armX((QActive*)me, 1, 8);
		return Q_HANDLED();
	case Q_TIMEOUT1_SIG:
		display_set_time(me, TRUE, TRUE);
		return Q_TRAN(uiMenuSettimeHours);
	case BUTTON_UP_PRESS_SIGNAL:
	case BUTTON_UP_LONG_PRESS_SIGNAL:
	case BUTTON_UP_REPEAT_SIGNAL:
	case BUTTON_DOWN_PRESS_SIGNAL:
	case BUTTON_DOWN_LONG_PRESS_SIGNAL:
	case BUTTON_DOWN_REPEAT_SIGNAL:
		/** @see the comment in uiMenuSettimeMinutesFlash() */
		display_set_time(me, TRUE, TRUE);
		break;
	case Q_EXIT_SIG:
		QActive_armX((QActive*)me, 1, 17);
		return Q_HANDLED();
	}
	return Q_SUPER(uiMenuSettimeHours);
}
Esempio n. 20
0
QState s_light_timer(ao_light_t * const me)
{
    QState status;
    switch (Q_SIG(me)) {
        case Q_ENTRY_SIG:
            light_on();
            status = Q_HANDLED();
            break;
        case LIGHT_OFF_SIG:
            status = Q_TRAN(&s_light_off);
            break;
        case LIGHT_ON_SIG:
            status = Q_TRAN(&s_light_on);
            break;
        case Q_TIMEOUT_SIG:
            me->timer -= 1;
            if (me->timer == 0)
                status = Q_TRAN(&s_light_off);
            else
                status = Q_HANDLED();
            break;
        default:
            status = Q_SUPER(&QHsm_top);
            break;
    }
    return status;
}
Esempio n. 21
0
File: ui.c Progetto: russells/hc2
static QState uiTop(struct UI *me)
{
	const struct Time *time;

	switch (Q_SIG(me)) {
	case Q_ENTRY_SIG:
		lcd_clear();
		lcd_showdigits("6789");
		break;
	case WATCHDOG_SIGNAL:
		// TODO: watchdog reset
		return Q_HANDLED();
	case TEMPERATURE_SIGNAL:
		SERIALSTR("uiTop: TS\r\n");
		return Q_HANDLED();
	case TIME_SIGNAL:
		time = (const struct Time*)(Q_PAR(me));
		Q_ASSERT( time->ht >= '0' && time->ht <= '9' );
		Q_ASSERT( time->h1 >= '0' && time->h1 <= '9' );
		Q_ASSERT( time->mt >= '0' && time->mt <= '9' );
		Q_ASSERT( time->m1 >= '0' && time->m1 <= '9' );
		show_time(time);
		return Q_HANDLED();
	case CURRENT_TEMPERATURE_SIGNAL:
		/* Handle this signal here, so that no matter where the UI is,
		   the current temperature will be available when it's
		   finished. */
		me->ti = (int16_t) Q_PAR(me);
		return Q_HANDLED();
	case BUTTON_CANCEL_PRESS_SIGNAL:
		return Q_TRAN(uiRun);
	}
	return Q_SUPER(QHsm_top);
}
Esempio n. 22
0
static QState twiState(struct TWI *me)
{
	struct TWIRequest **requestp;
	struct TWIRequest *request;

	switch (Q_SIG(me)) {

	case Q_ENTRY_SIG:
		twi.ready = 73;
		return Q_HANDLED();

	case TWI_REQUEST_SIGNAL:
		//SERIALSTR("TWI Got TWI_REQUEST_SIGNAL\r\n");
		requestp = (struct TWIRequest **)((uint16_t)Q_PAR(me));
		Q_ASSERT( requestp );
		request = *requestp;
		Q_ASSERT( request );
		Q_ASSERT( ! me->requests[0] );
		me->requests[0] = request;
		requestp++;
		request = *requestp;
		Q_ASSERT( ! me->requests[1] );
		me->requests[1] = request;
		me->requestIndex = 0;
		return Q_TRAN(twiBusyState);
	}
	return Q_SUPER(&QHsm_top);
}
Esempio n. 23
0
File: ui.c Progetto: russells/hc2
static QState uiMenu(struct UI *me)
{
	switch (Q_SIG(me)) {
	case Q_ENTRY_SIG:
		ACTION();
		BSP_fast_timer_1(TRUE);
		BSP_fast_timer_2(TRUE);
		return Q_HANDLED();
	case UI_ACTION_SIGNAL:
		SERIALSTR("U");
		me->timeoutcounter = 4;
		lcd_timeouts(me->timeoutcounter);
		QActive_armX((QActive*)(me), 2,
			     3 * BSP_TICKS_PER_SECOND_TIMER2);
		return Q_HANDLED();
	case Q_TIMEOUT2_SIG:
		me->timeoutcounter --;
		lcd_timeouts(me->timeoutcounter);
		if (me->timeoutcounter) {
			QActive_armX((QActive*)(me), 2,
				     3 * BSP_TICKS_PER_SECOND_TIMER2);
			return Q_HANDLED();
		} else {
			return Q_TRAN(uiRun);
		}
	case BUTTON_CANCEL_PRESS_SIGNAL:
		return Q_TRAN(uiRun);
	case Q_EXIT_SIG:
		BSP_fast_timer_1(FALSE);
		BSP_fast_timer_2(FALSE);
		lcd_timeouts(0);
		return Q_HANDLED();
	}
	return Q_SUPER(uiTop);
}
Esempio n. 24
0
/*..........................................................................*/
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);
}
/*${components::aoGrinder::SM::done} .......................................*/
static QState aoGrinder_done(aoGrinder * const me) {
    QState status_;
    switch (Q_SIG(me)) {
        /* ${components::aoGrinder::SM::done} */
        case Q_ENTRY_SIG: {
            BSP_println("Grinder done.");
            QActive_postISR((QActive *)&AO_Display, DISPLAY_RESULT_SIG, 0);
            status_ = Q_HANDLED();
            break;
        }
        /* ${components::aoGrinder::SM::done} */
        case Q_EXIT_SIG: {
            QActive_postISR((QActive *)&AO_Scale, SCALE_STOP_SIG, 0);
            QActive_postISR((QActive *)&AO_Display, DISPLAY_IDLE_SIG, 0);
            status_ = Q_HANDLED();
            break;
        }
        /* ${components::aoGrinder::SM::done::NEGATIVE_REACHED} */
        case NEGATIVE_REACHED_SIG: {
            status_ = Q_TRAN(&aoGrinder_idle);
            break;
        }
        default: {
            status_ = Q_SUPER(&QHsm_top);
            break;
        }
    }
    return status_;
}
Esempio n. 26
0
/*${SMs::ToastOven::SM::doorOpen} ..........................................*/
static QState ToastOven_doorOpen(ToastOven * const me) {
    QState status_;
    switch (Q_SIG(me)) {
        /*${SMs::ToastOven::SM::doorOpen} */
        case Q_ENTRY_SIG: {
            printf("door-Open,lamp-On;");
            status_ = Q_HANDLED();
            break;
        }
        /*${SMs::ToastOven::SM::doorOpen} */
        case Q_EXIT_SIG: {
            printf("lamp-Off;");
            status_ = Q_HANDLED();
            break;
        }
        /*${SMs::ToastOven::SM::doorOpen::CLOSE} */
        case CLOSE_SIG: {
            status_ = Q_TRAN_HIST(me->hist_doorClosed);
            break;
        }
        /*${SMs::ToastOven::SM::doorOpen::TERMINATE} */
        case TERMINATE_SIG: {
            status_ = Q_TRAN(&ToastOven_final);
            break;
        }
        default: {
            status_ = Q_SUPER(&QHsm_top);
            break;
        }
    }
    return status_;
}
Esempio n. 27
0
/*${SMs::ToastOven::SM::doorClosed::heating} ...............................*/
static QState ToastOven_heating(ToastOven * const me) {
    QState status_;
    switch (Q_SIG(me)) {
        /*${SMs::ToastOven::SM::doorClosed::heating} */
        case Q_ENTRY_SIG: {
            printf("heater-On;");
            status_ = Q_HANDLED();
            break;
        }
        /*${SMs::ToastOven::SM::doorClosed::heating} */
        case Q_EXIT_SIG: {
            printf("heater-Off;");
            status_ = Q_HANDLED();
            break;
        }
        /*${SMs::ToastOven::SM::doorClosed::heating::initial} */
        case Q_INIT_SIG: {
            status_ = Q_TRAN(&ToastOven_toasting);
            break;
        }
        default: {
            status_ = Q_SUPER(&ToastOven_doorClosed);
            break;
        }
    }
    return status_;
}
/*${components::aoGrinder::SM::grinding} ...................................*/
static QState aoGrinder_grinding(aoGrinder * const me) {
    QState status_;
    switch (Q_SIG(me)) {
        /* ${components::aoGrinder::SM::grinding} */
        case Q_ENTRY_SIG: {
            BSP_println("Start grinding.");
            BSP_ledOn();
            QActive_postISR((QActive *)&AO_Scale, SCALE_START_SIG, 0);
            QActive_postISR((QActive *)&AO_Display, DISPLAY_WEIGHT_SIG, 0);
            status_ = Q_HANDLED();
            break;
        }
        /* ${components::aoGrinder::SM::grinding} */
        case Q_EXIT_SIG: {
            BSP_println("Stop grinding.");
            BSP_ledOff();
            status_ = Q_HANDLED();
            break;
        }
        /* ${components::aoGrinder::SM::grinding::THRESHOLD_REACHED} */
        case THRESHOLD_REACHED_SIG: {
            status_ = Q_TRAN(&aoGrinder_settling);
            break;
        }
        default: {
            status_ = Q_SUPER(&QHsm_top);
            break;
        }
    }
    return status_;
}
Esempio n. 29
0
/*..........................................................................*/
QState Sensor_polling(Sensor *me) {
    switch (Q_SIG(me)) {
        case Q_ENTRY_SIG: {
                                                   /* timeout in 1/2 second */
            QActive_arm((QActive *)me, BSP_TICKS_PER_SEC/2);
            return Q_HANDLED();
        }
        case Q_EXIT_SIG: {
            QActive_disarm((QActive *)me);
            return Q_HANDLED();
        }
        case Q_INIT_SIG: {
            return Q_TRAN(&Sensor_processing);
        }
        case Q_TIMEOUT_SIG: {
                                                   /* timeout in 1/2 second */
            QActive_arm((QActive *)me, BSP_TICKS_PER_SEC/2);
            ++me->pollCtr;
            printf("poll %3d\n", me->pollCtr);
            if ((me->pollCtr & 0x3) == 0) {                     /* modulo 4 */
                QActive_post((QActive *)me, DATA_READY_SIG, 0);
            }
            return Q_HANDLED();
        }
        case TERMINATE_SIG: {
            return Q_TRAN(&Sensor_final);
        }
    }
    return Q_SUPER(&QHsm_top);
}
Esempio n. 30
0
static QState Pelican_carsGreenNoPed(Pelican * const me) {
    QState status_;
    switch (Q_SIG(me)) {
        /* @(/1/0/1/1/2/1/1/0) */
        case PEDS_WAITING_SIG: {
            static QActionHandler const act_[] = {
                Q_ACTION_CAST(&Pelican_carsGreenPedWait_e),
                Q_ACTION_CAST(0)
            };
            status_ = QM_TRAN(&Pelican_carsGreenPedWait_s, &act_[0]);
            break;
        }
        /* @(/1/0/1/1/2/1/1/1) */
        case Q_TIMEOUT_SIG: {
            static QActionHandler const act_[] = {
                Q_ACTION_CAST(&Pelican_carsGreenInt_e),
                Q_ACTION_CAST(0)
            };
            status_ = QM_TRAN(&Pelican_carsGreenInt_s, &act_[0]);
            break;
        }
        default: {
            status_ = QM_SUPER();
            break;
        }
    }
    return status_;
}