Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: AlohaTransceiver RingBuffer SX1276Lib_inAir SerialInterfaceProtocol mbed L3PDU
Revision 24:e41b5098ed0a, committed 2016-09-02
- Comitter:
- rba90
- Date:
- Fri Sep 02 04:20:47 2016 +0000
- Parent:
- 23:f3ae7ff4d3ae
- Child:
- 25:2fff6d1b4eb6
- Commit message:
- add door sensor interrupt handler
Changed in this revision
| AlohaTransceiver.lib | 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/AlohaTransceiver.lib Fri Sep 02 03:24:44 2016 +0000 +++ b/AlohaTransceiver.lib Fri Sep 02 04:20:47 2016 +0000 @@ -1,1 +1,1 @@ -http://developer.mbed.org/teams/ENEL400/code/AlohaTransceiver/#2e39f382f782 +http://developer.mbed.org/teams/ENEL400/code/AlohaTransceiver/#4b51a8e27f6a
--- a/main.cpp Fri Sep 02 03:24:44 2016 +0000
+++ b/main.cpp Fri Sep 02 04:20:47 2016 +0000
@@ -22,6 +22,7 @@
// sensors
#define SUPPLY_VOLTAGE 3.3f;
AnalogIn TempSensor(PA_0);
+InterruptIn door(D15);
// convert fp32 to 4 byte string
typedef union
@@ -45,8 +46,46 @@
bool getDoorState()
{
- // TODO: Jamie, you need to implement this!
- return true;
+ return door.read();
+}
+
+void doorStateChangeHandler()
+{
+ static uint8_t seqid = 0;
+ bool doorState = getDoorState();
+
+ DataBlockPacket doorEvent;
+
+ // set sequence id (the sequence id is configured as incoming sequence id + 1)
+ doorEvent.setSequenceID(seqid++);
+
+ // set source id (the source id is the current device ID)
+ doorEvent.setSourceID(aloha.getDeviceID());
+
+ // set destination id (send to base station by default)
+ doorEvent.setDestinationID(0x0);
+
+ // set source type (door state)
+ doorEvent.setSourceType(0x1);
+
+ // set payload type (boolean)
+ doorEvent.setPayloadType(0x8);
+
+ // copy door state (first byte)
+ doorEvent.setData(0, doorState);
+
+ // calculate crc
+ doorEvent.generateCrc();
+
+ // serialize and send it
+ uint8_t buffer[8];
+ memset(buffer, 0x0, sizeof(buffer));
+
+ // copy bytes into buffer
+ doorEvent.serialize(buffer);
+
+ // send to aloha transceiver
+ aloha.send(buffer, 8, 0x0);
}
void serialInterruptHandler() {
@@ -692,6 +731,10 @@
// configure button interrupt
button.fall(automaticPacketTransmit);
+ // configure door state
+ door.rise(doorStateChangeHandler); //Rising edge occurs when the "door opens"
+ door.fall(doorStateChangeHandler); //Falling edge occurs when the "door closes"
+
while(1) {
SIP.poll();
aloha.poll();