diff --git a/02-UML/ST_BUTTON.uxf b/02-UML/ST_BUTTON.uxf
new file mode 100644
index 0000000..7dc6a10
--- /dev/null
+++ b/02-UML/ST_BUTTON.uxf
@@ -0,0 +1,179 @@
+
+
+ 14
+
+ UMLSpecialState
+
+ 546
+ 140
+ 28
+ 28
+
+ type=initial
+
+
+
+ UMLState
+
+ 210
+ 364
+ 196
+ 56
+
+ ST_PBPRESSED
+
+
+
+ UMLState
+
+ 714
+ 364
+ 196
+ 56
+
+ ST_PBRELEASED
+
+
+
+ Relation
+
+ 798
+ 406
+ 126
+ 168
+
+ lt=->
+evPBPoll
+ 10.0;10.0;10.0;100.0
+
+
+ Relation
+
+ 546
+ 154
+ 126
+ 126
+
+ lt=->
+evPBInit
+ 10.0;10.0;10.0;70.0
+
+
+ UMLSpecialState
+
+ 532
+ 252
+ 56
+ 56
+
+ type=decision
+
+
+
+ Relation
+
+ 294
+ 266
+ 266
+ 126
+
+ lt=->
+m1=[pB==1]
+ 170.0;10.0;10.0;10.0;10.0;70.0
+
+
+ Relation
+
+ 294
+ 406
+ 126
+ 126
+
+ lt=->
+evPBPoll
+ 10.0;10.0;10.0;70.0
+
+
+ Relation
+
+ 574
+ 266
+ 266
+ 126
+
+ lt=->
+m1=[pB==0]
+ 10.0;10.0;170.0;10.0;170.0;70.0
+
+
+ UMLSpecialState
+
+ 280
+ 504
+ 56
+ 56
+
+ type=decision
+
+
+
+ UMLSpecialState
+
+ 784
+ 546
+ 56
+ 56
+
+ type=decision
+
+
+
+ Relation
+
+ 350
+ 308
+ 462
+ 308
+
+ lt=->
+m1=[pB==1] / pbPress()
+ 310.0;190.0;260.0;190.0;40.0;10.0;10.0;10.0;10.0;40.0
+
+
+ Relation
+
+ 322
+ 308
+ 462
+ 266
+
+ lt=->
+
+m1=[pB==0] / pbRelease()
+ 10.0;160.0;60.0;160.0;280.0;10.0;310.0;10.0;310.0;40.0
+
+
+ Relation
+
+ 154
+ 308
+ 154
+ 266
+
+ lt=->
+m1=[else]
+ 90.0;160.0;10.0;160.0;10.0;10.0;70.0;10.0;70.0;40.0
+
+
+ Relation
+
+ 826
+ 308
+ 154
+ 308
+
+ lt=->
+m1=[else]
+ 10.0;190.0;90.0;190.0;90.0;10.0;30.0;10.0;30.0;40.0
+
+
diff --git a/03-software/ch/kb28/blinkerProject/app/factory/factory.c b/03-software/ch/kb28/blinkerProject/app/factory/factory.c
index 7330ef5..76a2065 100755
--- a/03-software/ch/kb28/blinkerProject/app/factory/factory.c
+++ b/03-software/ch/kb28/blinkerProject/app/factory/factory.c
@@ -86,9 +86,16 @@ void Factory_init() {
BUTTON_initHW(b3());
}
+void lON(){
+ LED_on(l9());
+}
+void lOFF() {
+ LED_off(l9());
+}
+
//connect objects if required
void Factory_build() {
-
+ BUTTON_setEventFunctions(b1(), &lON, &lOFF);
}
//start all state machines
diff --git a/03-software/ch/kb28/blinkerProject/app/factory/factory.h b/03-software/ch/kb28/blinkerProject/app/factory/factory.h
index 1021168..baed0e7 100755
--- a/03-software/ch/kb28/blinkerProject/app/factory/factory.h
+++ b/03-software/ch/kb28/blinkerProject/app/factory/factory.h
@@ -1,8 +1,8 @@
/* this is the Factory class */
-#ifndef FACTORY_ONCE
-#define FACTORY_ONCE
+#ifndef FACTORY_H
+#define FACTORY_H
#include
#include
diff --git a/03-software/ch/kb28/blinkerProject/app/main.c b/03-software/ch/kb28/blinkerProject/app/main.c
index 1a5b342..23b0e52 100644
--- a/03-software/ch/kb28/blinkerProject/app/main.c
+++ b/03-software/ch/kb28/blinkerProject/app/main.c
@@ -1,9 +1,7 @@
#include "../mcc_generated_files/mcc.h"
-#include "../board/led/led.h"
#include "../app/factory/factory.h"
#include "../xf/xf.h"
-#include "../board/button/button.h"
diff --git a/03-software/ch/kb28/blinkerProject/board/button/button.c b/03-software/ch/kb28/blinkerProject/board/button/button.c
index 7b960c8..0c08cde 100644
--- a/03-software/ch/kb28/blinkerProject/board/button/button.c
+++ b/03-software/ch/kb28/blinkerProject/board/button/button.c
@@ -8,7 +8,6 @@
#include "button.h"
#include "../../mcc_generated_files/pin_manager.h"
-#include "../led/led.h"
#include "../../app/factory/factory.h"
/**
@@ -82,31 +81,29 @@ bool BUTTON_processEvent(Event * ev) {
switch(me->state){
case ST_PBINIT:
if (evid == evPBInit) {
+ POST(me, &BUTTON_processEvent, evPBPoll, 0, 0);
if(BUTTON_isPressed(me)) {
me->state = ST_PBPRESSED;
} else {
me->state = ST_PBRELEASED;
}
- POST(me, &BUTTON_processEvent, evPBPoll, PB_POLL_TIME, 0);
}
break;
- case ST_PBPOLL:
- break;
case ST_PBRELEASED:
if(evid == evPBPoll) {
+ POST(me, &BUTTON_processEvent, evPBPoll, PB_POLL_TIME, 0);
if(BUTTON_isPressed(me)) {
me->state = ST_PBPRESSED;
}
- POST(me, &BUTTON_processEvent, evPBPoll, PB_POLL_TIME, 0);
}
break;
case ST_PBPRESSED:
if(evid == evPBPoll) {
+ POST(me, &BUTTON_processEvent, evPBPoll, PB_POLL_TIME, 0);
if(!BUTTON_isPressed(me)){
me->state = ST_PBRELEASED;
}
- POST(me, &BUTTON_processEvent, evPBPoll, PB_POLL_TIME, 0);
}
break;
@@ -116,16 +113,19 @@ bool BUTTON_processEvent(Event * ev) {
switch(me->state){
case ST_PBINIT:
break;
- case ST_PBPOLL:
- break;
case ST_PBRELEASED:
- LED_off(l10());
+ if(me->fButtonRelease != NULL) me->fButtonRelease();
break;
case ST_PBPRESSED:
- LED_on(l10());
+ if(me->fButtonPress != NULL) me->fButtonPress();
break;
}
processed = true;
}
return processed;
+}
+
+void BUTTON_setEventFunctions(BUTTON* me, void (*fPress)(void), void (*fRelease)(void)) {
+ me->fButtonPress = fPress;
+ me->fButtonRelease = fRelease;
}
\ No newline at end of file
diff --git a/03-software/ch/kb28/blinkerProject/board/button/button.h b/03-software/ch/kb28/blinkerProject/board/button/button.h
index 96bc106..0db6698 100644
--- a/03-software/ch/kb28/blinkerProject/board/button/button.h
+++ b/03-software/ch/kb28/blinkerProject/board/button/button.h
@@ -6,7 +6,7 @@
*
*/
#ifndef BUTTON_H
-#define BUTTON_H
+#define BUTTON_H
#include
#include
@@ -14,13 +14,14 @@
#define PB_POLL_TIME 20
-typedef enum {ST_PBINIT, ST_PBWAIT, ST_PBPOLL, ST_PBRELEASED, ST_PBPRESSED} BUTTON_STATES;
+typedef enum {ST_PBINIT, ST_PBRELEASED, ST_PBPRESSED} BUTTON_STATES;
typedef enum {evPBInit=100, evPBPoll} BUTTON_EVENTS;
typedef struct {
uint8_t id;
BUTTON_STATES state;
-
+ void (*fButtonPress)(void);
+ void (*fButtonRelease)(void);
} BUTTON;
void BUTTON_init(BUTTON* me, uint8_t id);
@@ -28,5 +29,6 @@ void BUTTON_initHW(BUTTON* me);
bool BUTTON_isPressed(BUTTON* me);
void BUTTON_startBehaviour(BUTTON* me);
bool BUTTON_processEvent(Event* ev);
+void BUTTON_setEventFunctions(BUTTON* me, void (*fPress)(void), void (*fRelease)(void));
#endif /* BUTTON_H */
\ No newline at end of file
diff --git a/03-software/ch/kb28/blinkerProject/board/led/led.h b/03-software/ch/kb28/blinkerProject/board/led/led.h
index 63f3e3f..e05b2b7 100644
--- a/03-software/ch/kb28/blinkerProject/board/led/led.h
+++ b/03-software/ch/kb28/blinkerProject/board/led/led.h
@@ -6,7 +6,7 @@
*/
#ifndef LED_H
-#define LED_H
+#define LED_H
#include