Esempio n. 1
0
/*..........................................................................*/
void onConsoleInput(uint8_t key) {
    switch (key) {
        case 'n': {                                         /* new request? */
            static uint8_t reqCtr = 0;                /* count the requests */
            QActive_post((QActive *)&AO_TServer, NEW_REQUEST_SIG, ++reqCtr);
            break;
        }
        case 0x1B: {                                        /* ESC pressed? */
            QActive_post((QActive *)&AO_TServer, TERMINATE_SIG, 0);
            break;
        }
    }
}
Esempio n. 2
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. 3
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);
}
Esempio n. 4
0
static QState mmi_giga_pan(struct mmi_ao *me)
{
    char tmp[17];

    switch (Q_SIG(me)) {
    case Q_ENTRY_SIG:
        prog_init_giga_pan();
        lcd_clear();
        lcd_write(0, 0, "Giga pan", 0);
        snprintf(tmp, sizeof(tmp), "%dx%d tiles", giga_info.tiles.x, giga_info.tiles.y);
        lcd_write(0, 1, tmp, 0);
        return Q_HANDLED();
    case Q_EXIT_SIG:
        return Q_HANDLED();
    case Q_TIMEOUT_SIG:
        return Q_HANDLED();
    case SIG_KEY_PRESS:
        switch (Q_PAR(me)) {
        case KEY_ENTER:
            QActive_post((QActive *) &prog_ao, SIG_PROG_START, PROG_GIGA_PAN);
            return Q_TRAN(mmi_busy);
        case KEY_LEFT:
            return Q_TRAN(mmi_navigate);
        }
        return Q_HANDLED();;
    }

    return Q_SUPER(&QHsm_top);
}
Esempio n. 5
0
/*..........................................................................*/
QState Alarm_on(Alarm *me) {
    switch (Q_SIG(me)) {
        case Q_ENTRY_SIG: {
            printf("*** Alarm ON %02ld:%02ld\n",
                   me->alarm_time/60, me->alarm_time%60);
            fflush(stdout);
            return Q_HANDLED();
        }
        case ALARM_SET_SIG: {
            printf("*** Cannot set Alarm when it is ON\n");
            fflush(stdout);
            return Q_HANDLED();
        }
        case ALARM_OFF_SIG: {
            return Q_TRAN(&Alarm_off);
        }
        case TIME_SIG: {
            if (Q_PAR(me) == me->alarm_time) {
                printf("ALARM!!!\n");
                       /* asynchronously post the event to the container AO */
                QActive_post((QActive *)&AO_AlarmClock, ALARM_SIG, 0);
            }
            return Q_HANDLED();
        }
    }
    return Q_IGNORED();
}
Esempio n. 6
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. 7
0
File: ui.c Progetto: russells/hc2
static void recall(struct UI *me)
{
	if (me->deferredSignal) {
		QActive_post(&me->super, me->deferredSignal, me->deferredParam);
		me->deferredSignal = 0;
		me->deferredParam = 0;
	}
}
Esempio n. 8
0
/*..........................................................................*/
QState Ped_off(Ped *me) {
    switch (Q_SIG(me)) {
        case Q_ENTRY_SIG: {
            BSP_showState(me->super.prio, "off");
            QActive_arm((QActive *)me, OFF_TOUT);
            QActive_post((QActive *)&AO_Pelican, OFF_SIG, 0);
            return Q_HANDLED();
        }
        case Q_TIMEOUT_SIG: {
            QActive_post((QActive *)&AO_Pelican, ON_SIG, 0);
            return Q_TRAN(&Ped_wait);
        }
        case TERMINATE_SIG: {
            QF_stop();
            return Q_HANDLED();
        }
    }
    return Q_SUPER(&QHsm_top);
}
Esempio n. 9
0
void TServer_recallRequest(TServer *me) {
    if (me->deferredRequest.sig != 0) {    /* the request already deferred? */
        printf("recalling request #%d\n", (int)me->deferredRequest.par);
        QActive_post((QActive *)me,
                     me->deferredRequest.sig, me->deferredRequest.par);

        me->deferredRequest.sig = 0;          /* request no longer deferred */
    }
    else {
        printf("No requests to recall\n");
    }
}
Esempio n. 10
0
/*..........................................................................*/
QState Philo_hungry(Philo *me) {
    switch (Q_SIG(me)) {
        case Q_ENTRY_SIG: {
            QActive_post((QActive *)&AO_Table, HUNGRY_SIG, me->super.prio);
            return Q_HANDLED();
        }
        case EAT_SIG: {
            BSP_busyDelay();
            return Q_TRAN(&Philo_eating);
        }
//        case DONE_SIG: {
//            Q_ERROR();      /* thes event should never arrive in this state */
//            return Q_HANDLED();
//        }
    }
    return Q_IGNORED();
}
Esempio n. 11
0
/*..........................................................................*/
QState Oper_run(Oper *me) {
    switch (Q_SIG(me)) {
        case Q_ENTRY_SIG: {
            QActive_arm((QActive *)me, me->interval);
            return Q_HANDLED();
        }
        case Q_EXIT_SIG: {
            uint8_t timeout = me->bomb_prev + 1;
            if (timeout > me->bomb_max) {
                timeout = me->bomb_min;
            }
            me->bomb_prev = timeout;
            QActive_post((QActive *)&AO_Bomb, ARM_SIG, timeout);
            return Q_HANDLED();
        }
        case Q_TIMEOUT_SIG: {
            return Q_TRAN(&Oper_run);                 /* transition to self */
        }
    }
    return Q_IGNORED();
}
Esempio n. 12
0
/*..........................................................................*/
QState Philo_eating(Philo *me) {
    switch (Q_SIG(me)) {
        case Q_ENTRY_SIG: {
            QActive_arm((QActive *)me, EAT_TIME);
            return Q_HANDLED();
        }
        case Q_EXIT_SIG: {
            BSP_busyDelay();
            QActive_post((QActive *)&AO_Table, DONE_SIG, me->super.prio);
            return Q_HANDLED();
        }
        case Q_TIMEOUT_SIG: {
            return Q_TRAN(&Philo_thinking);
        }
        case EAT_SIG:
        case DONE_SIG: {
            Q_ERROR();    /* these events should never arrive in this state */
        }
    }
    return Q_SUPER(&QHsm_top);
}
Esempio n. 13
0
/**
 * Hello state.
 * Prints a hello message and waits for keypress or timeout to switch to main menu.
 */
static QState mmi_hello(struct mmi_ao *me)
{
    switch (Q_SIG(me)) {
    case Q_ENTRY_SIG:
        // Print hello message
        lcd_write(0, 0, " CamControl 0.1", 0);
        lcd_write(0, 1, "----------------", 0);
        QActive_post((QActive *) &backlight_ao, SIG_BACKLIGHT_ACTIVATE, 0);
        QActive_arm((QActive *) me, TIMEOUT_HELLO);
        return Q_HANDLED();
    case Q_EXIT_SIG:
        // Clear screen
        QActive_disarm((QActive *) me);
        return Q_HANDLED();
    case Q_TIMEOUT_SIG:
    case SIG_ENCODER:
    case SIG_KEY_PRESS:
    case SIG_KEY_RELEASE:
        return Q_TRAN(mmi_navigate);
    }

    return Q_SUPER(&QHsm_top);
}
Esempio n. 14
0
/*..........................................................................*/
void onConsoleInput(uint8_t key) {
    switch (key) {
        case 'o': {                                    /* Alarm 'o'n event? */
            QActive_post((QActive *)&AO_AlarmClock, ALARM_ON_SIG, 0);
            break;
        }
        case 'f': {                                   /* Alarm o'f'f event? */
            QActive_post((QActive *)&AO_AlarmClock, ALARM_OFF_SIG, 0);
            break;
        }
        case '0':
        case '1':
        case '2':
        case '3':
        case '4':
        case '5':
        case '6':
        case '7':
        case '8':
        case '9': {                                     /* Alarm set event? */
            QActive_post((QActive *)&AO_AlarmClock, ALARM_SET_SIG, key - '0');
            break;
        }
        case 'A': {                                     /* Clock 12H event? */
            QActive_post((QActive *)&AO_AlarmClock, CLOCK_12H_SIG, 0);
            break;
        }
        case 'B': {                                     /* Clock 24H event? */
            QActive_post((QActive *)&AO_AlarmClock, CLOCK_24H_SIG, 0);
            break;
        }
        case 0x1B: {                                        /* ESC pressed? */
            QActive_post((QActive *)&AO_AlarmClock, TERMINATE_SIG, 0);
            break;
        }
    }
}
Esempio n. 15
0
/**
 * Navigate state.
 * Navigates the menu structure using the following buttons:
 *  - up => go to previous item
 *  - down => go to next item
 *  - left => go to parent item
 *  - right => go to child item
 */
static QState mmi_navigate(struct mmi_ao *me)
{
    switch (Q_SIG(me)) {
    case Q_ENTRY_SIG:
        update_screen(me);
        return Q_HANDLED();
    case Q_EXIT_SIG:
        return Q_HANDLED();
    case SIG_ENCODER:
        switch (menu_cur->typ) {
        case MENU_TYP_PARAM:
            if (modify_param(menu_cur->param, Q_PAR(me), me->shift)) {
                print_param(menu_cur->param);
                if (menu_cur->cmd != CMD_NONE)
                    QActive_post((QActive *) me, SIG_MMI_CMD, menu_cur->cmd);
            }
            break;
        default:
            break;
        }
        return Q_HANDLED();
    case SIG_MMI_CMD:
        return execute_cmd(me, Q_PAR(me));
    case SIG_MMI_SHOW_MSG:
        return Q_TRAN(mmi_show_msg);
    case SIG_KEY_PRESS:
        switch (Q_PAR(me)) {
        case KEY_UP:
            // Go to previous item
            if (menu_prev())
                update_screen(me);
            break;
        case KEY_DOWN:
            // Go to next item
            if (menu_next())
                update_screen(me);
            break;
        case KEY_LEFT:
            // Go to parent item
            if (menu_parent())
                update_screen(me);
            break;
        case KEY_RIGHT:
            // Go to sub item
            if (menu_sub())
                update_screen(me);
            break;
        case KEY_ENTER:
            me->shift = 1;
            switch (menu_cur->typ) {
            case MENU_TYP_CMD:
                // Execute command
                if (menu_cur->cmd)
                    QActive_post((QActive *) me, SIG_MMI_CMD, menu_cur->cmd);
                break;
            case MENU_TYP_SUB:
                // Go to sub item
                if (menu_sub())
                    update_screen(me);
                break;
            default:
                break;
            }
            break;
        }
        return Q_HANDLED();
    case SIG_KEY_RELEASE:
        switch (Q_PAR(me)) {
        case KEY_ENTER:
            me->shift = 0;
        default:
            break;
        }
        return Q_HANDLED();
    case SIG_PROG_START:
        return Q_TRAN(mmi_busy);
        break;
    }

    return Q_SUPER(&QHsm_top);
}
Esempio n. 16
0
static QState execute_cmd(struct mmi_ao *me, int cmd)
{
    vec2f_t v;

    switch (cmd) {
    case CMD_SINGLE_SHOT:
        QActive_post((QActive *) &shutter_ao, SIG_SHUTTER_START, 0);
        break;
    case CMD_SPHERICAL_PAN:
        return Q_TRAN(mmi_spherical_pan);
    case CMD_GIGA_PAN:
        return Q_TRAN(mmi_giga_pan);
    case CMD_TIMELAPSE:
        QActive_post((QActive *) &prog_ao, SIG_PROG_START, PROG_TIMELAPSE);
        QActive_post((QActive *) &mmi_ao, SIG_PROG_START, PROG_TIMELAPSE);
        break;
    case CMD_SAVE:
        show_msg("Saving...", 1);
        param_save();
        break;
    case CMD_SERVO_MIN:
        vec2(&v, deg2rad(0.0), deg2rad(0.0));
        servo_move(&v);
        break;
    case CMD_SERVO_CENTER:
        vec2(&v, deg2rad(180.0), deg2rad(90.0));
        servo_move(&v);
        break;
    case CMD_SERVO_MAX:
        vec2(&v, deg2rad(360.0), deg2rad(180.0));
        servo_move(&v);
        break;
    case CMD_UPDATE_SERVO_MIN_X:
        servo_get_goal(&v);
        v.x = deg2rad(0);;
        servo_move(&v);
        break;
    case CMD_UPDATE_SERVO_MAX_X:
        servo_get_goal(&v);
        v.x = deg2rad(360);
        servo_move(&v);
        break;
    case CMD_UPDATE_SERVO_MIN_Y:
        servo_get_goal(&v);
        v.y = deg2rad(0);
        servo_move(&v);
        break;
    case CMD_UPDATE_SERVO_MAX_Y:
        servo_get_goal(&v);
        v.y = deg2rad(180);
        servo_move(&v);
        break;
    case CMD_UPDATE_CENTER:
        vec2(&v, deg2rad(pd.single.center_x), deg2rad(pd.single.center_y));
        servo_move(&v);
        break;
    case CMD_UPDATE_GIGA_START:
        vec2(&v, deg2rad(pd.giga.start_x), deg2rad(pd.giga.start_y));
        servo_move(&v);
        break;
    case CMD_UPDATE_GIGA_END:
        vec2(&v, deg2rad(pd.giga.end_x), deg2rad(pd.giga.end_y));
        servo_move(&v);
        break;
    case CMD_SHUTDOWN:
        vec2(&v, deg2rad(180.0), deg2rad(180.0));
        servo_move(&v);
        break;
    }

    return Q_HANDLED();
}
Esempio n. 17
0
static void show_msg(char *msg, int timeout)
{
    lcd_clear();
    lcd_write(0, 0, msg, 0);
    QActive_post((QActive *) &mmi_ao, SIG_MMI_SHOW_MSG, timeout);
}