Пример #1
0
// @(/3/0/2/3) ...............................................................
QP::QState Philo::eating(Philo * const me, QP::QEvt const * const e) {
    QP::QState status_;
    switch (e->sig) {
        // @(/3/0/2/3)
        case Q_ENTRY_SIG: {
            me->m_timeEvt.armX(think_time());
            status_ = Q_HANDLED();
            break;
        }
        // @(/3/0/2/3)
        case Q_EXIT_SIG: {
            QP::QF::PUBLISH(Q_NEW(TableEvt, DONE_SIG, PHILO_ID(me)), me);
            (void)me->m_timeEvt.disarm();
            status_ = Q_HANDLED();
            break;
        }
        // @(/3/0/2/3/0)
        case TIMEOUT_SIG: {
            status_ = Q_TRAN(&Philo::thinking);
            break;
        }
        // @(/3/0/2/3/1)
        case EAT_SIG: // intentionally fall through
        case DONE_SIG: {
            /* EAT or DONE must be for other Philos than this one */
            Q_ASSERT(Q_EVT_CAST(TableEvt)->philoNum != PHILO_ID(me));
            status_ = Q_HANDLED();
            break;
        }
        default: {
            status_ = Q_SUPER(&QHsm::top);
            break;
        }
    }
    return status_;
}
/*..........................................................................*/
QState AlarmMgr_playing(AlarmMgr *me, QEvt const *e) {
    switch (e->sig) {
        case Q_ENTRY_SIG: {
            QTimeEvt_postIn(&me->timer, (QActive *)me,
                            l_alarms[me->curr_alarm].note[me->curr_note].dur);
            TIM_PrescalerConfig(TIM3,
                           l_alarms[me->curr_alarm].note[me->curr_note].freq);
            TIM_CounterCmd(TIM3, TIM_START);                 /* start noise */
            return Q_HANDLED();
        }
        case Q_EXIT_SIG: {
            QTimeEvt_disarm(&me->timer);
            return Q_HANDLED();
        }
        case TIMEOUT_SIG: {
            ++me->curr_note;
            if (me->curr_note == l_alarms[me->curr_alarm].length) {
                me->curr_note = 0;                      /* start over again */
            }
            return Q_TRAN(&AlarmMgr_playing);         /* transition to self */
        }
    }
    return Q_SUPER(&AlarmMgr_on);
}
Пример #3
0
// @(/2/1/5/1/3) .............................................................
QP::QState Ship::flying(Ship * const me, QP::QEvt const * const e) {
    QP::QState status;
    switch (e->sig) {
        // @(/2/1/5/1/3)
        case Q_ENTRY_SIG: {
            me->m_score = 0U; /* reset the score */
            ScoreEvt *sev = Q_NEW(ScoreEvt, SCORE_SIG);
            sev->score = me->m_score;
            AO_Tunnel->POST(sev, me);
            status = Q_HANDLED();
            break;
        }
        // @(/2/1/5/1/3/0)
        case TIME_TICK_SIG: {
            // tell the Tunnel to draw the Ship and test for hits
            ObjectImageEvt *oie = Q_NEW(ObjectImageEvt, SHIP_IMG_SIG);
            oie->x   = me->m_x;
            oie->y   = me->m_y;
            oie->bmp = SHIP_BMP;
            AO_Tunnel->POST(oie, me);

            ++me->m_score; // increment the score for surviving another tick

            if ((me->m_score % 10U) == 0U) { // is the score "round"?
                ScoreEvt *sev = Q_NEW(ScoreEvt, SCORE_SIG);
                sev->score = me->m_score;
                AO_Tunnel->POST(sev, me);
            }
            status = Q_HANDLED();
            break;
        }
        // @(/2/1/5/1/3/1)
        case PLAYER_TRIGGER_SIG: {
            ObjectPosEvt *ope = Q_NEW(ObjectPosEvt, MISSILE_FIRE_SIG);
            ope->x = me->m_x;
            ope->y = me->m_y + SHIP_HEIGHT - 1U;
            AO_Missile->POST(ope, me);
            status = Q_HANDLED();
            break;
        }
        // @(/2/1/5/1/3/2)
        case DESTROYED_MINE_SIG: {
            me->m_score += Q_EVT_CAST(ScoreEvt)->score;
            // the score will be sent to the Tunnel by the next TIME_TICK
            status = Q_HANDLED();
            break;
        }
        // @(/2/1/5/1/3/3)
        case HIT_WALL_SIG: {
            status = Q_TRAN(&Ship::exploding);
            break;
        }
        // @(/2/1/5/1/3/4)
        case HIT_MINE_SIG: {
            status = Q_TRAN(&Ship::exploding);
            break;
        }
        default: {
            status = Q_SUPER(&Ship::active);
            break;
        }
    }
    return status;
}
Пример #4
0
/* HSM definition ----------------------------------------------------------*/
QState Sensor_initial(Sensor *me) {
    me->pollCtr = 0;
    me->procCtr = 0;
    return Q_TRAN(&Sensor_polling);
}
Пример #5
0
/* HSM definition ----------------------------------------------------------*/
QState Ped_initial(Ped *me) {
    return Q_TRAN(&Ped_wait);
}
Пример #6
0
// $(AOs::Usbtask::Statechart) ...............................................
// @(/2/3/2/0)
QState Usbtask::initial(Usbtask *me, QEvent const *e) {
    me->usb_tick.postIn(me, USB_TICK_TIME);
    return Q_TRAN(&Usbtask::usb_task);
}
Пример #7
0
Файл: ui.c Проект: russells/hc2
static QState uiShowMin(struct UI *me)
{
	QTimeEvtCtr timeout = showmaxmintimeout;
	int16_t ti;

	switch (Q_SIG(me)) {
	case Q_ENTRY_SIG:
		me->showmaxmincounter ++;
		switch (me->showmaxmincounter) {
		case 1:
			lcd_showstring("MIN T  ");
			timeout = showmaxmintimeout;
			break;
		case 2:
			lcd_showstring("SINCE  ");
			timeout = showmaxmintimeout;
			break;
		case 3:
			lcd_showstring("9 AM   ");
			timeout = showmaxmintimeout;
			break;
		case 4:
			ti = get_min_today()->ti;
			if (INVALIDTI == ti)
				me->showmaxmincounter ++;
			show_temperature(ti);
			timeout = 3 * showmaxmintimeout;
			break;
		case 5:
			show_at(&(get_min_today()->time));
			timeout = 3 * showmaxmintimeout;
			break;
		case 6:
			lcd_showstring("MIN T  ");
			timeout = showmaxmintimeout;
			break;
		case 7:
			lcd_showstring("TO LAST");
			timeout = showmaxmintimeout;
			break;
		case 8:
			lcd_showstring("9 AM   ");
			timeout = showmaxmintimeout;
			break;
		case 9:
			ti = get_min_yesterday()->ti;
			if (INVALIDTI == ti)
				me->showmaxmincounter ++;
			show_temperature(ti);
			timeout = 3 * showmaxmintimeout;
			break;
		case 10:
			show_at(&(get_min_yesterday()->time));
			timeout = 3 * showmaxmintimeout;
			break;
		default:
			Q_ASSERT( 0 );
			break;
		}
		QActive_armX(&me->super, 1, timeout);
		return Q_HANDLED();
	case Q_TIMEOUT1_SIG:
	case BUTTON_DOWN_PRESS_SIGNAL:
		if (10 == me->showmaxmincounter)
			return Q_TRAN(uiRun);
		else
			return Q_TRAN(uiShowMin);
	}
	return Q_SUPER(uiShowMinTop);
}
Пример #8
0
/* HSM definition ----------------------------------------------------------*/
QState QHsmTst_initial(QHsmTst *me, QEvt const *e) {
    (void)e;                      /* suppress "e not used" compiler warning */
    BSP_display("top-INIT;");
    me->foo = 0;                      /* initialize extended state variable */
    return Q_TRAN(&QHsmTst_s2);
}
//--------------------------------------------------------------------------------------------------------------
QState Temperature::initial(Temperature *me, QEvent const *) {

	me->initMotorTemperature();
    return Q_TRAN(&Temperature::run);
}
Пример #10
0
/*..........................................................................*/
QState Mine2_planted(Mine2 *me, QEvt const *e) {
    uint8_t x;
    uint8_t y;
    uint8_t bmp;

    switch (e->sig) {
        case TIME_TICK_SIG: {
            if (me->x >= GAME_SPEED_X) {
                ObjectImageEvt *oie;

                me->x -= GAME_SPEED_X;              /* move the mine 1 step */

                /* tell the Tunnel to draw the Mine */
                oie = Q_NEW(ObjectImageEvt, MINE_IMG_SIG);
                oie->x   = me->x;
                oie->y   = me->y;
                oie->bmp = MINE2_BMP;
                QACTIVE_POST(AO_Tunnel, (QEvt *)oie, me);
            }
            else {
                return Q_TRAN(&Mine2_unused);
            }
            return Q_HANDLED();
        }
        case SHIP_IMG_SIG: {
            x   = (uint8_t)((ObjectImageEvt const *)e)->x;
            y   = (uint8_t)((ObjectImageEvt const *)e)->y;
            bmp = (uint8_t)((ObjectImageEvt const *)e)->bmp;

            /* test for incoming Ship hitting this mine */
            if (do_bitmaps_overlap(MINE2_BMP, me->x, me->y, bmp, x, y)) {
                static MineEvt const mine2_hit = {
                    { HIT_MINE_SIG, 0, 0 },     /* the QEvt base instance */
                    2               /* type of the mine (2 for type-2 mine) */
                };
                QACTIVE_POST(AO_Ship, (QEvt *)&mine2_hit, me);

                /* go straight to 'disabled' and let the Ship do
                * the exploding
                */
                return Q_TRAN(&Mine2_unused);
            }
            return Q_HANDLED();
        }
        case MISSILE_IMG_SIG: {
            x   = (uint8_t)((ObjectImageEvt const *)e)->x;
            y   = (uint8_t)((ObjectImageEvt const *)e)->y;
            bmp = (uint8_t)((ObjectImageEvt const *)e)->bmp;

            /* test for incoming Missile hitting this mine */
            /* NOTE: Mine type-2 is nastier than Mine type-1.
            * The type-2 mine can hit the Ship with any of its
            * "tentacles". However, it can be destroyed by the
            * Missile only by hitting its center, defined as
            * a smaller bitmap MINE2_MISSILE_BMP.
            */
            if (do_bitmaps_overlap(MINE2_MISSILE_BMP,
                                   me->x, me->y, bmp, x, y))
            {
               static ScoreEvt const mine2_destroyed = {
                    { DESTROYED_MINE_SIG, 0, 0 },/*the QEvt base instance */
                    45                  /* score for destroying Mine type-2 */
                };
                QACTIVE_POST(AO_Missile, (QEvt *)&mine2_destroyed, me);
                return Q_TRAN(&Mine2_exploding);
            }
            return Q_HANDLED();
        }
    }
    return Q_SUPER(&Mine2_used);
}
/*..........................................................................*/
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);
}
Пример #12
0
QState PSConsole::Initial(PSConsole *me, QEvent const *e) 
{
    return Q_TRAN(&PSConsole::Inactive);
}
QP::QState Txr::flashing(Txr * const me, QP::QEvt const * const e) {
  static char ledCnt = 0;
  QP::QState status_;
  
  switch (e->sig) {
    case Q_ENTRY_SIG: 
    {
      ENC_RED_LED_OFF();
      ENC_GREEN_LED_TOGGLE();
      me->mFlashTimeout.postEvery(me, FLASH_RATE_TOUT);
      me->mCalibrationTimeout.postIn(me, FLASH_DURATION_TOUT);
      ledCnt = 0;
      /*if (FREESWITCH_ON()) {
          me->UpdatePosition(me); 
        } 
        else if (ZSWITCH_ON()) {
          me->UpdatePositionZMode(me); 
        }
        else {        
          me->UpdatePositionPlayBack(me); 
        }*/   
      status_ = Q_HANDLED();
      break;
    }
    case Q_EXIT_SIG: 
    {
      me->mFlashTimeout.disarm();
      ENC_RED_LED_ON();
      ENC_GREEN_LED_OFF();
      status_ = Q_HANDLED();
      break;
    }
    case CALIBRATION_SIG: 
    {
      // if they've pressed button 2 times calibration should be complete
      if (me->mEncPushes >= 2) {
        if (FREESWITCH_ON()) {
          status_ = Q_TRAN(&freeRun);
        } 
        else if (ZSWITCH_ON()) {
          status_ = Q_TRAN(&zmode);
        }
        else {        
          status_ = Q_TRAN(&playBack);
        }        
      }
      else {
        status_ = Q_TRAN(&uncalibrated);
      }
      break;
    }
    case FLASH_RATE_SIG: 
    {
      ENC_GREEN_LED_TOGGLE();
      status_ = Q_HANDLED();
      break;
    }
    case ENC_DOWN_SIG: 
    {
      // here to swallow the encoder press while flashing; else an exception occurs
      status_ = Q_HANDLED();
      break;
    }
    default: 
    {
      status_ = Q_SUPER(&uncalibrated);
      break;
    }
  }
  return status_;
}
QP::QState Txr::uncalibrated(Txr * const me, QP::QEvt const * const e) {
  QP::QState status_;
  switch (e->sig) {
    case Q_ENTRY_SIG: 
    {
      ENC_RED_LED_ON();
      ENC_GREEN_LED_OFF();
      me->mPacket.mode = FREE_MODE;
      me->mPrevEncoderCnt = BSP_GetEncoder();
      me->UpdateCalibrationMultiplier(BSP_GetMode());
      status_ = Q_HANDLED();
      break;
    }
    case Q_EXIT_SIG: 
    {
      status_ = Q_HANDLED();
      break;
    }
    case SEND_TIMEOUT_SIG: 
    {
      me->UpdatePositionCalibration(me);
      status_ = Q_HANDLED(); 
      break;
    }
    case ENC_DOWN_SIG: 
    {
      // if this is first time button press, just save the position
      if ((me->mEncPushes)++ == 0) {
        me->mCalibrationPos1 = me->mCurPos;
        settings.SetCalPos1(me->mCalibrationPos1);
      }
      // if this is second time, determine whether swapping is necessary
      // to map higher calibrated position with higher motor position
      else {
        me->mCalibrationPos2 = me->mCurPos;
        settings.SetCalPos2(me->mCalibrationPos2);
      }
      status_ = Q_TRAN(&flashing);
      break;
    }
    case PLAY_MODE_SIG: 
    {
      me->UpdateCalibrationMultiplier(PLAYBACK_MODE);
      status_ = Q_HANDLED(); 
      break;
    }
    case Z_MODE_SIG: 
    {
      me->UpdateCalibrationMultiplier(Z_MODE);
      status_ = Q_HANDLED(); 
      break;
    }
    case FREE_MODE_SIG: 
    {
      me->UpdateCalibrationMultiplier(FREE_MODE);
      status_ = Q_HANDLED(); 
      break;
    }
    default: 
    {
      status_ = Q_SUPER(&on);
      break;
    }
  }
  return status_;
}
Пример #15
0
/**
 * AlarmMenu state handler
 **/
