Ble for smart sOlutions

Dependencies:   Adafruit_WS2801

Files at this revision

API Documentation at this revision

Comitter:
kris@kris-X682X
Date:
Thu Jun 20 13:20:24 2019 +0200
Parent:
10:d845189d146e
Commit message:
Refactored

Changed in this revision

source/BleDevice.h Show annotated file Show diff for this revision Revisions of this file
source/BleDeviceCentral.cpp Show annotated file Show diff for this revision Revisions of this file
source/BleDeviceCentral.h Show annotated file Show diff for this revision Revisions of this file
source/BleDevicePeripheral.cpp Show annotated file Show diff for this revision Revisions of this file
source/BleDevicePeripheral.h Show annotated file Show diff for this revision Revisions of this file
source/ColorService.h Show annotated file Show diff for this revision Revisions of this file
source/InterestService.cpp Show annotated file Show diff for this revision Revisions of this file
source/MyStripSingleton.cpp Show annotated file Show diff for this revision Revisions of this file
source/main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/source/BleDevice.h	Fri Jun 14 10:24:57 2019 +0200
+++ b/source/BleDevice.h	Thu Jun 20 13:20:24 2019 +0200
@@ -123,7 +123,7 @@
             _event_queue(event_queue),
             _handle(0),
             _is_connecting(false),
-            hi(false){ };
+            has_interest_char(false){ };
 
     virtual ~BleDevice()
     {
@@ -230,33 +230,7 @@
                discovered_service->getEndHandle()
         );
     }
