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: GroveGPS libmDot-mbed5 ISL29011
Diff: examples/src/peer_to_peer_example.cpp
- Revision:
- 30:2f5ae37e6c47
- Parent:
- 25:56f7775c702f
- Child:
- 33:15ea8f985c54
diff -r 9e2c0d990ace -r 2f5ae37e6c47 examples/src/peer_to_peer_example.cpp
--- a/examples/src/peer_to_peer_example.cpp Fri Apr 20 14:42:46 2018 -0500
+++ b/examples/src/peer_to_peer_example.cpp Mon Apr 30 14:46:28 2018 -0500
@@ -28,6 +28,13 @@
Serial pc(USBTX, USBRX);
+#if defined(TARGET_XDOT_L151CC)
+I2C i2c(I2C_SDA, I2C_SCL);
+ISL29011 lux(i2c);
+#else
+AnalogIn lux(XBEE_AD0);
+#endif
+
int main() {
// Custom event handler for automatically displaying RX data
RadioEvent events;
@@ -38,6 +45,10 @@
pc.baud(115200);
+#if defined(TARGET_XDOT_L151CC)
+ i2c.frequency(400000);
+#endif
+
mts::MTSLog::setLogLevel(mts::MTSLog::TRACE_LEVEL);
#if CHANNEL_PLAN == CP_US915
@@ -147,8 +158,8 @@
// display configuration
display_config();
- uint8_t counter = 0;
while (true) {
+ uint16_t light;
std::vector<uint8_t> tx_data;
// join network if not joined
@@ -156,10 +167,30 @@
join_network();
}
- tx_data.push_back(++counter);
- logInfo("sending uplink with data = %d", counter);
+#if defined(TARGET_XDOT_L151CC)
+ // configure the ISL29011 sensor on the xDot-DK for continuous ambient light sampling, 16 bit conversion, and maximum range
+ lux.setMode(ISL29011::ALS_CONT);
+ lux.setResolution(ISL29011::ADC_16BIT);
+ lux.setRange(ISL29011::RNG_64000);
+
+ // get the latest light sample and send it to the gateway
+ light = lux.getData();
+ tx_data.push_back((light >> 8) & 0xFF);
+ tx_data.push_back(light & 0xFF);
+ logInfo("light: %lu [0x%04X]", light, light);
send_data(tx_data);
+ // put the LSL29011 ambient light sensor into a low power state
+ lux.setMode(ISL29011::PWR_DOWN);
+#else
+ // get some dummy data and send it to the gateway
+ light = lux.read_u16();
+ tx_data.push_back((light >> 8) & 0xFF);
+ tx_data.push_back(light & 0xFF);
+ logInfo("light: %lu [0x%04X]", light, light);
+ send_data(tx_data);
+#endif
+
// the Dot can't sleep in PEER_TO_PEER mode
// it must be waiting for data from the other Dot
// send data every 5 seconds