/*--------------------------------------------------------------------------*/ void Q_onAssert(char const Q_ROM * const file, int line) { Video_clearRect(0, 24, 80, 25, VIDEO_BGND_RED); Video_printStrAt(0, 24, VIDEO_FGND_WHITE, "ASSERTION FAILED in file:"); Video_printStrAt(26, 24, VIDEO_FGND_YELLOW, file); Video_printStrAt(57, 24, VIDEO_FGND_WHITE, "line:"); Video_printNumAt(62, 24, VIDEO_FGND_YELLOW, line); QF_stop(); /* stop QF and cleanup */ }
/*..........................................................................*/ QState UI_help_handler(UI_help *me, QEvt const *e) { switch (e->sig) { case Q_ENTRY_SIG: { /* instantiate the state-local objects */ Video_printStrAt(2, 10, VIDEO_FGND_BLACK, "Screen 0: Help "); Video_clearRect( 0, 11, 35, 23, VIDEO_BGND_BLUE); Video_clearRect(35, 11, 80, 23, VIDEO_BGND_BLACK); Video_printStrAt(36, 12, VIDEO_FGND_LIGHT_GRAY, "Press DOWN-Arrow to scroll down"); Video_printStrAt(36, 13, VIDEO_FGND_LIGHT_GRAY, "Press UP-Arrow to scroll up"); Video_printStrAt(36, 20, VIDEO_FGND_WHITE, "Press F1 to return to last screen"); Video_clearRect(HELP_X - 1, HELP_Y, HELP_X + HELP_DX + 1, HELP_Y + HELP_DY, VIDEO_BGND_BLACK); Video_drawRect (HELP_X - 2, HELP_Y - 1, HELP_X + HELP_DX + 2, HELP_Y + HELP_DY + 1, VIDEO_FGND_WHITE,2); me->help_line = 0; printHelp(me->super.help_text + me->help_line); return Q_HANDLED(); } case Q_EXIT_SIG: { /* destroy the state-local objects... */ return Q_HANDLED(); } case DOWN_SIG: { if (me->help_line + HELP_DY < me->super.help_len) { ++me->help_line; } printHelp(me->super.help_text + me->help_line); return Q_HANDLED(); } case UP_SIG: { if (me->help_line > 0) { --me->help_line; } printHelp(me->super.help_text + me->help_line); return Q_HANDLED(); } case HELP_SIG: { return Q_TRAN(me->super.history); /* go back to the last screen */ } } return Q_SUPER(&UI_top_handler); }
/*..........................................................................*/ void BSP_init(void) { Video_clearScreen(VIDEO_BGND_LIGHT_GRAY); Video_clearRect( 0, 0, 80, 1, VIDEO_BGND_RED | VIDEO_BLINK); Video_clearRect( 0, 8, 80, 24, VIDEO_BGND_BLACK | VIDEO_FGND_WHITE); Video_clearRect( 0, 7, 80, 8, VIDEO_BGND_BLUE); Video_clearRect( 0, 24, 80, 25, VIDEO_BGND_BLUE); Video_clearRect(24, 24, 28, 25, VIDEO_BGND_RED | VIDEO_BLINK); Video_clearRect(24, 24, 28, 25, VIDEO_BGND_RED | VIDEO_BLINK); Video_printStrAt(30, 0, VIDEO_FGND_WHITE, "FLY 'n' SHOOT"); Video_printStrAt(15, 2, VIDEO_FGND_BLACK, "Press UP-arrow to move the space ship up"); Video_printStrAt(15, 3, VIDEO_FGND_BLACK, "Press DOWN-arrow to move the space ship down"); Video_printStrAt(15, 4, VIDEO_FGND_BLACK, "Press SPACE to fire the missile"); Video_printStrAt(15, 5, VIDEO_FGND_BLACK, "Press ESC to quit the game"); Video_printStrAt( 8, 24, VIDEO_FGND_WHITE, "Ship Position:"); Video_printStrAt(37, 24, VIDEO_FGND_WHITE, "Triggers:"); Video_printStrAt(61, 24, VIDEO_FGND_WHITE, "Score:"); Video_clearRect(24, 24, 28, 25, VIDEO_BGND_RED); Video_clearRect(47, 24, 51, 25, VIDEO_BGND_RED); Video_clearRect(68, 24, 72, 25, VIDEO_BGND_RED); Video_printNumAt(24, 24, VIDEO_FGND_YELLOW, 0); Video_printNumAt(47, 24, VIDEO_FGND_YELLOW, 0); Video_printNumAt(68, 24, VIDEO_FGND_YELLOW, 0); }
/*..........................................................................*/ void BSP_displyPhilStat(uint8_t n, char const *stat) { Video_printStrAt(17, 12 + n, VIDEO_FGND_YELLOW, stat); QS_BEGIN(PHILO_STAT, AO_Philo[n]) /* application-specific record begin */ QS_U8(1, n); /* Philosopher number */ QS_STR(stat); /* Philosopher status */ QS_END() }
/*..........................................................................*/ void NumEntry_insert(NumEntry *me, uint8_t keyId) { if (me->len == 0) { me->str[NUM_STR_WIDTH - 1] = (char)keyId; } else if (me->len < (NUM_STR_WIDTH - 1)) { memmove(&me->str[0], &me->str[1], NUM_STR_WIDTH - 1); me->str[NUM_STR_WIDTH - 1] = (char)keyId; } ++me->len; Video_printStrAt(me->x, me->y, me->color, me->str); }
/*..........................................................................*/ QState NumEntry_top(NumEntry *me, QEvt const *e) { switch (e->sig) { case C_SIG: { memset(me->str, ' ', NUM_STR_WIDTH - 1); me->str[NUM_STR_WIDTH - 1] = '0'; me->str[NUM_STR_WIDTH] = '\0'; me->len = 0; Video_printStrAt(me->x, me->y, me->color, me->str); return Q_TRAN(&NumEntry_zero); } } return Q_SUPER(&QHsm_top); }
/*..........................................................................*/ void BSP_init(int argc, char *argv[]) { char const *com = "COM1"; if (argc > 1) { com = argv[1]; } if (!QS_INIT(com)) { /* initialize QS */ Q_ERROR(); } QS_OBJ_DICTIONARY(&l_tmr); QS_OBJ_DICTIONARY(&l_kbd); Video_clearScreen(VIDEO_BGND_LIGHT_GRAY); Video_clearRect( 0, 0, 80, 1, VIDEO_BGND_RED | VIDEO_BLINK); Video_clearRect( 0, 8, 80, 24, VIDEO_BGND_BLACK | VIDEO_FGND_WHITE); Video_clearRect( 0, 7, 80, 8, VIDEO_BGND_BLUE); Video_clearRect( 0, 24, 80, 25, VIDEO_BGND_BLUE); Video_clearRect(24, 24, 28, 25, VIDEO_BGND_RED | VIDEO_BLINK); Video_clearRect(24, 24, 28, 25, VIDEO_BGND_RED | VIDEO_BLINK); Video_printStrAt(35, 0, VIDEO_FGND_WHITE, "FLY 'n' SHOOT"); Video_printStrAt(15, 2, VIDEO_FGND_BLACK, "Press UP-arrow to move the space ship up"); Video_printStrAt(15, 3, VIDEO_FGND_BLACK, "Press DOWN-arrow to move the space ship down"); Video_printStrAt(15, 4, VIDEO_FGND_BLACK, "Press SPACE to fire the missile"); Video_printStrAt(15, 5, VIDEO_FGND_BLACK, "Press ESC to quit the game"); Video_printStrAt( 8, 24, VIDEO_FGND_WHITE, "Ship Position:"); Video_printStrAt(37, 24, VIDEO_FGND_WHITE, "Triggers:"); Video_printStrAt(61, 24, VIDEO_FGND_WHITE, "Score:"); Video_clearRect(24, 24, 28, 25, VIDEO_BGND_RED); Video_clearRect(47, 24, 51, 25, VIDEO_BGND_RED); Video_clearRect(68, 24, 72, 25, VIDEO_BGND_RED); Video_printNumAt(24, 24, VIDEO_FGND_YELLOW, 0); Video_printNumAt(47, 24, VIDEO_FGND_YELLOW, 0); Video_printNumAt(68, 24, VIDEO_FGND_YELLOW, 0); (void)com; /* avoid compiler warning if QS is not used */ }
/*..........................................................................*/ void BSP_signalPeds(enum BSP_PedsSignal sig) { switch (sig) { case PEDS_DONT_WALK: Video_printStrAt(51, 8, VIDEO_FGND_RED, "DON\'T"); Video_printStrAt(51, 9, VIDEO_FGND_RED, "WALK"); break; case PEDS_BLANK: Video_printStrAt(51, 8, VIDEO_FGND_RED, " "); Video_printStrAt(51, 9, VIDEO_FGND_RED, " "); break; case PEDS_WALK: Video_printStrAt(51, 8, VIDEO_FGND_GREEN, "WALK "); Video_printStrAt(51, 9, VIDEO_FGND_GREEN, " "); break; } }
/*..........................................................................*/ QState NumEntry_zero(NumEntry *me, QEvt const *e) { switch (e->sig) { case DIGIT_0_SIG: { ; /* explicitly ignore */ return Q_HANDLED(); } case NEG_SIG: { me->str[NUM_STR_WIDTH - 2] = '-'; Video_printStrAt(me->x, me->y, me->color, me->str); return Q_TRAN(&NumEntry_negative); } case DIGIT_1_9_SIG: { NumEntry_insert(me, ((KeyboardEvt const *)e)->key_code); return Q_TRAN(&NumEntry_integer); } case POINT_SIG: { NumEntry_insert(me, ((KeyboardEvt const *)e)->key_code); return Q_TRAN(&NumEntry_fraction); } } return Q_SUPER(&NumEntry_top); }
/*..........................................................................*/ void BSP_init(int argc, char *argv[]) { uint8_t n; if (argc > 1) { l_delay = atol(argv[1]); /* set the delay counter for busy delay */ } Video_clearScreen(VIDEO_BGND_BLACK); Video_clearRect( 0, 0, 80, 7, VIDEO_BGND_LIGHT_GRAY); Video_clearRect( 0, 11, 80, 12, VIDEO_BGND_LIGHT_GRAY); Video_clearRect( 0, 12, 41, 23, VIDEO_BGND_BLUE); Video_clearRect(41, 12, 80, 23, VIDEO_BGND_RED); Video_clearRect( 0, 23, 80, 24, VIDEO_BGND_LIGHT_GRAY); n = VIDEO_FGND_BLUE; Video_printStrAt(10, 0, n, " __"); Video_printStrAt(10, 1, n, " / | _ _ -|- _ _"); Video_printStrAt(10, 2, n, " \\__| | | _\\ | \\ | | | | \\ \\"); Video_printStrAt(10, 3, n, " | \\_/ |_| | | | \\_| | | |"); Video_printStrAt(10, 4, n, " |"); n = VIDEO_FGND_RED; Video_printStrAt(43, 0, n, " _ __ "); Video_printStrAt(43, 1, n, "| /_\\ | \\ TM"); Video_printStrAt(43, 2, n, "| \\_ _ |__/ _"); Video_printStrAt(43, 3, n, "| _\\ | |_"); Video_printStrAt(43, 4, n, "|___ |_| | _|"); Video_printStrAt(10, 5, VIDEO_FGND_BLUE, "_____________________________________________________"); Video_printStrAt(10, 6, VIDEO_FGND_RED, "i n n o v a t i n g e m b e d d e d s y s t e m s"); Video_printStrAt(18, 7, VIDEO_FGND_WHITE, "Dining Philosophers Problem (DPP)"); Video_printStrAt(18, 8, VIDEO_FGND_WHITE, "QP-nano (QK) "); Video_printStrAt(32, 8, VIDEO_FGND_YELLOW, QP_getVersion()); Video_printStrAt(41, 10, VIDEO_FGND_WHITE, "Delay Counter"); Video_printNumAt(54, 10, VIDEO_FGND_YELLOW, l_delay); Video_printStrAt( 1, 11, VIDEO_FGND_BLUE, "Active Object State Preemptions"); Video_printStrAt(42, 11, VIDEO_FGND_RED, "ISR Calls Data Preemptions"); for (n = 0; n < N_PHILO; ++n) { Video_printStrAt( 1, 12 + n, VIDEO_FGND_WHITE, "Philosopher"); Video_printNumAt(12, 12 + n, VIDEO_FGND_WHITE, n); } Video_printStrAt( 1, 12 + N_PHILO, VIDEO_FGND_WHITE, "Table"); Video_printStrAt(17, 12 + N_PHILO, VIDEO_FGND_YELLOW, "serving"); Video_printStrAt( 1, 12 + N_PHILO + 1, VIDEO_FGND_WHITE, "KbdMgr"); Video_printStrAt(17, 12 + N_PHILO + 1, VIDEO_FGND_YELLOW, "active"); Video_printStrAt( 1, 12 + N_PHILO + 3, VIDEO_FGND_WHITE, "Locked Sched"); Video_printStrAt(42, 12 + 0, VIDEO_FGND_WHITE, "kbdISR"); Video_printStrAt(42, 12 + 1, VIDEO_FGND_WHITE, "tmrISR"); Video_printStrAt(10, 23, VIDEO_FGND_BLUE, "* Copyright (c) Quantum Leaps, LLC * www.quantum-leaps.com *"); Video_printStrAt(28, 24, VIDEO_FGND_LIGHT_RED, "<< Press Esc to quit >>"); }
/*..........................................................................*/ QState UI_num_sd_handler(UI_num_sd *me, QEvt const *e) { switch (e->sig) { case Q_ENTRY_SIG: { uint8_t c; static char const * const help_sd[] = { "Standard Deviation: ", "Find the mean value and the ", " root-mean-square (RMS) ", "deviation of n data samples ", "xi, where i = 1..n. ", "Mean value <x> is calculated", "as follows: ", "<x> = Sum(xi)/n; ", "Two RMS estimatators are ", "provided: ", "sig(n) = ", " sqrt(Sum(xi-<x>)**2 / n);", "sig(n-1) = ", "sqrt(Sum(xi-<x>)**2 / (n-1))" }; /* instantiate the state-local objects */ me->super.super.help_text = help_sd; me->super.super.help_len = Q_DIM(help_sd); me->n = 0.0; me->sum = 0.0; me->sum_sq = 0.0; Video_printStrAt(2, 10, VIDEO_FGND_BLACK, "Screen 1: Standard Deviation "); Video_clearRect( 0, 11, 35, 23, VIDEO_BGND_BLUE); Video_clearRect(35, 11, 80, 23, VIDEO_BGND_BLACK); c = VIDEO_FGND_LIGHT_GRAY; Video_printStrAt(36, 12, c, "Press '-' to enter a negative number"); Video_printStrAt(36, 13, c, "Press '0' .. '9' to enter a digit"); Video_printStrAt(36, 14, c, "Press '.' to enter the decimal point"); Video_printStrAt(36, 15, c, "Press <Enter> to enter the data sample"); Video_printStrAt(36, 16, c, "Press 'e' or 'E' to Cancel last entry"); Video_printStrAt(36, 17, c, "Press 'c' or 'C' to Cancel the data set"); c = VIDEO_FGND_WHITE; Video_printStrAt(36, 20, c, "Press UP-arrow for previous screen"); Video_printStrAt(36, 21, c, "Press DOWN-arrow for next screen"); Video_printStrAt(36, 22, c, "Press F1 for help"); Video_clearRect(NUM_ENTRY_X, NUM_ENTRY_Y, NUM_ENTRY_X + NUM_STR_WIDTH, NUM_ENTRY_Y + 1, VIDEO_BGND_BLACK); Video_drawRect(NUM_ENTRY_X - 1, NUM_ENTRY_Y - 1, NUM_ENTRY_X + NUM_STR_WIDTH + 1, NUM_ENTRY_Y + 2, VIDEO_FGND_WHITE, 2); NumEntry_config(&me->super.num_entry, NUM_ENTRY_X, NUM_ENTRY_Y, NUM_ENTRY_COLOR); QHsm_dispatch((QHsm *)&me->super.num_entry, &l_clear_evt); c = VIDEO_FGND_WHITE; /* labels */ Video_printStrAt(NUM_ENTRY_X - 1, NUM_ENTRY_Y + 4, c, "n ="); Video_printStrAt(NUM_ENTRY_X - 1, NUM_ENTRY_Y + 5, c, "<x> ="); Video_printStrAt(NUM_ENTRY_X - 1, NUM_ENTRY_Y + 6, c, "sig(n) ="); Video_printStrAt(NUM_ENTRY_X - 1, NUM_ENTRY_Y + 7, c, "sig(n-1) ="); c = VIDEO_FGND_YELLOW; /* values */ Video_printStrAt(NUM_ENTRY_X + 10, NUM_ENTRY_Y + 4, c, "0 "); Video_printStrAt(NUM_ENTRY_X + 10, NUM_ENTRY_Y + 5, c, "N/A "); Video_printStrAt(NUM_ENTRY_X + 10, NUM_ENTRY_Y + 6, c, "N/A "); Video_printStrAt(NUM_ENTRY_X + 10, NUM_ENTRY_Y + 7, c, "N/A "); return Q_HANDLED(); } case Q_EXIT_SIG: { /* destroy the state-local objects... */ /* noting to destroy */ return Q_HANDLED(); } case C_SIG: { return Q_TRAN(&UI_num_sd_handler); /* transition-to-self */ } case CE_SIG: { QHsm_dispatch((QHsm *)&me->super.num_entry, &l_clear_evt); return Q_HANDLED(); } case UP_SIG: { return Q_TRAN(&UI_num_lr_handler); /* Liner Regression screen */ } case DOWN_SIG: { return Q_TRAN(&UI_num_lr_handler); /* Liner Regression screen */ } case NEG_SIG: case DIGIT_0_SIG: case DIGIT_1_9_SIG: case POINT_SIG: { QHsm_dispatch((QHsm *)&me->super.num_entry, e); return Q_HANDLED(); } case ENTER_SIG: { double tmp = NumEntry_get(&me->super.num_entry); char buf[14]; me->n += 1.0; me->sum += tmp; me->sum_sq += tmp*tmp; sprintf(buf, "%-12.6g", me->n); Video_printStrAt(NUM_ENTRY_X + 10, NUM_ENTRY_Y + 4, VIDEO_FGND_YELLOW, buf); tmp = me->sum / me->n; /* <x> */ sprintf(buf, "%-12.6g", tmp); Video_printStrAt(NUM_ENTRY_X + 10, NUM_ENTRY_Y + 5, VIDEO_FGND_YELLOW, buf); tmp = me->sum_sq / me->n - tmp*tmp; if (tmp >= 0.0) { /* sigma(n) */ tmp = sqrt(tmp); sprintf(buf, "%-12.6g", tmp); Video_printStrAt(NUM_ENTRY_X + 10, NUM_ENTRY_Y + 6, VIDEO_FGND_YELLOW, buf); if (me->n > 1.0) { /* sigma(n-1) */ tmp *= sqrt(me->n/(me->n - 1.0)); sprintf(buf, "%-12.6g", tmp); Video_printStrAt(NUM_ENTRY_X + 10, NUM_ENTRY_Y + 7, VIDEO_FGND_YELLOW, buf); } } QHsm_dispatch((QHsm *)&me->super.num_entry, &l_clear_evt); return Q_HANDLED(); } } return Q_SUPER(&UI_num_handler); }
/*..........................................................................*/ void BSP_init(void) { uint8_t n; Video_clearScreen(VIDEO_BGND_BLACK); Video_clearRect( 0, 0, 80, 7, VIDEO_BGND_LIGHT_GRAY); Video_clearRect( 0, 11, 41, 12, VIDEO_BGND_LIGHT_GRAY); Video_clearRect( 0, 7, 41, 11, VIDEO_BGND_RED); Video_clearRect( 0, 12, 41, 23, VIDEO_BGND_BLUE); Video_clearRect( 0, 23, 80, 24, VIDEO_BGND_LIGHT_GRAY); n = VIDEO_FGND_BLUE; Video_printStrAt(10, 0, n, " __"); Video_printStrAt(10, 1, n, " / | _ _ -|- _ _"); Video_printStrAt(10, 2, n, " \\__| | | _\\ | \\ | | | | \\ \\"); Video_printStrAt(10, 3, n, " | \\_/ |_| | | | \\_| | | |"); Video_printStrAt(10, 4, n, " |"); n = VIDEO_FGND_RED; Video_printStrAt(43, 0, n, " _ __ "); Video_printStrAt(43, 1, n, "| /_\\ | \\ TM"); Video_printStrAt(43, 2, n, "| \\_ _ |__/ _"); Video_printStrAt(43, 3, n, "| _\\ | |_"); Video_printStrAt(43, 4, n, "|___ |_| | _|"); Video_printStrAt(10, 5, VIDEO_FGND_BLUE, "_____________________________________________________"); Video_printStrAt(10, 6, VIDEO_FGND_RED, "i n n o v a t i n g e m b e d d e d s y s t e m s"); Video_printStrAt(10, 8, VIDEO_FGND_WHITE, "PELICAN Crossing Example"); Video_printStrAt(10, 9, VIDEO_FGND_WHITE, "QP-nano"); Video_printStrAt(20, 9, VIDEO_FGND_YELLOW, QP_getVersion()); Video_printStrAt(4, 11, VIDEO_FGND_BLUE, "Active Object State"); Video_printStrAt(4, 13, VIDEO_FGND_WHITE, "PELICAN"); Video_printStrAt(4, 14, VIDEO_FGND_WHITE, "Pedestrian"); Video_printStrAt(4, 17, VIDEO_FGND_WHITE, "Tick #"); n = VIDEO_FGND_WHITE | VIDEO_BGND_BLACK; Video_printStrAt(43, 7, n, " �������Ŀ"); Video_printStrAt(43, 8, n, " � �"); Video_printStrAt(43, 9, n, " � �"); Video_printStrAt(43, 10, n, " ���������"); Video_printStrAt(43, 11, n, "��������������������������������"); Video_printStrAt(43, 12, n, " ^ ���������"); Video_printStrAt(43, 13, n, " | ���������"); Video_printStrAt(43, 14, n, " PEDS ��������� <- CARS ->"); Video_printStrAt(43, 15, n, " | ���������"); Video_printStrAt(43, 16, n, " v ���������"); Video_printStrAt(43, 17, n, "��������������������������������"); Video_printStrAt(43, 18, n, " �������������Ŀ"); Video_printStrAt(43, 19, n, " � �Ŀ �Ŀ �Ŀ �"); Video_printStrAt(43, 20, n, " � � � � � � � �"); Video_printStrAt(43, 21, n, " � ��� ��� ��� �"); Video_printStrAt(43, 22, n, " ���������������"); Video_printStrAt(4, 23, VIDEO_FGND_BLUE, "* Copyright (c) Quantum Leaps, LLC * www.quantum-leaps.com *"); Video_printStrAt(28, 24, VIDEO_FGND_LIGHT_RED, "<< Press Esc to quit >>"); }
/*..........................................................................*/ void BSP_showState(uint8_t prio, char const *state) { Video_printStrAt(20, 12 + prio, VIDEO_FGND_YELLOW, " "); Video_printStrAt(20, 12 + prio, VIDEO_FGND_YELLOW, state); }
/*..........................................................................*/ QState UI_top_handler(UI_top *me, QEvt const *e) { switch (e->sig) { case Q_ENTRY_SIG: { uint8_t c; static char const * const help_unknown[] = { "Unknown Screen Help: ", " ", " ", " ", " " }; me->help_text = help_unknown; me->help_len = Q_DIM(help_unknown); Video_clearScreen(VIDEO_BGND_BLACK); Video_clearRect( 0, 0, 80, 7, VIDEO_BGND_LIGHT_GRAY); Video_clearRect( 0, 10, 80, 11, VIDEO_BGND_LIGHT_GRAY); Video_clearRect( 0, 23, 80, 24, VIDEO_BGND_LIGHT_GRAY); c = VIDEO_FGND_BLUE; Video_printStrAt(10, 0, c, " __"); Video_printStrAt(10, 1, c, " / | _ _ -|- _ _"); Video_printStrAt(10, 2, c, " \\__| | | _\\ | \\ | | | | \\ \\"); Video_printStrAt(10, 3, c, " | \\_/ |_| | | | \\_| | | |"); Video_printStrAt(10, 4, c, " |"); c = VIDEO_FGND_RED; Video_printStrAt(43, 0, c, " _ __ "); Video_printStrAt(43, 1, c, "| /_\\ | \\ TM"); Video_printStrAt(43, 2, c, "| \\_ _ |__/ _"); Video_printStrAt(43, 3, c, "| _\\ | |_"); Video_printStrAt(43, 4, c, "|___ |_| | _|"); Video_printStrAt(10, 5, VIDEO_FGND_BLUE, "_____________________________________________________"); Video_printStrAt(10, 6, VIDEO_FGND_RED, "i n n o v a t i n g e m b e d d e d s y s t e m s"); Video_printStrAt(2, 8, VIDEO_FGND_WHITE, "State-Local Storage Example"); Video_printStrAt(36, 8, VIDEO_FGND_WHITE, "QEP/C"); Video_printStrAt(45, 8, VIDEO_FGND_YELLOW, QEP_getVersion()); Video_printStrAt(55, 8, VIDEO_FGND_WHITE, "QF/C"); Video_printStrAt(64, 8, VIDEO_FGND_YELLOW, QF_getVersion()); Video_printStrAt(10, 23, VIDEO_FGND_BLUE, "* Copyright (c) Quantum Leaps, LLC * www.state-machine.com *"); Video_printStrAt(28, 24, VIDEO_FGND_LIGHT_RED, "<< Press Esc to quit >>"); return Q_HANDLED(); } case Q_EXIT_SIG: { Video_clearScreen(VIDEO_BGND_BLACK); /* clear the screen... */ return Q_HANDLED(); } case QUIT_SIG: { return Q_TRAN(&UI_top_final); } } return Q_SUPER(&QHsm_top); }
/*..........................................................................*/ QState UI_top_handler(UI_top *me) { switch (Q_SIG(me)) { case Q_ENTRY_SIG: { uint8_t c; Video_clearScreen(VIDEO_BGND_BLACK); Video_clearRect( 0, 0, 80, 7, VIDEO_BGND_LIGHT_GRAY); Video_clearRect( 0, 10, 80, 11, VIDEO_BGND_LIGHT_GRAY); Video_clearRect( 0, 23, 80, 24, VIDEO_BGND_LIGHT_GRAY); c = VIDEO_FGND_BLUE; Video_printStrAt(10, 0, c, " __"); Video_printStrAt(10, 1, c, " / | _ _ -|- _ _"); Video_printStrAt(10, 2, c, " \\__| | | _\\ | \\ | | | | \\ \\"); Video_printStrAt(10, 3, c, " | \\_/ |_| | | | \\_| | | |"); Video_printStrAt(10, 4, c, " |"); c = VIDEO_FGND_RED; Video_printStrAt(43, 0, c, " _ __ "); Video_printStrAt(43, 1, c, "| /_\\ | \\ TM"); Video_printStrAt(43, 2, c, "| \\_ _ |__/ _"); Video_printStrAt(43, 3, c, "| _\\ | |_"); Video_printStrAt(43, 4, c, "|___ |_| | _|"); Video_printStrAt(10, 5, VIDEO_FGND_BLUE, "_____________________________________________________"); Video_printStrAt(10, 6, VIDEO_FGND_RED, "i n n o v a t i n g e m b e d d e d s y s t e m s"); Video_printStrAt(2, 8, VIDEO_FGND_WHITE, "State-Local Storage Example"); Video_printStrAt(36, 8, VIDEO_FGND_WHITE, "QP-nano"); Video_printStrAt(45, 8, VIDEO_FGND_YELLOW, QP_getVersion()); Video_printStrAt(10, 23, VIDEO_FGND_BLUE, "* Copyright (c) Quantum Leaps, LLC * www.quantum-leaps.com *"); Video_printStrAt(28, 24, VIDEO_FGND_LIGHT_RED, "<< Press Esc to quit >>"); return Q_HANDLED(); } case Q_EXIT_SIG: { Video_clearScreen(VIDEO_BGND_BLACK); /* clear the screen... */ return Q_HANDLED(); } case QUIT_SIG: { return Q_TRAN(&UI_top_final); } } return Q_SUPER(&QHsm_top); }
/*..........................................................................*/ void BSP_displyPhilStat(uint8_t n, char const *stat) { Video_printStrAt(17, 12 + n, VIDEO_FGND_YELLOW, stat); }
/*..........................................................................*/ void BSP_init(int argc, char *argv[]) { char const *com = "COM1"; uint8_t n; if (argc > 1) { l_delay = atol(argv[1]); /* set the delay counter for busy delay */ } if (argc > 2) { com = argv[2]; (void)com; /* avoid compiler warning if Q_SPY not defined */ } if (!QS_INIT(com)) { /* initialize QS */ Q_ERROR(); } QS_OBJ_DICTIONARY(&l_tickHook); QS_OBJ_DICTIONARY(&l_kbdTask); Video_clearScreen(VIDEO_BGND_BLACK); Video_clearRect( 0, 0, 80, 7, VIDEO_BGND_LIGHT_GRAY); Video_clearRect( 0, 11, 80, 12, VIDEO_BGND_LIGHT_GRAY); Video_clearRect( 0, 12, 41, 23, VIDEO_BGND_BLUE); Video_clearRect(41, 12, 80, 23, VIDEO_BGND_RED); Video_clearRect( 0, 23, 80, 24, VIDEO_BGND_LIGHT_GRAY); n = VIDEO_FGND_BLUE; Video_printStrAt(10, 0, n, " __"); Video_printStrAt(10, 1, n, " / | _ _ -|- _ _"); Video_printStrAt(10, 2, n, " \\__| | | _\\ | \\ | | | | \\ \\"); Video_printStrAt(10, 3, n, " | \\_/ |_| | | | \\_| | | |"); Video_printStrAt(10, 4, n, " |"); n = VIDEO_FGND_RED; Video_printStrAt(43, 0, n, " _ __ "); Video_printStrAt(43, 1, n, "| /_\\ | \\ TM"); Video_printStrAt(43, 2, n, "| \\_ _ |__/ _"); Video_printStrAt(43, 3, n, "| _\\ | |_"); Video_printStrAt(43, 4, n, "|___ |_| | _|"); Video_printStrAt(10, 5, VIDEO_FGND_BLUE, "_____________________________________________________"); Video_printStrAt(10, 6, VIDEO_FGND_RED, "i n n o v a t i n g e m b e d d e d s y s t e m s"); Video_printStrAt(18, 7, VIDEO_FGND_WHITE, "Dining Philosophers Example"); Video_printStrAt(18, 8, VIDEO_FGND_WHITE, "QEP/C"); Video_printStrAt(28, 8, VIDEO_FGND_YELLOW, QEP_getVersion()); Video_printStrAt(18, 9, VIDEO_FGND_WHITE, "QF/C"); Video_printStrAt(28, 9, VIDEO_FGND_YELLOW, QF_getVersion()); Video_printStrAt(18, 10, VIDEO_FGND_WHITE, "uC/OS-II"); /* uC/OS-II version is returned as an integer value multiplied by 100 */ Video_printNumAt(29, 10, VIDEO_FGND_YELLOW, OSVersion()%100); Video_printStrAt(28, 10, VIDEO_FGND_YELLOW, "2."); Video_printStrAt( 1, 11, VIDEO_FGND_BLUE, "Active Object State Data"); for (n = 0; n < N_PHILO; ++n) { Video_printStrAt( 1, 12 + n, VIDEO_FGND_WHITE, "Philosopher"); Video_printNumAt(12, 12 + n, VIDEO_FGND_WHITE, n + 1); } Video_printStrAt( 1, 12 + N_PHILO, VIDEO_FGND_WHITE, "Table"); Video_printStrAt(17, 12 + N_PHILO, VIDEO_FGND_YELLOW, "serving"); Video_printStrAt( 1, 12 + N_PHILO + 1, VIDEO_FGND_WHITE, "ucosTask"); Video_printStrAt(17, 12 + N_PHILO + 1, VIDEO_FGND_YELLOW, "active"); Video_printStrAt(4, 23, VIDEO_FGND_BLUE, "* Copyright (c) Quantum Leaps, LLC * www.state-machine.com *"); Video_printStrAt(28, 24, VIDEO_FGND_LIGHT_RED, "<< Press Esc to quit >>"); }
/*..........................................................................*/ void BSP_signalCars(enum BSP_CarsSignal sig) { switch (sig) { case CARS_OFF: Video_printStrAt(62, 20, VIDEO_FGND_BLACK, "�"); Video_printStrAt(66, 20, VIDEO_FGND_BLACK, "�"); Video_printStrAt(70, 20, VIDEO_FGND_BLACK, "�"); break; case CARS_RED: Video_printStrAt(62, 20, VIDEO_FGND_RED, "�"); Video_printStrAt(66, 20, VIDEO_FGND_BLACK, "�"); Video_printStrAt(70, 20, VIDEO_FGND_BLACK, "�"); break; case CARS_YELLOW: Video_printStrAt(62, 20, VIDEO_FGND_BLACK, "�"); Video_printStrAt(66, 20, VIDEO_FGND_YELLOW,"�"); Video_printStrAt(70, 20, VIDEO_FGND_BLACK, "�"); break; case CARS_GREEN: Video_printStrAt(62, 20, VIDEO_FGND_BLACK, "�"); Video_printStrAt(66, 20, VIDEO_FGND_BLACK, "�"); Video_printStrAt(70, 20, VIDEO_FGND_GREEN, "�"); break; } }
/*..........................................................................*/ static void printHelp(char const * const *txt) { uint8_t y; for (y = 0; y < HELP_DY; ++y) { Video_printStrAt(HELP_X, HELP_Y + y, VIDEO_FGND_YELLOW, txt[y]); } }