static QState MenuAO_AlarmMenu(MenuAO *me, QEvent const *e)
{
    switch ( e->sig )
    {
    case Q_INIT_SIG:
    {
        return Q_HANDLED();
    }

    case Q_ENTRY_SIG:
    {
        // get current alarm
        RTC_GetAlarm(&rtcTime);
        sprintf(output, "3: Alarm %02d:%02d", rtcTime.RTC_Hour, rtcTime.RTC_Min);

        // display alarm menu (1st row of LCD)
        lcd_clear();
        set_cursor(0, 0);
        lcd_print((unsigned char*)output);

        return Q_HANDLED();
    }

    case BUTTON_SHORTPRESS_SIG:
    {
        // short press > proceed to next submenu
        if (!me->waitingForSetTime)
            // guard condition: only if not waiting for set time
            return Q_TRAN(&MenuAO_ClockMenu);
        else
            return Q_HANDLED();
    }

    case BUTTON_LONGPRESS_SIG:
    {
        if (me->waitingForSetTime != true)
        {
            // long press > send change time request and wait for response
            me->waitingForSetTime = true;

            // send ENTER_SET_TIME_SIG to SetTimeAO
            QActive_postFIFO(SetTimeAOBase, (QEvent*)&l_EnterSetTimeEvt);
        }

        return Q_HANDLED();
    }

    case TIME_SET_SIG:
    {
        TimeSetEvt* evt = (TimeSetEvt*)e;
        me->waitingForSetTime = false;

        // save and arm time at RTC
        RTC_AlarmDisable();
        RTC_SetAlarm(&evt->time);
        RTC_AlarmEnable();

        // display new alarm
        sprintf(output, "3: Alarm %02d:%02d", evt->time.RTC_Hour, evt->time.RTC_Min);

        lcd_clear();
        set_cursor(0, 0);
        lcd_print((unsigned char*)output);

        return Q_HANDLED();
    }

    case Q_EXIT_SIG:
    {
        return Q_HANDLED();
    }
    }

    return Q_SUPER(&MenuAO_Idle);
}
Пример #16
0
/* @(/1/0/1/0) */
static QState QHsmTst_initial(QHsmTst * const me) {
    me->foo = 0U;
    BSP_display("top-INIT;");
    return Q_TRAN(&QHsmTst_s2);
}
Пример #17
0
/*..........................................................................*/
QState Philo_initial(Philo *me) {
    return Q_TRAN(&Philo_thinking);
}
Пример #18
0
/*..........................................................................*/
QState Bomb4_initial(Bomb4 *me, QEvent const *e) {
    (void)e;
    me->timeout = INIT_TIMEOUT;
    return Q_TRAN(&Bomb4_setting);
}
Пример #19
0
Файл: ui.c Проект: russells/hc2
static QState uiInitial(struct UI *me)
{
	return Q_TRAN(scrollText);
}
Пример #20
0
/* HSM definition ----------------------------------------------------------*/
QState TServer_initial(TServer *me) {
    me->deferredRequest.sig = 0;                    /* no deferred requests */
    return Q_TRAN(&TServer_operational);
}
Пример #21
0
//............................................................................
QState QHsmTst::initial(QHsmTst *me, QEvt const *) {
    BSP_display("top-INIT;");
    me->m_foo = 0;                       // initialize extended state variable
    return Q_TRAN(&QHsmTst::s2);
}
/*${components::aoGrinder::SM} .............................................*/
static QState aoGrinder_initial(aoGrinder * const me) {
    /* ${components::aoGrinder::SM::initial} */
    TargetDose = 7;
    return Q_TRAN(&aoGrinder_idle);
}
Пример #23
0
/* @(/1/15/0/0) */
static QState QPrinter_initial(QPrinter * const me, QEvt const * const e) {
    return Q_TRAN(&QPrinter_state1);
}
Пример #24
0
/*..........................................................................*/
QState Oper_initial(Oper *me) {
    return Q_TRAN(&Oper_run);
}
Пример #25
0
// @(/1/0/3) .................................................................
// @(/1/0/3/0)
QP::QState Pelican::initial(Pelican * const me, QP::QEvt const * const e) {
    me->subscribe(PEDS_WAITING_SIG);
    return Q_TRAN(&Pelican::operational);
}
Пример #26
0
//............................................................................
QState Table::serving(Table *me, QEvt const *e) {
    uint8_t n, m;
    TableEvt *pe;

    switch (e->sig) {
        case Q_ENTRY_SIG: {
            displyTableStat("serving");
            for (n = 0; n < N_PHILO; ++n) {      // give permissions to eat...
                if (me->m_isHungry[n]
                    && (me->m_fork[LEFT(n)] == FREE)
                        && (me->m_fork[n] == FREE))
                {
                    me->m_fork[LEFT(n)] = me->m_fork[n] = USED;
                    pe = Q_NEW(TableEvt, EAT_SIG);
                    pe->philoNum = n;
                    QF::PUBLISH(pe, me);
                    me->m_isHungry[n] = 0;
                    displyPhilStat(n, "eating  ");
                }
            }
            return Q_HANDLED();
        }
        case HUNGRY_SIG: {
            n = ((TableEvt *)e)->philoNum;
            Q_ASSERT(n < N_PHILO && !me->m_isHungry[n]);
            displyPhilStat(n, "hungry  ");
            m = LEFT(n);
            if (me->m_fork[m] == FREE && me->m_fork[n] == FREE) {
                me->m_fork[m] = me->m_fork[n] = USED;
                pe = Q_NEW(TableEvt, EAT_SIG);
                pe->philoNum = n;
                QF::PUBLISH(pe, me);
                displyPhilStat(n, "eating  ");
            }
            else {
                me->m_isHungry[n] = 1;
            }
            return Q_HANDLED();
        }
        case DONE_SIG: {
            n = ((TableEvt *)e)->philoNum;
            Q_ASSERT(n < N_PHILO);
            displyPhilStat(n, "thinking");
            me->m_fork[LEFT(n)] = me->m_fork[n] = FREE;
            m = RIGHT(n);                          // check the right neighbor
            if (me->m_isHungry[m] && me->m_fork[m] == FREE) {
                me->m_fork[n] = me->m_fork[m] = USED;
                me->m_isHungry[m] = 0;
                pe = Q_NEW(TableEvt, EAT_SIG);
                pe->philoNum = m;
                QF::PUBLISH(pe, me);
                displyPhilStat(m, "eating  ");
            }
            m = LEFT(n);                            // check the left neighbor
            n = LEFT(m);
            if (me->m_isHungry[m] && me->m_fork[n] == FREE) {
                me->m_fork[m] = me->m_fork[n] = USED;
                me->m_isHungry[m] = 0;
                pe = Q_NEW(TableEvt, EAT_SIG);
                pe->philoNum = m;
                QF::PUBLISH(pe, me);
                displyPhilStat(m, "eating  ");
            }
            return Q_HANDLED();
        }
        case PAUSE_SIG:                             // "Toggle" button pressed
        case KEY_CENTER_PRESS_SIG: {                 // hardkey CENTER pressed
            return Q_TRAN(&Table::paused);
        }
    }
    return Q_SUPER(&Table::ready);
}
Пример #27
0
/*..........................................................................*/
QState Cruncher_initial(Cruncher * const me) {
    return Q_TRAN(&Cruncher_processing);
}
Пример #28
0
// $(AOs::Camera::Statechart) ................................................
// @(/2/1/4/0)
QState Camera::initial(Camera *me, QEvent const *e) {
    return Q_TRAN(&Camera::operation);
}
Пример #29
0
/* @(/1/16/0/0) */
static QState QIR_initial(QIR * const me, QEvt const * const e) {
    return Q_TRAN(&QIR_state1);
}
Пример #30
0
/* @(/1/0/1/1/4) ...........................................................*/
static QState QHsmTst_s1(QHsmTst * const me) {
    QState status_;
    switch (Q_SIG(me)) {
        /* @(/1/0/1/1/4) */
        case Q_ENTRY_SIG: {
            BSP_display("s1-ENTRY;");
            status_ = Q_HANDLED();
            break;
        }
        /* @(/1/0/1/1/4) */
        case Q_EXIT_SIG: {
            BSP_display("s1-EXIT;");
            status_ = Q_HANDLED();
            break;
        }
        /* @(/1/0/1/1/4/0) */
        case Q_INIT_SIG: {
            BSP_display("s1-INIT;");
            status_ = Q_TRAN(&QHsmTst_s11);
            break;
        }
        /* @(/1/0/1/1/4/1) */
        case I_SIG: {
            BSP_display("s1-I;");
            status_ = Q_HANDLED();
            break;
        }
        /* @(/1/0/1/1/4/2) */
        case D_SIG: {
            /* @(/1/0/1/1/4/2/0) */
            if (!me->foo) {
                me->foo = 1U;
                BSP_display("s1-D;");
                status_ = Q_TRAN(&QHsmTst_s);
            }
            else {
                status_ = Q_UNHANDLED();
            }
            break;
        }
        /* @(/1/0/1/1/4/3) */
        case A_SIG: {
            BSP_display("s1-A;");
            status_ = Q_TRAN(&QHsmTst_s1);
            break;
        }
        /* @(/1/0/1/1/4/4) */
        case B_SIG: {
            BSP_display("s1-B;");
            status_ = Q_TRAN(&QHsmTst_s11);
            break;
        }
        /* @(/1/0/1/1/4/5) */
        case F_SIG: {
            BSP_display("s1-F;");
            status_ = Q_TRAN(&QHsmTst_s211);
            break;
        }
        /* @(/1/0/1/1/4/6) */
        case C_SIG: {
            BSP_display("s1-C;");
            status_ = Q_TRAN(&QHsmTst_s2);
            break;
        }
        default: {
            status_ = Q_SUPER(&QHsmTst_s);
            break;
        }
    }
    return status_;
}