Ble for smart sOlutions

Dependencies:   Adafruit_WS2801

source/main.cpp

Committer:
kris@kris-X682X
Date:
2019-06-14
Revision:
10:d845189d146e
Parent:
9:92d861703f96
Child:
11:d6ed1437c2ee

File content as of revision 10:d845189d146e:

/* mbed Microcontroller Library
 * Copyright (c) 2006-2014 ARM Limited
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include <events/mbed_events.h>
#include <mbed.h>
#include "ble/BLE.h"
#include "ble/Gap.h"
#include "GattCallbackParamTypes.h"
#include "mbed.h"
#include "ColorService.h"
#include "BleDeviceCentral.h"
#include "BleDevicePeripheral.h"
#include "MyStripSingleton.h"
#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();
    events::EventQueue queue;
    printf(" Is filename capture enabled? \t\t");
    #if MBED_CONF_PLATFORM_ERROR_FILENAME_CAPTURE_ENABLED
    printf(" Enabled filename capture");
    #endif

    BleDevicePeripheral peripheral(ble, queue);
    BleDeviceCentral central(ble, queue);
    MyStripSingleton* inst = MyStripSingleton::getInstance();
    MyStripSingleton::getInstance()->colorWipe(1, 0x00FF00);

    MyStripSingleton::getInstance()->blink(10, 2);
    MyStripSingleton::getInstance()->flash(1, 0xFFFF00);

    while(1) {
        printf("\r\n PERIPHERAL \r\n\r\n");
        peripheral.run(15000);
        peripheral.stop();

        printf("\r\n CENTRAL \r\n\r\n");
        central.run(10000);
        central.stop();
    }
    return 0;
}