Lizzy project

Dependencies:   aconno_I2C Lis2dh12 adc52832_common aconno_SEGGER_RTT

source/main.cpp

Committer:
jurica238814
Date:
2018-09-13
Branch:
SimpleGATTExample
Revision:
22:7dae8496b97c
Parent:
19:2681edc2f2b9

File content as of revision 22:7dae8496b97c:

/*
 * aconno.de
 * Made by Jurica Resetar
 * All right reserved
 *
 */

#include "bsp.h"
#include "bspLed.h"
#include "tasks.h"
#include <events/mbed_events.h>
#include "aconnoConfig.h"
#include "aconno_ble.h"

#if !defined(MBED_CPU_STATS_ENABLED) || !defined(DEVICE_LPTICKER) || \
	!defined(DEVICE_SLEEP)
#error [NOT_SUPPORTED] Test not supported for statistics
#endif

EventQueue queue(32 * EVENTS_EVENT_SIZE);

Thread bleT;
Thread updateServiceT;
Thread updateBuzzLedsT;
Thread updateStatisticsT;

void printStatsF()
{
    mbed_stats_cpu_t stats;

    mbed_stats_cpu_get(&stats);
    printf("%-20lld", stats.uptime/1000);
    printf("%-20lld", stats.idle_time/1000);
    printf("%-20lld", stats.sleep_time/1000);
    printf("%-20lld\n", stats.deep_sleep_time/1000);
}

void bleEventsProcessing(BLE::OnEventsToProcessCallbackContext* context) {
    BLE &ble = BLE::Instance();
    queue.call(Callback<void()>(&ble, &BLE::processEvents));
}

int main()
{
	printf("Main program started.\r\n");
	bspInit();

    BLE &ble = BLE::Instance();
	ble.onEventsToProcess(bleEventsProcessing);
    ble.init(bleInitComplete);

	#if PRINT_ON_RTT
		queue.call_every(2000, printStatsF);
	#endif

    updateBuzzLedsT.start(updateBuzzLedsF);
	queue.dispatch_forever();

}