-    /**
-       * Add a discovered characteristic into the list of discovered characteristics.
-       */
-//    bool add_characteristic(const DiscoveredCharacteristic *characteristic)
-//    {
-//        //TODO: If char UUID == UUID, store char for reading
-//        if
-//        printf("Adding char");
-//
-////        if (new_node == false) {
-////            printf("Error while allocating a new characteristic.\r\n");
-////            return false;
-////        }
-//        printf("Added char");
-//
-//        if (_characteristics == NULL) {
-//            _characteristics = const_cast<DiscoveredCharacteristic *>(characteristic);
-//        } else {
-//            DiscoveredCharacteristic* c = _characteristics;
-//            while() {
-//                c = c->next;
-//            }
-//            c->next = new_node;
-//        }
-//        delete new_node;
-//        return true;
-//    }
+
     /**
      * Handle characteristics discovered.
      *
@@ -271,7 +245,6 @@
         printf("\tCharacteristic discovered: uuid = ");
         print_uuid(discovered_characteristic->getUUID());
         printf(", properties = ");
-//        print_properties(discovered_characteristic->getProperties());
         printf(
                 ", decl handle = %u, value handle = %u, last handle = %u.\r\n",
                 discovered_characteristic->getDeclHandle(),
@@ -280,7 +253,7 @@
         );
         if(discovered_characteristic->getUUID() == CustomUUIDs::UUID_INTEREST_CHAR){
             printf("You have the interest char!");
-            hi = true;
+            has_interest_char = true;
             _interest_characteristic = discovered_characteristic;
         }
     }
@@ -295,7 +268,7 @@
      */
     void when_service_discovery_ends(Gap::Handle_t connection_handle)
     {
-        if (!hi) {
+        if (!has_interest_char) {
             printf("No characteristics discovered, end of the process.\r\n");
             return;
         }
@@ -369,8 +342,7 @@
         }
         printf(".\r\n");
 
-//        Characteristic value at 6 equal to: 0xFF 0x00 0xFF 0x04 0xFF 0x55 0xFF 0x01 0x05 0x05 0x05 0x07 0xFF 0xFF 0xFF 0x06 0xFF 0xEE 0xFF 0x09 .
-        //TODO: Nummer op pos 3, 7, 11, 15, 19 vergelijken met mijn interesses. Als er eentje overeen komt, licht dan op.
+        //TODO: Lelijke code ombouwen naar loop
         for(int i = 3; i < 20; i += 4){
             int targetInterest = read_event->data[i];
             printf("Let's see if there's a match between you guys..\r\n");
@@ -440,9 +412,6 @@
         _event_queue.break_dispatch();
         //And/or resume advertising?
     };
-    virtual void compareInterests(const GattReadCallbackParams *read_event){
-
-    }
 
     virtual void onAdvertisingEnd(const ble::AdvertisingEndEvent &)
     {
@@ -480,7 +449,7 @@
     events::EventQueue &_event_queue;
     ble::connection_handle_t _handle;
     bool _is_connecting;
-    bool hi;
+    bool has_interest_char;
     const DiscoveredCharacteristic *_interest_characteristic;
 
 };
--- a/source/BleDeviceCentral.cpp	Fri Jun 14 10:24:57 2019 +0200
+++ b/source/BleDeviceCentral.cpp	Thu Jun 20 13:20:24 2019 +0200
@@ -84,8 +84,6 @@
                 char GoogleHome[field.value.size()];
                 char *output = NULL;
                 output = strstr (test, "GoogleHome");
-
-
                 memcpy(test, field.value.data(), field.value.size());
                 //TODO: If name contains something like google home, do fancy shit but keep it at that
                 if (output) {
--- a/source/BleDeviceCentral.h	Fri Jun 14 10:24:57 2019 +0200
+++ b/source/BleDeviceCentral.h	Thu Jun 20 13:20:24 2019 +0200
@@ -31,8 +31,6 @@
             print_error(error, "Error in Gap::startScan %d\r\n");
             return;
         }
-//
-//        /* start scanning, results will be handled by onAdvertisingReport */
         error = _ble.gap().startScan();
 
         if (error) {
--- a/source/BleDevicePeripheral.cpp	Fri Jun 14 10:24:57 2019 +0200
+++ b/source/BleDevicePeripheral.cpp	Thu Jun 20 13:20:24 2019 +0200
@@ -1,26 +1,12 @@
 #include "BleDevicePeripheral.h"
 
-void ledStuff(){
-
-    MyStripSingleton::getInstance()->connectionFlash();
-    MyStripSingleton::getInstance()->resetColor();
-}
 void BleDevicePeripheral::onConnectionComplete(const ble::ConnectionCompleteEvent &event) {
-//    ble_error_t error;
-    /* remember the device that connects to us now so we can connect to it
-     * during the next demonstration */
-//        memcpy(_peer_address, event.getPeerAddress().data(), sizeof(_peer_address));
-    //TODO: Connecting to the device breaks the event queue; it should. BUT there should start some new stuff
     printf("[PERIPHERAL]\t Connected to peer: ");
     print_address(event.getPeerAddress().data());
     _handle = event.getConnectionHandle();
     printf("[PERIPHERAL]\t I'm connected to someone, what should i do now?");
+
     //Dispatch forever makes sure that we stay in this state until explicitly told otherwise (on disconnect).
-
-
-//    MyStripSingleton::getInstance()->connectionFlash();
-//    MyStripSingleton::getInstance()->resetColor();
-//    _event_queue.call(callback(ledStuff));
     _event_queue.dispatch_forever();
 
 }
--- a/source/BleDevicePeripheral.h	Fri Jun 14 10:24:57 2019 +0200
+++ b/source/BleDevicePeripheral.h	Thu Jun 20 13:20:24 2019 +0200
@@ -8,12 +8,8 @@
 #include "InterestService.h"
 
 #include "ColorService.h"
-const static char     DEVICE_NAME[] = "SSS-Wearable";
-
 class BleDevicePeripheral : public BleDevice {
 private:
-    static ColorService* colorServicePtr;
-    uint16_t uuid16_list;
     ColorService *cs;
     InterestService *is;
 public:
--- a/source/ColorService.h	Fri Jun 14 10:24:57 2019 +0200
+++ b/source/ColorService.h	Thu Jun 20 13:20:24 2019 +0200
@@ -31,20 +31,8 @@
         ble.gattServer().addService(colorService);
 
         ble.gattServer().onDataWritten(this, &ColorService::onDataWritten);
-//        serviceAdded = true;
     }
 
-
-    /**
-     * @brief   Update temperature characteristic.
-     * @param   newTemperatureVal New temperature measurement.
-     */
-//    void updateColor(const ColorType_t newColorVal)
-//    {
-//        color = ( *((int*)newColorVal ) );
-//        ble.gattServer().write(colorCharacteristic.getValueHandle(), (uint8_t *) &color, sizeof(ColorType_t));
-//    }
-
     virtual ~ColorService() {
         printf("[PERIPHERAL]\t Destructing ColorService");
     }
--- a/source/InterestService.cpp	Fri Jun 14 10:24:57 2019 +0200
+++ b/source/InterestService.cpp	Thu Jun 20 13:20:24 2019 +0200
@@ -105,7 +105,6 @@
             interests[2] = ptr->interest3;
             interests[3] = ptr->interest4;
             interests[4] = ptr->interest5;
-            //TODO: wRITE THIS TO THE GATTSERVER
             ble.gattServer().write(interestCharacteristic.getValueHandle(), (uint8_t *) &interests, sizeof(interests_T));
 
             printf("[PERIPHERAL]\t Interests should now be set to: %8x,%8x,%8x,%8x,%8x \r\n",
--- a/source/MyStripSingleton.cpp	Fri Jun 14 10:24:57 2019 +0200
+++ b/source/MyStripSingleton.cpp	Thu Jun 20 13:20:24 2019 +0200
@@ -33,18 +33,6 @@
         return Color(0, WheelPos * 3, 255 - WheelPos * 3);
     }
 }
-void MyStripSingleton::rainbow(uint8_t waittime) {
-    int i, j;
-
-    for (j=0; j < 256; j++) {     // 3 cycles of all 256 colors in the wheel
-        for (i=0; i < strip.numPixels(); i++) {
-            strip.setPixelColor(i, Wheel( (i + j) % 255));
-        }
-        strip.show();   // write all the pixels out
-        wait_ms(waittime);// (wait);
-    }
-}
-
 // Slightly different, this one makes the rainbow wheel equally distributed
 // along the chain
 void MyStripSingleton::rainbowCycle(uint8_t waittime) {
--- a/source/main.cpp	Fri Jun 14 10:24:57 2019 +0200
+++ b/source/main.cpp	Thu Jun 20 13:20:24 2019 +0200
@@ -27,68 +27,6 @@
 #define MBED_CONF_PLATFORM_ERROR_FILENAME_CAPTURE_ENABLED true
 MyStripSingleton* MyStripSingleton::instance = 0;
 
-DigitalOut led1(LED1, 1);
-
-static EventQueue eventQueue(/* event count */ 16 * EVENTS_EVENT_SIZE);
-
-
-void blinkCallback(void)
-{
-    //TODO: Every
-    led1 = !led1; /* Do blinky on LED1 while we're waiting for BLE events */
-    BLE &ble = BLE::Instance();
-
-
-    if (ble.gap().getState().connected) {
-        /* Hier kan je nog iets doen wanneer je verbonden bent */
-//        eventQueue.call(updateSensorValue);
-
-    } else {
-        ble.gap().startAdvertising();
-        printf("Stopped advertisement");
-    }
-}
-
-void printMacAddress()
-{
-    /* Print out device MAC address to the console*/
-    Gap::AddressType_t addr_type;
-    Gap::Address_t address;
-    BLE::Instance().gap().getAddress(&addr_type, address);
-    printf("DEVICE MAC ADDRESS: ");
-    for (int i = 5; i >= 1; i--){
-        printf("%02x:", address[i]);
-    }
-    printf("%02x\r\n", address[0]);
-}
-
-/**
- * Callback triggered when the ble initialization process has finished
- */
-void bleInitComplete(BLE::InitializationCompleteCallbackContext *params)
-{
-
-}
-
-
-void scheduleBleEventsProcessing(BLE::OnEventsToProcessCallbackContext* context) {
-    BLE &ble = BLE::Instance();
-    //TODO: Event handling; wel benieuwd naar wat er allemaal gebeurt
-    eventQueue.call(Callback<void()>(&ble, &BLE::processEvents));
-}
-
-uint32_t colorMaker(uint8_t r, uint8_t g, uint8_t b){
-    uint32_t c;
-    c = r;
-    c <<= 8;
-    c |= g;
-    c <<= 8;
-    c |= b;
-    return c;
-}
-
-
-
 int main()
 {
     BLE& ble = BLE::Instance();