![](/media/cache/group/default_image.jpg.50x50_q85.jpg)
Wireless interface using LoRa technology
Dependencies: AlohaTransceiver RingBuffer SX1276Lib_inAir SerialInterfaceProtocol mbed L3PDU
Diff: main.cpp
- Revision:
- 24:e41b5098ed0a
- Parent:
- 22:fea9289f31b3
- Child:
- 25:2fff6d1b4eb6
--- 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();