Just a quick custom service

Files at this revision

API Documentation at this revision

Comitter:
gaggenwaschke
Date:
Fri Feb 15 11:27:45 2019 +0000
Parent:
0:bc6cd13ebbdb
Commit message:
Changed to speed test;

Changed in this revision

CountdownService.h Show annotated file Show diff for this revision Revisions of this file
wavr.h Show annotated file Show diff for this revision Revisions of this file
--- a/CountdownService.h	Fri Nov 23 08:59:41 2018 +0000
+++ b/CountdownService.h	Fri Feb 15 11:27:45 2019 +0000
@@ -10,46 +10,48 @@
 #include "ble/BLE.h"
 
 
+/** definitions for UUID's */
+static const char* UUID_COUNTDOWN_SERVICE = "8ca81a4b-6182-4b04-ba9c-e4002a4a7a8b";    // UUID of the contdown service
+static const char* UUID_W_CHARACTERISTIC = "6a9e371d-a3fc-4a34-bd21-ad887188532c";  // UUID of the time characteristic
+static UUID UUID_Service(UUID_COUNTDOWN_SERVICE);
+static UUID UUID_WCharacteristic(UUID_W_CHARACTERISTIC);
+
+typedef struct Buffer {
+    uint8_t data[512];
+} Buffer;
+
 class CountdownService {
 typedef CountdownService Self;
-public:
-    const static uint16_t UUID_Service = 0xFFFF;
-    const static uint16_t UUID_TimeCharacteristic = 0xFFFF;
-    
-    CountdownService(GattServer &server, Callback<void(uint32_t)> countdown_changed_callback = NULL):
+public:    
+    CountdownService(GattServer &server, Callback<void(uint8_t*, uint16_t)> w_changed_callback):
     server(server),
-    countdownChar(UUID_TimeCharacteristic,0),
-    onCountdownReset(countdown_changed_callback) {
+    wChar(UUID_WCharacteristic, NULL),
+    onWCharWritten(w_changed_callback) {
         
-        GattCharacteristic *charTable[] = {&countdownChar};
+        GattCharacteristic *charTable[] = {&wChar};
         GattService service(UUID_Service, charTable, sizeof(charTable) / sizeof(GattCharacteristic *));
         
         server.addService(service); 
         server.onDataWritten(this, &CountdownService::onDataWritten);
     }
     
-    
-    void SetCountdown(uint32_t value) {
-        server.write(countdownChar.getValueHandle(), (const uint8_t*)&value, sizeof(uint32_t)); 
-    }
-    uint32_t GetCountdown() {
-        uint16_t len = 4;
-        uint32_t value;
-        uint8_t* buffer = (uint8_t*)&value;
-        server.read(countdownChar.getValueHandle(), buffer, &len);
-        return value;
+    void GetWCharValue(uint8_t *data, uint16_t *length) {
+        server.read(wChar.getValueHandle(), data, length);
     }
     
 private:
     void onDataWritten(const GattWriteCallbackParams *params) {
-        if (params->handle == countdownChar.getValueHandle()) {
-            onCountdownReset(GetCountdown());
+        if (params->handle == wChar.getValueHandle()) {
+            uint16_t length;
+            uint8_t data[512];
+            GetWCharValue(data, &length);
+            onWCharWritten(data, length);
         }
     }
     
 private:
     GattServer &server;
-    ReadWriteGattCharacteristic<uint32_t> countdownChar;
-    Callback<void(uint32_t)> onCountdownReset;
+    WriteOnlyGattCharacteristic<Buffer> wChar;
+    Callback<void(uint8_t, 512)> onWCharWritten;
 };
 #endif
\ No newline at end of file
--- a/wavr.h	Fri Nov 23 08:59:41 2018 +0000
+++ b/wavr.h	Fri Feb 15 11:27:45 2019 +0000
@@ -18,14 +18,23 @@
 /**
  *  Settings for general behavior
  */
- #define EVENT_QUEUE_SIZE           (8)            // size of the event queue
+#define PRODUCT_ID                  (0x05)          // WAVR product id
+#define VERSION_NUMBER              (0x01)          // version of the software         
+#define EVENT_QUEUE_SIZE            (16)             // size of the event queue
  
  /**
  *  General IO pins
  */
-#define PIN_LED_RED                 (p12)           //Module red LED
-#define PIN_LED_BLUE                (p14)           //Module blue LED
-#define PIN_LED_GREEN               (p15)           //Module green LED
+#define PIN_LED_RED                 (p12)           // Module red LED
+#define PIN_LED_BLUE                (p14)           // Module blue LED
+#define PIN_LED_GREEN               (p15)           // Module green LED
+
+/** battery pins */
+#define PIN_BAT_VOL                 (p3)            // battery voltage
+#define MAX_BAT_V                   (4.2)           // maximum battery voltage
+#define MIN_BAT_V                   (3.7)           // minimum battery voltage
+#define R3                          (330000)        // upper voltage splitter R 
+#define R4                          (100000)        // lower voltage splitter R
  
 /**
  *  Pins for the DRV8837 motor controller
@@ -33,6 +42,8 @@
 #define PIN_M_NSLEEP                (p21)           // inverted sleep motor driver
 #define PIN_M_IN1                   (p10)           // motor driver in1
 #define PIN_M_IN2                   (p9)            // motor driver in2
+#define PIN_M_CUR                   (p2)            // motor driver current sense
+#define M_STALL_CUR                 (0.09)           // stall current in ampere
 
 /**
  *  Settings for BT
@@ -42,4 +53,6 @@
 #define MSD_SIZE                    (29)            // Manufacturer Specific Data lenght (in B)
 #define ADVERTISING_INTERVAL_MS     (500)           // interval in which the device is advertised, at least 100ms
 
+const float V_MULTI =               3.3 * (R3 + R4) / R4; // multiplier for measured voltage to battery voltage
+
 #endif
\ No newline at end of file