Digi International Inc. / Mbed 2 deprecated XBee802_dio_adc_pwm

Dependencies:   XBeeLib mbed

Files at this revision

API Documentation at this revision

Comitter:
hbujanda
Date:
Thu May 14 16:22:04 2015 +0200
Parent:
4:8cb879e995f2
Child:
6:d0224db329e1
Commit message:
Automatic upload

Changed in this revision

XBeeLib.lib Show annotated file Show diff for this revision Revisions of this file
config.h 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/XBeeLib.lib	Thu May 14 16:04:34 2015 +0200
+++ b/XBeeLib.lib	Thu May 14 16:22:04 2015 +0200
@@ -1,1 +1,1 @@
-http://developer.mbed.org/teams/Digi-International-Inc/code/XBeeLib/#
+http://developer.mbed.org/teams/Digi-International-Inc/code/XBeeLib/#2ee1b6d51df2
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/config.h	Thu May 14 16:22:04 2015 +0200
@@ -0,0 +1,47 @@
+
+#if !defined(__CONFIG_H_)
+#define __CONFIG_H_
+
+/** Library configuration options */
+#define ENABLE_LOGGING
+#define ENABLE_ASSERTIONS
+#define FRAME_BUFFER_SIZE           4
+#define MAX_FRAME_PAYLOAD_LEN       128
+#define ENABLE_PM_SUPPORT
+
+#define SYNC_OPS_TIMEOUT_MS         2000
+
+//#define RADIO_TX                NC /* TODO: specify your setup's Serial TX pin connected to the XBee module DIN pin */
+//#define RADIO_RX                NC /* TODO: specify your setup's Serial RX pin connected to the XBee module DOUT pin */
+//#define RADIO_RTS               NC /* TODO: specify your setup's Serial RTS# pin connected to the XBee module RTS# pin */
+//#define RADIO_CTS               NC /* TODO: specify your setup's Serial CTS# pin connected to the XBee module CTS# pin */
+//#define RADIO_RESET             NC /* TODO: specify your setup's GPIO (output) connected to the XBee module's reset pin */
+//#define RADIO_SLEEP_REQ         NC /* TODO: specify your setup's GPIO (output) connected to the XBee module's SLEEP_RQ pin */
+//#define RADIO_ON_SLEEP          NC /* TODO: specify your setup's GPIO (input) connected to the XBee module's ON_SLEEP pin */
+//#define DEBUG_TX                NC /* TODO: specify your setup's Serial TX for debugging */
+//#define DEBUG_RX                NC /* TODO: specify your setup's Serial RX for debugging (optional) */
+
+#if !defined(RADIO_TX)
+    #error "Please define RADIO_TX pin"
+#endif
+
+#if !defined(RADIO_RX)
+    #error "Please define RADIO_RX pin"
+#endif
+
+#if !defined(RADIO_RESET)
+    #define RADIO_RESET             NC
+    #warning "RADIO_RESET not defined, defaulted to 'NC'"
+#endif
+
+#if defined(ENABLE_LOGGING)
+    #if !defined(DEBUG_TX)
+        #error "Please define DEBUG_TX"
+    #endif
+    #if !defined(DEBUG_RX)
+        #define DEBUG_RX                NC
+        #warning "DEBUG_RX not defined, defaulted to 'NC'"
+    #endif
+#endif
+
+#endif /* __CONFIG_H_ */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Thu May 14 16:22:04 2015 +0200
@@ -0,0 +1,103 @@
+/**
+ * Copyright (c) 2015 Digi International Inc.,
+ * All rights not expressly granted are reserved.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this file,
+ * You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * Digi International Inc. 11001 Bren Road East, Minnetonka, MN 55343
+ * =======================================================================
+ */
+
+#include "mbed.h"
+#include "XBeeLib.h"
+#if defined(ENABLE_LOGGING)
+#include "DigiLoggerMbedSerial.h"
+using namespace DigiLog;
+#endif
+
+// TODO Replace with the MSB of the remote module's 64-bit address (SH parameter)
+#define REMOTE_NODE_ADDR64_MSB  ((uint32_t)0x0013A200)
+// TODO Replace with the LSB of the remote module's 64-bit address (SL parameter)
+#define REMOTE_NODE_ADDR64_LSB  ((uint32_t)0x40D2B03E)
+
+#define REMOTE_NODE_ADDR64      UINT64(REMOTE_NODE_ADDR64_MSB, REMOTE_NODE_ADDR64_LSB)
+
+using namespace XBeeLib;
+
+Serial *log_serial;
+
+int main()
+{
+    log_serial = new Serial(DEBUG_TX, DEBUG_RX);
+    log_serial->baud(9600);
+    log_serial->printf("Sample application to demo how to handle remote XBee802 devices DIOs, ADCs and PWMs\r\n\r\n");
+    log_serial->printf(XB_LIB_BANNER);
+
+#if defined(ENABLE_LOGGING)
+    new DigiLoggerMbedSerial(log_serial, LogLevelInfo);
+#endif
+
+    XBee802 xbee = XBee802(RADIO_TX, RADIO_RX, RADIO_RESET, NC, NC, 9600);
+
+    RadioStatus radioStatus = xbee.init();
+    MBED_ASSERT(radioStatus == Success);
+
+    const RemoteXBee802 remoteDevice = RemoteXBee802(REMOTE_NODE_ADDR64);
+
+    radioStatus = xbee.set_pin_config(remoteDevice, XBee802::DIO3_AD3, DigitalInput);
+    MBED_ASSERT(radioStatus == Success);
+
+    radioStatus = xbee.set_pin_pull_up(remoteDevice, XBee802::DIO3_AD3, true);
+    MBED_ASSERT(radioStatus == Success);
+
+    radioStatus = xbee.set_pin_config(remoteDevice, XBee802::DIO4_AD4, DigitalOutHigh);
+    MBED_ASSERT(radioStatus == Success);
+
+    radioStatus = xbee.set_pin_config(remoteDevice, XBee802::DIO2_AD2, Adc);
+    MBED_ASSERT(radioStatus == Success);
+
+    radioStatus = xbee.set_pin_config(remoteDevice, XBee802::PWM0, Pwm);
+    MBED_ASSERT(radioStatus == Success);
+
+    while(true) {
+        /* Read DIO3_AD3 digital value */
+        DioVal dio3_val;
+        radioStatus = xbee.get_dio(remoteDevice, XBee802::DIO3_AD3, &dio3_val);
+        MBED_ASSERT(radioStatus == Success);
+        log_serial->printf("DIO3 value = %d\r\n", dio3_val);
+
+        /* Toggle LED associated to DIO4 */
+        static bool led_on = false;
+        log_serial->printf("Setting DIO4 to = %d\r\n", led_on);
+        if (!led_on)
+            radioStatus = xbee.set_dio(remoteDevice, XBee802::DIO4_AD4, Low);
+        else
+            radioStatus = xbee.set_dio(remoteDevice, XBee802::DIO4_AD4, High); 
+        MBED_ASSERT(radioStatus == Success);
+        led_on = !led_on;
+
+        /* Read DIO2_AD2 analog value */
+        uint16_t adc2_val;
+        radioStatus = xbee.get_adc(remoteDevice, XBee802::DIO2_AD2, &adc2_val);
+        MBED_ASSERT(radioStatus == Success);
+        log_serial->printf("ADC2 value = 0x%04x\r\n", adc2_val);
+
+        /* Set the PWM0 LED to different values */
+        static float pwm_val_list[] = { 0.0, 50.0, 70.0, 100.0 };
+        static uint8_t pwm_val_idx = 0;
+        log_serial->printf("Setting PWM0 to = %f\r\n", pwm_val_list[pwm_val_idx]);
+        radioStatus = xbee.set_pwm(remoteDevice, XBee802::PWM0, pwm_val_list[pwm_val_idx]);
+        MBED_ASSERT(radioStatus == Success);
+        pwm_val_idx++;
+        if (pwm_val_idx == sizeof(pwm_val_list)/sizeof(pwm_val_list[0]))
+            pwm_val_idx = 0;
+
+        log_serial->printf("\r\n");
+        
+        wait(5);
+    }
+
+    delete(log_serial);
+}