Reinout nvt
/
PGO6_VoteController_template
Initial commit
Fork of PGO6_VoteController_template by
Revision 2:f283e5274a0f, committed 2017-10-26
- Comitter:
- Rennert
- Date:
- Thu Oct 26 14:25:29 2017 +0000
- Parent:
- 1:e7a311bd038e
- Commit message:
- Commented;
Changed in this revision
debounce_button.cpp | Show annotated file Show diff for this revision Revisions of this file |
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/debounce_button.cpp Thu Oct 26 14:16:10 2017 +0000 +++ b/debounce_button.cpp Thu Oct 26 14:25:29 2017 +0000 @@ -64,8 +64,11 @@ - informs the main loop that the user is clicking the button. Therefore, this main loop cannot continue its procedure until the clicks within 1 second have been counted. */ + +//Processes button interrupts void button1_onpressed_cb(void) { + //If not busy, start measuring presses if(!button1_busy){ button1_busy=true; button1_enabled=false; @@ -74,6 +77,7 @@ enableTimeout.attach(callback(&button1_enabled_cb), 0.1); } + //If busy, measure presses if(button1_busy && button1_enabled){ button1_enabled=false; enableTimeout.attach(callback(&button1_enabled_cb), 0.1);
--- a/main.cpp Thu Oct 26 14:16:10 2017 +0000 +++ b/main.cpp Thu Oct 26 14:25:29 2017 +0000 @@ -47,6 +47,8 @@ - To have a uniform message sending procedure, use the following function usage: sendMessage(&client, topic, buf, qos, retained, duplicate) */ + +//Connects to Network & MQTT void connect(char* name){ interface.connect(); while(interface.get_ip_address()== NULL){ @@ -62,6 +64,7 @@ connected=1; } +//Publishes MQTT data void send(char* feedback){ char buf[100]; sprintf(buf, feedback); @@ -75,6 +78,7 @@ client.publish(TOPIC, message); } +//Disconnects MQTT void disconnect(void){ client.unsubscribe(TOPIC); client.disconnect(); @@ -82,10 +86,12 @@ connected=0; } +//Processes message arrived void messageArrived(MQTT::MessageData& md) { MQTT::Message &message = md.message; info=1; + //NOTE: Due to lack of working serial terminal, sends data to clubIOT/feedback for reading. This should be printf. char buf[100]; sprintf(buf,"Message arrived: qos %d, retained %d, dup %d, packetid %d\r\n", message.qos, message.retained, message.dup, message.id); send(buf); @@ -93,18 +99,20 @@ send(buf); } +//Subscribe to MQTT topic void subscribe(char* topic){ client.subscribe(topic, MQTT::QOS2, messageArrived); } + int main(int argc, char* argv[]) { - connect("Jef"); + connect("Reinout"); subscribe("clubIOT/songmeta"); + //Connect button to interrupt InterruptIn button(USER_BUTTON); + button.fall(callback(&button1_onpressed_cb)); - button.fall(callback(&button1_onpressed_cb)); - float x=0; while(connected){ if(!button1_busy && multiclick_state!=0){ if(multiclick_state==1)