add clickHandler
This commit is contained in:
parent
ffc2f67b53
commit
8cc4c9089f
@ -1,13 +1,13 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||||
<diagram program="umlet" version="15.1">
|
<diagram program="umlet" version="15.1">
|
||||||
<zoom_level>14</zoom_level>
|
<zoom_level>20</zoom_level>
|
||||||
<element>
|
<element>
|
||||||
<id>UMLSpecialState</id>
|
<id>UMLSpecialState</id>
|
||||||
<coordinates>
|
<coordinates>
|
||||||
<x>546</x>
|
<x>1160</x>
|
||||||
<y>140</y>
|
<y>200</y>
|
||||||
<w>28</w>
|
<w>40</w>
|
||||||
<h>28</h>
|
<h>40</h>
|
||||||
</coordinates>
|
</coordinates>
|
||||||
<panel_attributes>type=initial</panel_attributes>
|
<panel_attributes>type=initial</panel_attributes>
|
||||||
<additional_attributes/>
|
<additional_attributes/>
|
||||||
@ -15,10 +15,10 @@
|
|||||||
<element>
|
<element>
|
||||||
<id>UMLState</id>
|
<id>UMLState</id>
|
||||||
<coordinates>
|
<coordinates>
|
||||||
<x>210</x>
|
<x>680</x>
|
||||||
<y>364</y>
|
<y>520</y>
|
||||||
<w>196</w>
|
<w>280</w>
|
||||||
<h>56</h>
|
<h>80</h>
|
||||||
</coordinates>
|
</coordinates>
|
||||||
<panel_attributes>ST_PBPRESSED</panel_attributes>
|
<panel_attributes>ST_PBPRESSED</panel_attributes>
|
||||||
<additional_attributes/>
|
<additional_attributes/>
|
||||||
@ -26,10 +26,10 @@
|
|||||||
<element>
|
<element>
|
||||||
<id>UMLState</id>
|
<id>UMLState</id>
|
||||||
<coordinates>
|
<coordinates>
|
||||||
<x>714</x>
|
<x>1400</x>
|
||||||
<y>364</y>
|
<y>520</y>
|
||||||
<w>196</w>
|
<w>280</w>
|
||||||
<h>56</h>
|
<h>80</h>
|
||||||
</coordinates>
|
</coordinates>
|
||||||
<panel_attributes>ST_PBRELEASED</panel_attributes>
|
<panel_attributes>ST_PBRELEASED</panel_attributes>
|
||||||
<additional_attributes/>
|
<additional_attributes/>
|
||||||
@ -37,10 +37,10 @@
|
|||||||
<element>
|
<element>
|
||||||
<id>Relation</id>
|
<id>Relation</id>
|
||||||
<coordinates>
|
<coordinates>
|
||||||
<x>798</x>
|
<x>1520</x>
|
||||||
<y>406</y>
|
<y>580</y>
|
||||||
<w>126</w>
|
<w>180</w>
|
||||||
<h>168</h>
|
<h>240</h>
|
||||||
</coordinates>
|
</coordinates>
|
||||||
<panel_attributes>lt=->
|
<panel_attributes>lt=->
|
||||||
evPBPoll</panel_attributes>
|
evPBPoll</panel_attributes>
|
||||||
@ -49,10 +49,10 @@ evPBPoll</panel_attributes>
|
|||||||
<element>
|
<element>
|
||||||
<id>Relation</id>
|
<id>Relation</id>
|
||||||
<coordinates>
|
<coordinates>
|
||||||
<x>546</x>
|
<x>1160</x>
|
||||||
<y>154</y>
|
<y>220</y>
|
||||||
<w>126</w>
|
<w>180</w>
|
||||||
<h>126</h>
|
<h>180</h>
|
||||||
</coordinates>
|
</coordinates>
|
||||||
<panel_attributes>lt=->
|
<panel_attributes>lt=->
|
||||||
evPBInit</panel_attributes>
|
evPBInit</panel_attributes>
|
||||||
@ -61,10 +61,10 @@ evPBInit</panel_attributes>
|
|||||||
<element>
|
<element>
|
||||||
<id>UMLSpecialState</id>
|
<id>UMLSpecialState</id>
|
||||||
<coordinates>
|
<coordinates>
|
||||||
<x>532</x>
|
<x>1140</x>
|
||||||
<y>252</y>
|
<y>360</y>
|
||||||
<w>56</w>
|
<w>80</w>
|
||||||
<h>56</h>
|
<h>80</h>
|
||||||
</coordinates>
|
</coordinates>
|
||||||
<panel_attributes>type=decision</panel_attributes>
|
<panel_attributes>type=decision</panel_attributes>
|
||||||
<additional_attributes/>
|
<additional_attributes/>
|
||||||
@ -72,10 +72,10 @@ evPBInit</panel_attributes>
|
|||||||
<element>
|
<element>
|
||||||
<id>Relation</id>
|
<id>Relation</id>
|
||||||
<coordinates>
|
<coordinates>
|
||||||
<x>294</x>
|
<x>800</x>
|
||||||
<y>266</y>
|
<y>380</y>
|
||||||
<w>266</w>
|
<w>380</w>
|
||||||
<h>126</h>
|
<h>180</h>
|
||||||
</coordinates>
|
</coordinates>
|
||||||
<panel_attributes>lt=->
|
<panel_attributes>lt=->
|
||||||
m1=[pB==1]</panel_attributes>
|
m1=[pB==1]</panel_attributes>
|
||||||
@ -84,10 +84,10 @@ m1=[pB==1]</panel_attributes>
|
|||||||
<element>
|
<element>
|
||||||
<id>Relation</id>
|
<id>Relation</id>
|
||||||
<coordinates>
|
<coordinates>
|
||||||
<x>294</x>
|
<x>800</x>
|
||||||
<y>406</y>
|
<y>580</y>
|
||||||
<w>126</w>
|
<w>180</w>
|
||||||
<h>126</h>
|
<h>180</h>
|
||||||
</coordinates>
|
</coordinates>
|
||||||
<panel_attributes>lt=->
|
<panel_attributes>lt=->
|
||||||
evPBPoll</panel_attributes>
|
evPBPoll</panel_attributes>
|
||||||
@ -96,10 +96,10 @@ evPBPoll</panel_attributes>
|
|||||||
<element>
|
<element>
|
||||||
<id>Relation</id>
|
<id>Relation</id>
|
||||||
<coordinates>
|
<coordinates>
|
||||||
<x>574</x>
|
<x>1200</x>
|
||||||
<y>266</y>
|
<y>380</y>
|
||||||
<w>266</w>
|
<w>380</w>
|
||||||
<h>126</h>
|
<h>180</h>
|
||||||
</coordinates>
|
</coordinates>
|
||||||
<panel_attributes>lt=->
|
<panel_attributes>lt=->
|
||||||
m1=[pB==0]</panel_attributes>
|
m1=[pB==0]</panel_attributes>
|
||||||
@ -108,10 +108,10 @@ m1=[pB==0]</panel_attributes>
|
|||||||
<element>
|
<element>
|
||||||
<id>UMLSpecialState</id>
|
<id>UMLSpecialState</id>
|
||||||
<coordinates>
|
<coordinates>
|
||||||
<x>280</x>
|
<x>780</x>
|
||||||
<y>504</y>
|
<y>720</y>
|
||||||
<w>56</w>
|
<w>80</w>
|
||||||
<h>56</h>
|
<h>80</h>
|
||||||
</coordinates>
|
</coordinates>
|
||||||
<panel_attributes>type=decision</panel_attributes>
|
<panel_attributes>type=decision</panel_attributes>
|
||||||
<additional_attributes/>
|
<additional_attributes/>
|
||||||
@ -119,10 +119,10 @@ m1=[pB==0]</panel_attributes>
|
|||||||
<element>
|
<element>
|
||||||
<id>UMLSpecialState</id>
|
<id>UMLSpecialState</id>
|
||||||
<coordinates>
|
<coordinates>
|
||||||
<x>784</x>
|
<x>1500</x>
|
||||||
<y>546</y>
|
<y>780</y>
|
||||||
<w>56</w>
|
<w>80</w>
|
||||||
<h>56</h>
|
<h>80</h>
|
||||||
</coordinates>
|
</coordinates>
|
||||||
<panel_attributes>type=decision</panel_attributes>
|
<panel_attributes>type=decision</panel_attributes>
|
||||||
<additional_attributes/>
|
<additional_attributes/>
|
||||||
@ -130,10 +130,10 @@ m1=[pB==0]</panel_attributes>
|
|||||||
<element>
|
<element>
|
||||||
<id>Relation</id>
|
<id>Relation</id>
|
||||||
<coordinates>
|
<coordinates>
|
||||||
<x>350</x>
|
<x>880</x>
|
||||||
<y>308</y>
|
<y>440</y>
|
||||||
<w>462</w>
|
<w>660</w>
|
||||||
<h>308</h>
|
<h>440</h>
|
||||||
</coordinates>
|
</coordinates>
|
||||||
<panel_attributes>lt=->
|
<panel_attributes>lt=->
|
||||||
m1=[pB==1] / pbPress()</panel_attributes>
|
m1=[pB==1] / pbPress()</panel_attributes>
|
||||||
@ -142,10 +142,10 @@ m1=[pB==1] / pbPress()</panel_attributes>
|
|||||||
<element>
|
<element>
|
||||||
<id>Relation</id>
|
<id>Relation</id>
|
||||||
<coordinates>
|
<coordinates>
|
||||||
<x>322</x>
|
<x>840</x>
|
||||||
<y>308</y>
|
<y>440</y>
|
||||||
<w>462</w>
|
<w>660</w>
|
||||||
<h>266</h>
|
<h>380</h>
|
||||||
</coordinates>
|
</coordinates>
|
||||||
<panel_attributes>lt=->
|
<panel_attributes>lt=->
|
||||||
|
|
||||||
@ -155,10 +155,10 @@ m1=[pB==0] / pbRelease()</panel_attributes>
|
|||||||
<element>
|
<element>
|
||||||
<id>Relation</id>
|
<id>Relation</id>
|
||||||
<coordinates>
|
<coordinates>
|
||||||
<x>154</x>
|
<x>600</x>
|
||||||
<y>308</y>
|
<y>440</y>
|
||||||
<w>154</w>
|
<w>220</w>
|
||||||
<h>266</h>
|
<h>380</h>
|
||||||
</coordinates>
|
</coordinates>
|
||||||
<panel_attributes>lt=->
|
<panel_attributes>lt=->
|
||||||
m1=[else]</panel_attributes>
|
m1=[else]</panel_attributes>
|
||||||
@ -167,13 +167,25 @@ m1=[else]</panel_attributes>
|
|||||||
<element>
|
<element>
|
||||||
<id>Relation</id>
|
<id>Relation</id>
|
||||||
<coordinates>
|
<coordinates>
|
||||||
<x>826</x>
|
<x>1560</x>
|
||||||
<y>308</y>
|
<y>440</y>
|
||||||
<w>154</w>
|
<w>220</w>
|
||||||
<h>308</h>
|
<h>440</h>
|
||||||
</coordinates>
|
</coordinates>
|
||||||
<panel_attributes>lt=->
|
<panel_attributes>lt=->
|
||||||
m1=[else]</panel_attributes>
|
m1=[else]</panel_attributes>
|
||||||
<additional_attributes>10.0;190.0;90.0;190.0;90.0;10.0;30.0;10.0;30.0;40.0</additional_attributes>
|
<additional_attributes>10.0;190.0;90.0;190.0;90.0;10.0;30.0;10.0;30.0;40.0</additional_attributes>
|
||||||
</element>
|
</element>
|
||||||
|
<element>
|
||||||
|
<id>UMLNote</id>
|
||||||
|
<coordinates>
|
||||||
|
<x>1000</x>
|
||||||
|
<y>880</y>
|
||||||
|
<w>400</w>
|
||||||
|
<h>100</h>
|
||||||
|
</coordinates>
|
||||||
|
<panel_attributes>pbRelease() & pbPress()
|
||||||
|
are CallBack Functions</panel_attributes>
|
||||||
|
<additional_attributes/>
|
||||||
|
</element>
|
||||||
</diagram>
|
</diagram>
|
||||||
|
155
02-UML/ST_CLICK_HANDLER.uxf
Normal file
155
02-UML/ST_CLICK_HANDLER.uxf
Normal file
@ -0,0 +1,155 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||||
|
<diagram program="umlet" version="15.1">
|
||||||
|
<zoom_level>20</zoom_level>
|
||||||
|
<element>
|
||||||
|
<id>UMLSpecialState</id>
|
||||||
|
<coordinates>
|
||||||
|
<x>700</x>
|
||||||
|
<y>20</y>
|
||||||
|
<w>40</w>
|
||||||
|
<h>40</h>
|
||||||
|
</coordinates>
|
||||||
|
<panel_attributes>type=initial</panel_attributes>
|
||||||
|
<additional_attributes/>
|
||||||
|
</element>
|
||||||
|
<element>
|
||||||
|
<id>Relation</id>
|
||||||
|
<coordinates>
|
||||||
|
<x>700</x>
|
||||||
|
<y>40</y>
|
||||||
|
<w>180</w>
|
||||||
|
<h>180</h>
|
||||||
|
</coordinates>
|
||||||
|
<panel_attributes>lt=->
|
||||||
|
evCHInit</panel_attributes>
|
||||||
|
<additional_attributes>10.0;10.0;10.0;70.0</additional_attributes>
|
||||||
|
</element>
|
||||||
|
<element>
|
||||||
|
<id>UMLState</id>
|
||||||
|
<coordinates>
|
||||||
|
<x>580</x>
|
||||||
|
<y>180</y>
|
||||||
|
<w>280</w>
|
||||||
|
<h>80</h>
|
||||||
|
</coordinates>
|
||||||
|
<panel_attributes>ST_WAIT</panel_attributes>
|
||||||
|
<additional_attributes/>
|
||||||
|
</element>
|
||||||
|
<element>
|
||||||
|
<id>Relation</id>
|
||||||
|
<coordinates>
|
||||||
|
<x>700</x>
|
||||||
|
<y>240</y>
|
||||||
|
<w>200</w>
|
||||||
|
<h>180</h>
|
||||||
|
</coordinates>
|
||||||
|
<panel_attributes>lt=->
|
||||||
|
evPBPress</panel_attributes>
|
||||||
|
<additional_attributes>10.0;10.0;10.0;70.0</additional_attributes>
|
||||||
|
</element>
|
||||||
|
<element>
|
||||||
|
<id>Relation</id>
|
||||||
|
<coordinates>
|
||||||
|
<x>700</x>
|
||||||
|
<y>440</y>
|
||||||
|
<w>240</w>
|
||||||
|
<h>180</h>
|
||||||
|
</coordinates>
|
||||||
|
<panel_attributes>lt=->
|
||||||
|
evPBRelease</panel_attributes>
|
||||||
|
<additional_attributes>10.0;10.0;10.0;70.0</additional_attributes>
|
||||||
|
</element>
|
||||||
|
<element>
|
||||||
|
<id>UMLState</id>
|
||||||
|
<coordinates>
|
||||||
|
<x>540</x>
|
||||||
|
<y>380</y>
|
||||||
|
<w>360</w>
|
||||||
|
<h>80</h>
|
||||||
|
</coordinates>
|
||||||
|
<panel_attributes>ST_LONG_CLICK</panel_attributes>
|
||||||
|
<additional_attributes/>
|
||||||
|
</element>
|
||||||
|
<element>
|
||||||
|
<id>UMLState</id>
|
||||||
|
<coordinates>
|
||||||
|
<x>540</x>
|
||||||
|
<y>580</y>
|
||||||
|
<w>360</w>
|
||||||
|
<h>80</h>
|
||||||
|
</coordinates>
|
||||||
|
<panel_attributes>ST_SINGLE_CLICK</panel_attributes>
|
||||||
|
<additional_attributes/>
|
||||||
|
</element>
|
||||||
|
<element>
|
||||||
|
<id>UMLState</id>
|
||||||
|
<coordinates>
|
||||||
|
<x>540</x>
|
||||||
|
<y>780</y>
|
||||||
|
<w>360</w>
|
||||||
|
<h>80</h>
|
||||||
|
</coordinates>
|
||||||
|
<panel_attributes>ST_DOUBLE_CLICK</panel_attributes>
|
||||||
|
<additional_attributes/>
|
||||||
|
</element>
|
||||||
|
<element>
|
||||||
|
<id>Relation</id>
|
||||||
|
<coordinates>
|
||||||
|
<x>700</x>
|
||||||
|
<y>640</y>
|
||||||
|
<w>200</w>
|
||||||
|
<h>180</h>
|
||||||
|
</coordinates>
|
||||||
|
<panel_attributes>lt=->
|
||||||
|
evPBPress</panel_attributes>
|
||||||
|
<additional_attributes>10.0;10.0;10.0;70.0</additional_attributes>
|
||||||
|
</element>
|
||||||
|
<element>
|
||||||
|
<id>Relation</id>
|
||||||
|
<coordinates>
|
||||||
|
<x>840</x>
|
||||||
|
<y>200</y>
|
||||||
|
<w>560</w>
|
||||||
|
<h>280</h>
|
||||||
|
</coordinates>
|
||||||
|
<panel_attributes>lt=->
|
||||||
|
m1=evCHtimer / chLongClick()</panel_attributes>
|
||||||
|
<additional_attributes>30.0;110.0;260.0;110.0;260.0;10.0;10.0;10.0</additional_attributes>
|
||||||
|
</element>
|
||||||
|
<element>
|
||||||
|
<id>Relation</id>
|
||||||
|
<coordinates>
|
||||||
|
<x>840</x>
|
||||||
|
<y>200</y>
|
||||||
|
<w>560</w>
|
||||||
|
<h>480</h>
|
||||||
|
</coordinates>
|
||||||
|
<panel_attributes>lt=->
|
||||||
|
m1=evCHtimer / chSingleClick()</panel_attributes>
|
||||||
|
<additional_attributes>30.0;210.0;260.0;210.0;260.0;10.0;10.0;10.0</additional_attributes>
|
||||||
|
</element>
|
||||||
|
<element>
|
||||||
|
<id>Relation</id>
|
||||||
|
<coordinates>
|
||||||
|
<x>840</x>
|
||||||
|
<y>200</y>
|
||||||
|
<w>560</w>
|
||||||
|
<h>660</h>
|
||||||
|
</coordinates>
|
||||||
|
<panel_attributes>lt=->
|
||||||
|
m1=evCHtimer / chDoubleClick()</panel_attributes>
|
||||||
|
<additional_attributes>30.0;300.0;260.0;300.0;260.0;10.0;10.0;10.0</additional_attributes>
|
||||||
|
</element>
|
||||||
|
<element>
|
||||||
|
<id>Relation</id>
|
||||||
|
<coordinates>
|
||||||
|
<x>840</x>
|
||||||
|
<y>200</y>
|
||||||
|
<w>560</w>
|
||||||
|
<h>700</h>
|
||||||
|
</coordinates>
|
||||||
|
<panel_attributes>lt=->
|
||||||
|
m1=evPBRelease / chDoubleClick()</panel_attributes>
|
||||||
|
<additional_attributes>30.0;320.0;260.0;320.0;260.0;10.0;10.0;10.0</additional_attributes>
|
||||||
|
</element>
|
||||||
|
</diagram>
|
@ -47,6 +47,16 @@ BUTTON* b3() {
|
|||||||
return &theFactory.b3_;
|
return &theFactory.b3_;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
CLICK_HANDLER* ch1() {
|
||||||
|
return &theFactory.ch1_;
|
||||||
|
}
|
||||||
|
CLICK_HANDLER* ch2() {
|
||||||
|
return &theFactory.ch2_;
|
||||||
|
}
|
||||||
|
CLICK_HANDLER* ch3() {
|
||||||
|
return &theFactory.ch3_;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
LEDBlinker* lb() {
|
LEDBlinker* lb() {
|
||||||
return &theFactory.lb_;
|
return &theFactory.lb_;
|
||||||
@ -69,6 +79,10 @@ void Factory_init() {
|
|||||||
BUTTON_init(b2(), 2);
|
BUTTON_init(b2(), 2);
|
||||||
BUTTON_init(b3(), 3);
|
BUTTON_init(b3(), 3);
|
||||||
|
|
||||||
|
CLICK_HANDLER_init(ch1(), b1());
|
||||||
|
CLICK_HANDLER_init(ch2(), b2());
|
||||||
|
CLICK_HANDLER_init(ch3(), b3());
|
||||||
|
|
||||||
|
|
||||||
LED_initHW(l1());
|
LED_initHW(l1());
|
||||||
LED_initHW(l2());
|
LED_initHW(l2());
|
||||||
@ -86,30 +100,29 @@ void Factory_init() {
|
|||||||
BUTTON_initHW(b3());
|
BUTTON_initHW(b3());
|
||||||
}
|
}
|
||||||
|
|
||||||
//typedef void (*fButtonCallback)(void*);
|
|
||||||
buttonCallBack myFunction;
|
|
||||||
|
|
||||||
void lON(void * l){
|
|
||||||
LED* l_ = (LED*)l;
|
|
||||||
LED_on(l_);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void lOFF(void* l) {
|
|
||||||
LED* l_ = (LED*)l;
|
|
||||||
LED_off(l_);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
//connect objects if required
|
//connect objects if required
|
||||||
void Factory_build() {
|
void Factory_build() {
|
||||||
BUTTON_setEventFunctions(b1(), BUTTON_defineCallBack(&lON, l1()), BUTTON_defineCallBack(NULL, NULL));
|
//BUTTON_setEventFunctions(b1(), BUTTON_defineCallBack(&LED_on, l1()), BUTTON_defineCallBack(NULL, NULL));
|
||||||
BUTTON_setEventFunctions(b3(), BUTTON_defineCallBack(&lOFF, l1()), BUTTON_defineCallBack(NULL, NULL));
|
//BUTTON_setEventFunctions(b3(), BUTTON_defineCallBack(&LED_off, l1()), BUTTON_defineCallBack(NULL, NULL));
|
||||||
|
|
||||||
|
|
||||||
|
CLICK_HANDLER_setSingleClickCallback(ch1(), CLICK_HANDLER_defineCallBack(&LED_on, l1()));
|
||||||
|
CLICK_HANDLER_setSingleClickCallback(ch3(), CLICK_HANDLER_defineCallBack(&LED_on, l3()));
|
||||||
|
|
||||||
|
CLICK_HANDLER_setDoubleClickCallback(ch1(), CLICK_HANDLER_defineCallBack(&LED_off, l1()));
|
||||||
|
CLICK_HANDLER_setDoubleClickCallback(ch3(), CLICK_HANDLER_defineCallBack(&LED_off, l3()));
|
||||||
|
|
||||||
|
CLICK_HANDLER_setLongClickCallback(ch1(), CLICK_HANDLER_defineCallBack(&LED_on, l2()));
|
||||||
|
CLICK_HANDLER_setLongClickCallback(ch3(), CLICK_HANDLER_defineCallBack(&LED_off, l2()));
|
||||||
}
|
}
|
||||||
|
|
||||||
//start all state machines
|
//start all state machines
|
||||||
void Factory_start() {
|
void Factory_start() {
|
||||||
//LEDBlinker_startBehaviour(lb());
|
//LEDBlinker_startBehaviour(lb());
|
||||||
BUTTON_startBehaviour(b1());
|
BUTTON_startBehaviour(b1());
|
||||||
|
BUTTON_startBehaviour(b2());
|
||||||
BUTTON_startBehaviour(b3());
|
BUTTON_startBehaviour(b3());
|
||||||
|
CLICK_HANDLER_startBehaviour(ch1());
|
||||||
|
CLICK_HANDLER_startBehaviour(ch2());
|
||||||
|
CLICK_HANDLER_startBehaviour(ch3());
|
||||||
}
|
}
|
||||||
|
@ -10,8 +10,7 @@
|
|||||||
#include "../../board/led/led.h"
|
#include "../../board/led/led.h"
|
||||||
#include "../../board/button/button.h"
|
#include "../../board/button/button.h"
|
||||||
#include "../ledblinker.h"
|
#include "../ledblinker.h"
|
||||||
#define LID 1
|
#include "../../middleware/clickHandler.h"
|
||||||
|
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
LED l1_;
|
LED l1_;
|
||||||
@ -27,6 +26,9 @@ typedef struct {
|
|||||||
BUTTON b1_;
|
BUTTON b1_;
|
||||||
BUTTON b2_;
|
BUTTON b2_;
|
||||||
BUTTON b3_;
|
BUTTON b3_;
|
||||||
|
CLICK_HANDLER ch1_;
|
||||||
|
CLICK_HANDLER ch2_;
|
||||||
|
CLICK_HANDLER ch3_;
|
||||||
|
|
||||||
LEDBlinker lb_;
|
LEDBlinker lb_;
|
||||||
} Factory;
|
} Factory;
|
||||||
@ -52,6 +54,10 @@ BUTTON* b1();
|
|||||||
BUTTON* b2();
|
BUTTON* b2();
|
||||||
BUTTON* b3();
|
BUTTON* b3();
|
||||||
|
|
||||||
|
CLICK_HANDLER* ch1();
|
||||||
|
CLICK_HANDLER* ch2();
|
||||||
|
CLICK_HANDLER* ch3();
|
||||||
|
|
||||||
LEDBlinker* lb();
|
LEDBlinker* lb();
|
||||||
|
|
||||||
#endif
|
#endif
|
@ -1,8 +1,8 @@
|
|||||||
/**
|
/**
|
||||||
* @file button.c
|
* @file button.c
|
||||||
* @author Rémi Heredero (remi@heredero.ch)
|
* @author Rémi Heredero (remi@heredero.ch)
|
||||||
* @version 0.1
|
* @version 1
|
||||||
* @date 2023-06-06
|
* @date 2023-06-13
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
/**
|
/**
|
||||||
* @file button.h
|
* @file button.h
|
||||||
* @author Rémi Heredero (remi@heredero.ch)
|
* @author Rémi Heredero (remi@heredero.ch)
|
||||||
* @version 0.1
|
* @version 1
|
||||||
* @date 2023-06-06
|
* @date 2023-06-13
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
#ifndef BUTTON_H
|
#ifndef BUTTON_H
|
||||||
@ -30,13 +30,33 @@ typedef struct {
|
|||||||
buttonCallBack release;
|
buttonCallBack release;
|
||||||
} BUTTON;
|
} BUTTON;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Initialize the button
|
||||||
|
*
|
||||||
|
* @param me The object to initialize
|
||||||
|
* @param id The id of the button
|
||||||
|
*/
|
||||||
void BUTTON_init(BUTTON* me, uint8_t id);
|
void BUTTON_init(BUTTON* me, uint8_t id);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Initialize the hardware of the button
|
||||||
|
*
|
||||||
|
* @param me The object to initialize
|
||||||
|
*/
|
||||||
void BUTTON_initHW(BUTTON* me);
|
void BUTTON_initHW(BUTTON* me);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Check if the button is pressed
|
||||||
|
* The function returns true if the button is pressed, false otherwise
|
||||||
|
*
|
||||||
|
* @param me The object to check
|
||||||
|
* @return true if the button is pressed
|
||||||
|
* @return false if the button is not pressed
|
||||||
|
*/
|
||||||
|
void BUTTON_setEventFunctions(BUTTON* me, buttonCallBack fPress, buttonCallBack release);
|
||||||
bool BUTTON_isPressed(BUTTON* me);
|
bool BUTTON_isPressed(BUTTON* me);
|
||||||
void BUTTON_startBehaviour(BUTTON* me);
|
void BUTTON_startBehaviour(BUTTON* me);
|
||||||
bool BUTTON_processEvent(Event* ev);
|
bool BUTTON_processEvent(Event* ev);
|
||||||
void BUTTON_setEventFunctions(BUTTON* me, buttonCallBack fPress, buttonCallBack release);
|
|
||||||
buttonCallBack BUTTON_defineCallBack(fButtonCallback f, void* param);
|
buttonCallBack BUTTON_defineCallBack(fButtonCallback f, void* param);
|
||||||
|
|
||||||
#endif /* BUTTON_H */
|
#endif /* BUTTON_H */
|
@ -1,8 +1,7 @@
|
|||||||
#include "led.h"
|
#include "led.h"
|
||||||
#include "../../mcc_generated_files/pin_manager.h"
|
#include "../../mcc_generated_files/pin_manager.h"
|
||||||
|
|
||||||
void LED_init(LED* me, uint8_t id)
|
void LED_init(LED* me, uint8_t id) {
|
||||||
{
|
|
||||||
me->id = id;
|
me->id = id;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -10,15 +9,13 @@ void LED_init(LED* me, uint8_t id)
|
|||||||
* @brief Initialize the Driver
|
* @brief Initialize the Driver
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
void LED_initHW(LED* me)
|
void LED_initHW(LED* me) {
|
||||||
{
|
|
||||||
LED_off(me);
|
LED_off(me);
|
||||||
}
|
}
|
||||||
|
|
||||||
void LED_on(LED* me)
|
void LED_on(void* me) {
|
||||||
{
|
LED* l = (LED*) me;
|
||||||
switch (me->id)
|
switch (l->id) {
|
||||||
{
|
|
||||||
case 1:
|
case 1:
|
||||||
OUTPUT1_SetHigh();
|
OUTPUT1_SetHigh();
|
||||||
break;
|
break;
|
||||||
@ -53,10 +50,9 @@ void LED_on(LED* me)
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void LED_off(LED* me)
|
void LED_off(void* me) {
|
||||||
{
|
LED* l = (LED*) me;
|
||||||
switch (me->id)
|
switch (l->id) {
|
||||||
{
|
|
||||||
case 1:
|
case 1:
|
||||||
OUTPUT1_SetLow();
|
OUTPUT1_SetLow();
|
||||||
break;
|
break;
|
||||||
|
@ -19,8 +19,8 @@ typedef struct LED_ LED;
|
|||||||
|
|
||||||
void LED_init(LED* me, uint8_t id);
|
void LED_init(LED* me, uint8_t id);
|
||||||
void LED_initHW(LED* me);
|
void LED_initHW(LED* me);
|
||||||
void LED_on(LED* me);
|
void LED_on(void* me);
|
||||||
void LED_off(LED* me);
|
void LED_off(void* me);
|
||||||
|
|
||||||
#endif /* LED_H */
|
#endif /* LED_H */
|
||||||
|
|
||||||
|
152
03-software/ch/kb28/blinkerProject/middleware/clickHandler.c
Normal file
152
03-software/ch/kb28/blinkerProject/middleware/clickHandler.c
Normal file
@ -0,0 +1,152 @@
|
|||||||
|
/**
|
||||||
|
* @file clickHandler.c
|
||||||
|
* @author Rémi Heredero (remi@heredero.ch)
|
||||||
|
* @version 0.1
|
||||||
|
* @date 2023-06-13
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "clickHandler.h"
|
||||||
|
|
||||||
|
void CLICK_HANDLER_BUTTON_PRESS(CLICK_HANDLER* me){
|
||||||
|
POST(me, &CLICK_HANDLER_processEvent, evCHpbPress, 0, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
void CLICK_HANDLER_BUTTON_RELEASE(CLICK_HANDLER * me) {
|
||||||
|
POST(me, &CLICK_HANDLER_processEvent, evCHpbRelease, 0, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
void CLICK_HANDLER_init(CLICK_HANDLER* me, BUTTON* b){
|
||||||
|
me->button = b;
|
||||||
|
me->state = STCH_INIT;
|
||||||
|
me->longClick.fCallBack = NULL;
|
||||||
|
me->singleClick.fCallBack = NULL;
|
||||||
|
me->doubleClick.fCallBack = NULL;
|
||||||
|
|
||||||
|
buttonCallBack pbPressCallBack;
|
||||||
|
pbPressCallBack.fCallBack = CLICK_HANDLER_BUTTON_PRESS;
|
||||||
|
pbPressCallBack.param = me;
|
||||||
|
|
||||||
|
buttonCallBack pbReleaseCallBack;
|
||||||
|
pbReleaseCallBack.fCallBack = CLICK_HANDLER_BUTTON_RELEASE;
|
||||||
|
pbReleaseCallBack.param = me;
|
||||||
|
|
||||||
|
BUTTON_setEventFunctions(b, pbPressCallBack, pbReleaseCallBack);
|
||||||
|
}
|
||||||
|
|
||||||
|
void CLICK_HANDLER_startBehaviour(CLICK_HANDLER* me){
|
||||||
|
POST(me, &CLICK_HANDLER_processEvent, evCHinit, 0, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
clickHandlerCallBack CLICK_HANDLER_defineCallBack(fClickHandlerCallBack f, void* param) {
|
||||||
|
clickHandlerCallBack c;
|
||||||
|
c.fCallBack = f;
|
||||||
|
c.param = param;
|
||||||
|
return c;
|
||||||
|
}
|
||||||
|
|
||||||
|
void CLICK_HANDLER_setLongClickCallback(CLICK_HANDLER* me, clickHandlerCallBack callBack) {
|
||||||
|
me->longClick = callBack;
|
||||||
|
}
|
||||||
|
|
||||||
|
void CLICK_HANDLER_setSingleClickCallback(CLICK_HANDLER* me, clickHandlerCallBack callBack) {
|
||||||
|
me->singleClick = callBack;
|
||||||
|
}
|
||||||
|
|
||||||
|
void CLICK_HANDLER_setDoubleClickCallback(CLICK_HANDLER* me, clickHandlerCallBack callBack) {
|
||||||
|
me->doubleClick = callBack;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool CLICK_HANDLER_processEvent(Event* ev) {
|
||||||
|
bool processed = false;
|
||||||
|
CLICK_HANDLER* me = (CLICK_HANDLER*)Event_getTarget(ev);
|
||||||
|
CLICK_HANDLER_STATES oldState = me->state;
|
||||||
|
evIDT evid = Event_getId(ev);
|
||||||
|
|
||||||
|
switch(me->state) {
|
||||||
|
case STCH_INIT:
|
||||||
|
if(evid == evCHinit) {
|
||||||
|
me->state = STCH_WAIT;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case STCH_WAIT:
|
||||||
|
|
||||||
|
if(evid == evCHpbPress) {
|
||||||
|
me->state = STCH_LONG_CLICK;
|
||||||
|
POST(me, &CLICK_HANDLER_processEvent, evCHtimer, CH_CLICK_TIMER, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
|
||||||
|
|
||||||
|
case STCH_LONG_CLICK:
|
||||||
|
|
||||||
|
if(evid == evCHpbRelease) {
|
||||||
|
me->state = STCH_SINGLE_CLICK;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(evid == evCHtimer) {
|
||||||
|
me->state = STCH_WAIT;
|
||||||
|
if(me->longClick.fCallBack != NULL) {
|
||||||
|
me->longClick.fCallBack(me->longClick.param);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
|
||||||
|
|
||||||
|
case STCH_SINGLE_CLICK:
|
||||||
|
|
||||||
|
if(evid == evCHpbPress) {
|
||||||
|
me->state = STCH_DOUBLE_CLICK;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(evid == evCHtimer) {
|
||||||
|
me->state = STCH_WAIT;
|
||||||
|
if(me->singleClick.fCallBack != NULL) {
|
||||||
|
me->singleClick.fCallBack(me->singleClick.param);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
|
||||||
|
|
||||||
|
case STCH_DOUBLE_CLICK:
|
||||||
|
|
||||||
|
if(evid == evCHpbRelease){
|
||||||
|
me->state = STCH_WAIT;
|
||||||
|
if(me->doubleClick.fCallBack != NULL){
|
||||||
|
me->doubleClick.fCallBack(me->doubleClick.param);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(evid == evCHtimer) {
|
||||||
|
me->state = STCH_WAIT;
|
||||||
|
if(me->doubleClick.fCallBack != NULL) {
|
||||||
|
me->doubleClick.fCallBack(me->doubleClick.param);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
if(oldState != me->state) {
|
||||||
|
switch(oldState) {
|
||||||
|
case STCH_INIT:
|
||||||
|
break;
|
||||||
|
|
||||||
|
case STCH_WAIT:
|
||||||
|
break;
|
||||||
|
|
||||||
|
case STCH_LONG_CLICK:
|
||||||
|
break;
|
||||||
|
|
||||||
|
case STCH_SINGLE_CLICK:
|
||||||
|
break;
|
||||||
|
|
||||||
|
case STCH_DOUBLE_CLICK:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
55
03-software/ch/kb28/blinkerProject/middleware/clickHandler.h
Normal file
55
03-software/ch/kb28/blinkerProject/middleware/clickHandler.h
Normal file
@ -0,0 +1,55 @@
|
|||||||
|
/**
|
||||||
|
* @file clickHandler.h
|
||||||
|
* @author Rémi Heredero (remi@heredero.ch)
|
||||||
|
* @version 0.1
|
||||||
|
* @date 2023-06-13
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef CLICKHANDLER_H
|
||||||
|
#define CLICKHANDLER_H
|
||||||
|
|
||||||
|
#include "../xf/xf.h"
|
||||||
|
#include "../board/button/button.h"
|
||||||
|
|
||||||
|
#define CH_CLICK_TIMER 250
|
||||||
|
|
||||||
|
typedef enum {
|
||||||
|
STCH_INIT,
|
||||||
|
STCH_WAIT,
|
||||||
|
STCH_LONG_CLICK,
|
||||||
|
STCH_SINGLE_CLICK,
|
||||||
|
STCH_DOUBLE_CLICK
|
||||||
|
} CLICK_HANDLER_STATES;
|
||||||
|
|
||||||
|
typedef enum {
|
||||||
|
evCHinit = 150,
|
||||||
|
evCHtimer,
|
||||||
|
evCHpbPress,
|
||||||
|
evCHpbRelease
|
||||||
|
} CLICK_HANDLER_EVENTS;
|
||||||
|
|
||||||
|
typedef void (*fClickHandlerCallBack)(void*);
|
||||||
|
typedef struct {
|
||||||
|
fClickHandlerCallBack fCallBack;
|
||||||
|
void* param;
|
||||||
|
} clickHandlerCallBack;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
BUTTON* button;
|
||||||
|
CLICK_HANDLER_STATES state;
|
||||||
|
clickHandlerCallBack longClick;
|
||||||
|
clickHandlerCallBack singleClick;
|
||||||
|
clickHandlerCallBack doubleClick;
|
||||||
|
}CLICK_HANDLER;
|
||||||
|
|
||||||
|
void CLICK_HANDLER_init(CLICK_HANDLER* me, BUTTON* b);
|
||||||
|
clickHandlerCallBack CLICK_HANDLER_defineCallBack(fClickHandlerCallBack f, void* param);
|
||||||
|
void CLICK_HANDLER_startBehaviour(CLICK_HANDLER* me);
|
||||||
|
void CLICK_HANDLER_setLongClickCallback(CLICK_HANDLER* me, clickHandlerCallBack callBack);
|
||||||
|
void CLICK_HANDLER_setSingleClickCallback(CLICK_HANDLER* me, clickHandlerCallBack callBack);
|
||||||
|
void CLICK_HANDLER_setDoubleClickCallback(CLICK_HANDLER* me, clickHandlerCallBack callBack);
|
||||||
|
bool CLICK_HANDLER_processEvent(Event* ev);
|
||||||
|
|
||||||
|
|
||||||
|
#endif /* CLICKHANDLER_H */
|
||||||
|
|
@ -28,6 +28,7 @@
|
|||||||
<itemPath>ch/kb28/blinkerProject/mcc_generated_files/device_config.h</itemPath>
|
<itemPath>ch/kb28/blinkerProject/mcc_generated_files/device_config.h</itemPath>
|
||||||
</logicalFolder>
|
</logicalFolder>
|
||||||
<logicalFolder name="middleware" displayName="middleware" projectFiles="true">
|
<logicalFolder name="middleware" displayName="middleware" projectFiles="true">
|
||||||
|
<itemPath>ch/kb28/blinkerProject/middleware/clickHandler.h</itemPath>
|
||||||
</logicalFolder>
|
</logicalFolder>
|
||||||
<logicalFolder name="xf" displayName="xf" projectFiles="true">
|
<logicalFolder name="xf" displayName="xf" projectFiles="true">
|
||||||
<itemPath>ch/kb28/blinkerProject/xf/ireactive.h</itemPath>
|
<itemPath>ch/kb28/blinkerProject/xf/ireactive.h</itemPath>
|
||||||
@ -67,6 +68,7 @@
|
|||||||
<itemPath>ch/kb28/blinkerProject/mcc_generated_files/tmr0.c</itemPath>
|
<itemPath>ch/kb28/blinkerProject/mcc_generated_files/tmr0.c</itemPath>
|
||||||
</logicalFolder>
|
</logicalFolder>
|
||||||
<logicalFolder name="middleware" displayName="middleware" projectFiles="true">
|
<logicalFolder name="middleware" displayName="middleware" projectFiles="true">
|
||||||
|
<itemPath>ch/kb28/blinkerProject/middleware/clickHandler.c</itemPath>
|
||||||
</logicalFolder>
|
</logicalFolder>
|
||||||
<logicalFolder name="xf" displayName="xf" projectFiles="true">
|
<logicalFolder name="xf" displayName="xf" projectFiles="true">
|
||||||
<itemPath>ch/kb28/blinkerProject/xf/xf.c</itemPath>
|
<itemPath>ch/kb28/blinkerProject/xf/xf.c</itemPath>
|
||||||
@ -93,7 +95,7 @@
|
|||||||
<platformTool>PICkit3PlatformTool</platformTool>
|
<platformTool>PICkit3PlatformTool</platformTool>
|
||||||
<languageToolchain>XC8</languageToolchain>
|
<languageToolchain>XC8</languageToolchain>
|
||||||
<languageToolchainVersion>2.41</languageToolchainVersion>
|
<languageToolchainVersion>2.41</languageToolchainVersion>
|
||||||
<platform>3</platform>
|
<platform>2</platform>
|
||||||
</toolsSet>
|
</toolsSet>
|
||||||
<packs>
|
<packs>
|
||||||
<pack name="PIC18F-K_DFP" vendor="Microchip" version="1.7.134"/>
|
<pack name="PIC18F-K_DFP" vendor="Microchip" version="1.7.134"/>
|
||||||
@ -215,6 +217,7 @@
|
|||||||
<property key="debugoptions.debug-startup" value="Use system settings"/>
|
<property key="debugoptions.debug-startup" value="Use system settings"/>
|
||||||
<property key="debugoptions.reset-behaviour" value="Use system settings"/>
|
<property key="debugoptions.reset-behaviour" value="Use system settings"/>
|
||||||
<property key="debugoptions.useswbreakpoints" value="false"/>
|
<property key="debugoptions.useswbreakpoints" value="false"/>
|
||||||
|
<property key="firmware.download.all" value="false"/>
|
||||||
<property key="hwtoolclock.frcindebug" value="false"/>
|
<property key="hwtoolclock.frcindebug" value="false"/>
|
||||||
<property key="memories.aux" value="false"/>
|
<property key="memories.aux" value="false"/>
|
||||||
<property key="memories.bootflash" value="true"/>
|
<property key="memories.bootflash" value="true"/>
|
||||||
|
Reference in New Issue
Block a user