?? qbomb.c
字號:
/****************************************************************************** Product: Quantum Bomb Example* Version: Compatible with QEP/C 3.0.xx* Updated: Oct 21, 2005** Copyright (C) 2002-2005 Quantum Leaps, LLC. All rights reserved.** This example is part of the Quantum Leaps QP/C software, and may be* distributed and modified under the terms of the GNU General Public License* version 2 (GPL) as published by the Free Software Foundation and appearing* in the file GPL.TXT included in the packaging of this file. Please note* that GPL Section 2[b] requires that all works based on this software must* also be made publicly available under the terms of the GPL ("Copyleft").** Alternatively, this software may be distributed and modified in conjunction* with a valid QP/C Quantum Leaps commercial license. Quantum Leaps* commercial licenses are designed for users who want to retain proprietary* status of their code. The users who license this software under one of* Quantum Leaps commercial licenses do not use this software under the GPL* and therefore are not subject to any of its terms.** Contact information:* Quantum Leaps Web site: http://www.quantum-leaps.com* Quantum Leaps licensing: http://www.quantum-leaps.com/licensing* Quantum Leaps products: http://www.quantum-leaps.com/products* e-mail: sales@quantum-leaps.com*****************************************************************************/#include "qep_port.h"#include "qbomb.h"#include "qassert.h"Q_DEFINE_THIS_FILE/*--------------------------------------------------------------------------*/enum { MIN_TIMEOUT = 1, MAX_TIMEOUT = 99, INIT_TIMEOUT = 5};/*..........................................................................*/void QBomb_ctor(QBomb *me) { QFsm_ctor_(&me->super_, (QState)&QBomb_initial); /* superclass ctor */}/*..........................................................................*/void QBomb_initial(QBomb *me, QEvent const *e) { Q_REQUIRE(e != (QEvent const *)0); /* initialization event expected */ QBomb_updateState(me, "top-INIT"); me->timeout__ = INIT_TIMEOUT; me->defuse__ = ((QBombInitEvt const *)e)->defuse; Q_INIT(&QBomb_setting);}/*..........................................................................*/void QBomb_setting(QBomb *me, QEvent const *e) { switch (e->sig) { case Q_ENTRY_SIG: { QBomb_updateState(me, "setting-ENTRY"); break; } case Q_EXIT_SIG: { QBomb_updateState(me, "setting-EXIT"); break; } case UP_SIG: { if (me->timeout__ < MAX_TIMEOUT) { ++me->timeout__; } break; } case DOWN_SIG: { if (me->timeout__ > MIN_TIMEOUT) { --me->timeout__; } break; } case ARM_SIG: { Q_TRAN(&QBomb_timing); break; } }}/*..........................................................................*/void QBomb_timing(QBomb *me, QEvent const *e) { switch (e->sig) { case Q_ENTRY_SIG: { QBomb_updateState(me, "timing-ENTRY"); me->code__ = (uint8_t)0; /* invalidate the defuse code */ break; } case Q_EXIT_SIG: { QBomb_updateState(me, "timing-EXIT"); break; } case TICK_SIG: { if (me->timeout__ > (uint8_t)0) { --me->timeout__; } else { /* timeout expired */ Q_TRAN(&QBomb_blast); } break; } case UP_SIG: { me->code__ = (uint8_t)((me->code__ << 1) | 1); break; } case DOWN_SIG: { me->code__ <<= 1; break; } case ARM_SIG: { if (me->code__ == me->defuse__) { Q_TRAN(&QBomb_setting); } break; } }}/*..........................................................................*/void QBomb_blast(QBomb *me, QEvent const *e) { switch (e->sig) { case Q_ENTRY_SIG: { QBomb_updateState(me, "blast-ENTRY"); QBomb_exit(me); break; } }}/*..........................................................................*/uint8_t QBomb_getTimeout(QBomb *me) { return me->timeout__;}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -