work on finite state machine

master
polymurph 4 years ago
parent 4594792f77
commit 39634860b2

@ -1,15 +0,0 @@
#ifndef _HEATER_HPP_
#define _HEATER_HPP_
class Heater
{
public:
Heater();
private:
};
#endif // _HEATER_HPP_

@ -1 +0,0 @@
#include "heaterCtrl.hpp"

@ -1,21 +0,0 @@
#ifndef _HEATERCTRL_HPP_
#define _HEATERCTRL_HPP_
class HeaterController
{
public:
enum Event{
};
HeaterController();
private:
};
#endif // _HEATERCTRL_HPP_

@ -8,9 +8,15 @@
#include <pthread.h>
#include <cstdlib>
#include "oven.hpp"
int main(void)
{
Oven oven;
return 0;
}

@ -0,0 +1,46 @@
#include "oven.hpp"
#include <iostream>
Oven::Oven()
{
turnEverythingOff();
}
void Oven::setHeaterDutyCycle()
{
}
void Oven::turnOnHeater()
{
std::cout << "Oven::turnOnHeateri()" << std::endl;
}
void Oven::turnOffHeater()
{
std::cout << "Oven::turnOffHeater()" << std::endl;
}
float Oven::getTemperature_C()
{
return 0;
}
void Oven::turnOnAirCirculation()
{
std::cout << "Oven::turnOnAirCirculation()" << std::endl;
}
void Oven::turnOffAirCirculation()
{
std::cout << "Oven::turnOnffAirCirculation()" << std::endl;
}
void Oven::turnEverythingOff()
{
turnOffHeater();
turnOffAirCirculation();
}

@ -5,14 +5,19 @@ class Oven
{
public:
// has a sensor and has a heater
// has a sensor, air circulation and has a heater
Oven();
void setHeaterDutyCycle();
void turnOnHeater();
void turnOffHeater();
float getTemperature_C();
void turnOnAirCirculation();
void turnOffAirCirculation();
void turnEverythingOff();
private:
};

@ -0,0 +1,19 @@
#include "ovenCtrl.hpp"
OvenControll::OvenControll() :
entity(),
pState(OvenState::init(entity))
{
}
void OvenControll::process(Event e)
{
pState = pState->handle(entity, e);
}

@ -1,13 +1,26 @@
#ifndef _OVENCTRL_HPP_
#define _OVENCTRL_HPP_
#include "oven.hpp"
// forward declaration
class OvenState;
class OvenControll
{
public:
OvenControll();
enum Event {
evTurnEverythingOff,
evTurn
};
OvenControll();
void process(Event e);
private:
Oven entity;
OvenState* pState;
};

@ -0,0 +1,48 @@
#ifndef _OVENSTATE_HPP_
#define _OVENSTATE_HPP_
#include "oven.hpp"
#include "ovenCtrl.hpp"
class OvenState
{
public:
static OvenState* init(Oven& entity);
virtual handle(Oven& entity,
OvenController::Event e) = 0;
protected:
virtual void entryAction(Oven& Entity);
virtual void exitAction(Oven& Entity);
typedef void (Oven::State::*Action)(Oven& entity);
OvenState* changeState(Oven& entity,
Action pTransitAction,
OvenState* pNewState);
// transition Actions
void emptyAction() {};
};
class IdleState : public OvenState
{
public:
static IdleState* getInstatnce():
virtual OvenState* handle(Oven& entity,
OvenControll::Event e);
protected:
virtual void entryAction(Oven& entity);
virtual void exitAction(Oven& entity);
private:
IdleState() {};
static IdleState instance;
};
#endif // _OVENSTATE_HPP_
Loading…
Cancel
Save