mirror of
https://github.com/QuantumLeaps/qpcpp.git
synced 2025-01-28 06:02:56 +08:00
82 lines
3.0 KiB
C++
82 lines
3.0 KiB
C++
//****************************************************************************
|
|
// Product: Transition to History Example
|
|
// Last updated for version 5.3.0
|
|
// Last updated on 2014-04-03
|
|
//
|
|
// Q u a n t u m L e a P s
|
|
// ---------------------------
|
|
// innovating embedded systems
|
|
//
|
|
// Copyright (C) Quantum Leaps, www.state-machine.com.
|
|
//
|
|
// This program is open source software: you can redistribute it and/or
|
|
// modify it under the terms of the GNU General Public License as published
|
|
// by the Free Software Foundation, either version 3 of the License, or
|
|
// (at your option) any later version.
|
|
//
|
|
// Alternatively, this program may be distributed and modified under the
|
|
// terms of Quantum Leaps commercial licenses, which expressly supersede
|
|
// the GNU General Public License and are specifically designed for
|
|
// licensees interested in retaining the proprietary status of their code.
|
|
//
|
|
// This program is distributed in the hope that it will be useful,
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
// GNU General Public License for more details.
|
|
//
|
|
// You should have received a copy of the GNU General Public License
|
|
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
//
|
|
// Contact information:
|
|
// Web: www.state-machine.com
|
|
// Email: info@state-machine.com
|
|
//****************************************************************************
|
|
#include "qep_port.h"
|
|
#include "qassert.h"
|
|
#include "history.h"
|
|
|
|
#include <conio.h>
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
|
|
//............................................................................
|
|
int 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",
|
|
QP::QEP::getVersion());
|
|
|
|
// instantiate the ToastOven HSM and trigger the initial transition
|
|
the_oven->init();
|
|
|
|
for (;;) {
|
|
|
|
printf("\n");
|
|
uint8_t c = (uint8_t)_getch(); // read one character from the console
|
|
printf("%c: ", c);
|
|
|
|
QP::QEvt e;
|
|
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
|
|
the_oven->dispatch(&e);
|
|
}
|
|
return 0;
|
|
}
|
|
//............................................................................
|
|
extern "C" void Q_onAssert(char const Q_ROM * const file, int line) {
|
|
fprintf(stderr, "Assertion failed in %s, line %d", file, line);
|
|
_exit(-1);
|
|
}
|