コード例 #1
0
int main() {
    printf("History state pattern\nQP-nano version: %s\n"
           "Press 'o' to OPEN  the door\n"
           "Press 'c' to CLOSE the door\n"
           "Press 't' to start TOASTING\n"
           "Press 'b' to start BAKING\n"
           "Press 'f' to turn the oven OFF\n"
           "Press ESC to quit...\n",
           QP_getVersion());

    ToasterOven_ctor(&l_test);        /* instantiate the ToasterOven 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 'o':  Q_SIG(&l_test) = OPEN_SIG;      break;
            case 'c':  Q_SIG(&l_test) = CLOSE_SIG;     break;
            case 't':  Q_SIG(&l_test) = TOAST_SIG;     break;
            case 'b':  Q_SIG(&l_test) = BAKE_SIG;      break;
            case 'f':  Q_SIG(&l_test) = OFF_SIG;       break;
            case 0x1B: Q_SIG(&l_test) = TERMINATE_SIG; break;
        }
                               /* dispatch the event into the state machine */
        QHsm_dispatch((QHsm *)&l_test);
    }
    return 0;
}
コード例 #2
0
ファイル: history.c プロジェクト: christation/STM32491_CPLR
void main() {
    printf("History state pattern\nQEP version: %s\n"
           "Press 'o' to OPEN  the door\n"
           "Press 'c' to CLOSE the door\n"
           "Press 't' to start TOASTING\n"
           "Press 'b' to start BAKING\n"
           "Press 'f' to turn the oven OFF\n"
           "Press ESC to quit...\n",
           QEP_getVersion());

      /* instantiate the ToasterOven HSM and trigger the initial transition */
    ToasterOven_ctor(&l_test);
    QHsm_init((QHsm *)&l_test, (QEvt *)0);

    for (;;) {
        QEvt e;
        uint8_t c;

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

        switch (c) {
            case 'o':  e.sig = OPEN_SIG;        break;
            case 'c':  e.sig = CLOSE_SIG;       break;
            case 't':  e.sig = TOAST_SIG;       break;
            case 'b':  e.sig = BAKE_SIG;        break;
            case 'f':  e.sig = OFF_SIG;         break;
            case 0x1B: e.sig = TERMINATE_SIG;   break;
        }
                               /* dispatch the event into the state machine */
        QHsm_dispatch((QHsm *)&l_test,  &e);
    }
}