It is a lot of code to set up resources and manage the control flow. I'm also learning the Arduino IDE, so I'm not even sure which files it's linking to, but I copied a couple to this sketch from the Dining Philosophers QP example.
In any case this attempt just has two states, on and off, and sets up timer events to trigger the transitions. I did learn a bit about how periodic events are set up, and how the class is written to accept events and do state transitions, but it looks like I'm still in the dark about getting it initialized.
Quote
#include <qp_port.h>
#include "bsp.h"
#include <qf.h>
enum DPPSignals {
ON_SIG,
OFF_SIG
};
#define BLINK_PERIOD 100
#define ON_TIME 50
class Blinker :
public QP::QActive {
private:
uint8_t led_num; // led to blink
QP::QTimeEvt off_timeEvt;
QP::QTimeEvt on_timeEvt;
public:
Blinker()
:
QActive((QP::QStateHandler)&Blinker::initial),
off_timeEvt(OFF_SIG),
on_timeEvt(ON_SIG),
led_num(13) // constant for now
{
}
protected:
static QP::QState initial (Blinker *me, QP::QEvent const *e) {
me->subscribe(ON_SIG); // subscribe to HUNGRY
me->subscribe(OFF_SIG); // subscribe to DONE
me->off_timeEvt.postEvery( me, BLINK_PERIOD );
me->on_timeEvt.postEvery( me, BLINK_PERIOD );
me->off_timeEvt.rearm( ON_TIME ); // rephase by ON_TIME
return Q_TRAN(&Blinker::off);
};
static QP::QState on (Blinker *me, QP::QEvent const *e) {
switch (e->sig) {
case OFF_SIG:
return Q_TRAN( &Blinker::off );
default:
{
digitalWrite( 13, HIGH );
return Q_HANDLED();
}
}
};
static QP::QState off (Blinker *me, QP::QEvent const *e) {
switch (e->sig) {
case ON_SIG:
return Q_TRAN( &Blinker::on );
default:
{
digitalWrite( 13, LOW );
return Q_HANDLED();
}
}
};
};
static QP::QEvent const *l_blinkQueueSto[5]; // queue for blinker
static QP::QSubscrList l_subscrSto[10];
static QF_MPOOL_EL(QP::QEvt) l_smlPoolSto[5];//storage for small epool
// the one true blinker
static Blinker l_Blinker;
QP::QActive * const AO_Blinker = &l_Blinker;
void setup() {
pinMode(13, OUTPUT);
QP::QF::init(); // initialize the framework and the underlying RT kernel
BSP_init(); // initialize the BSP
// initialize event pools...
QP::QF::poolInit(l_smlPoolSto, sizeof(l_smlPoolSto), sizeof(l_smlPoolSto[0]));
QP::QF::psInit(l_subscrSto, Q_DIM(l_subscrSto)); // init publish-subscribe
// start the active objects...
AO_Blinker->start(1,
l_blinkQueueSto, Q_DIM(l_blinkQueueSto),
(void *)0, 0U);
}
#include "bsp.h"
#include <qf.h>
enum DPPSignals {
ON_SIG,
OFF_SIG
};
#define BLINK_PERIOD 100
#define ON_TIME 50
class Blinker :
public QP::QActive {
private:
uint8_t led_num; // led to blink
QP::QTimeEvt off_timeEvt;
QP::QTimeEvt on_timeEvt;
public:
Blinker()
:
QActive((QP::QStateHandler)&Blinker::initial),
off_timeEvt(OFF_SIG),
on_timeEvt(ON_SIG),
led_num(13) // constant for now
{
}
protected:
static QP::QState initial (Blinker *me, QP::QEvent const *e) {
me->subscribe(ON_SIG); // subscribe to HUNGRY
me->subscribe(OFF_SIG); // subscribe to DONE
me->off_timeEvt.postEvery( me, BLINK_PERIOD );
me->on_timeEvt.postEvery( me, BLINK_PERIOD );
me->off_timeEvt.rearm( ON_TIME ); // rephase by ON_TIME
return Q_TRAN(&Blinker::off);
};
static QP::QState on (Blinker *me, QP::QEvent const *e) {
switch (e->sig) {
case OFF_SIG:
return Q_TRAN( &Blinker::off );
default:
{
digitalWrite( 13, HIGH );
return Q_HANDLED();
}
}
};
static QP::QState off (Blinker *me, QP::QEvent const *e) {
switch (e->sig) {
case ON_SIG:
return Q_TRAN( &Blinker::on );
default:
{
digitalWrite( 13, LOW );
return Q_HANDLED();
}
}
};
};
static QP::QEvent const *l_blinkQueueSto[5]; // queue for blinker
static QP::QSubscrList l_subscrSto[10];
static QF_MPOOL_EL(QP::QEvt) l_smlPoolSto[5];//storage for small epool
// the one true blinker
static Blinker l_Blinker;
QP::QActive * const AO_Blinker = &l_Blinker;
void setup() {
pinMode(13, OUTPUT);
QP::QF::init(); // initialize the framework and the underlying RT kernel
BSP_init(); // initialize the BSP
// initialize event pools...
QP::QF::poolInit(l_smlPoolSto, sizeof(l_smlPoolSto), sizeof(l_smlPoolSto[0]));
QP::QF::psInit(l_subscrSto, Q_DIM(l_subscrSto)); // init publish-subscribe
// start the active objects...
AO_Blinker->start(1,
l_blinkQueueSto, Q_DIM(l_blinkQueueSto),
(void *)0, 0U);
}