/* main.c - Application main entry point */

/*
 * Copyright (c) 2015-2016 Intel Corporation
 *
 * SPDX-License-Identifier: Apache-2.0
 */

#include <zephyr/types.h>
#include <stddef.h>
#include <string.h>
#include <errno.h>
#include <sys/printk.h>
#include <sys/byteorder.h>
#include <zephyr.h>

#include "app_bluetooth.h"

class BTHandler
{
private:
	bool mInitialized;
public:
	BTHandler(void);
	int init(void);
	int hrsNotify(void);
	int basNotify(void);
};

BTHandler::BTHandler(void)
{
	mInitialized = false;
}

int BTHandler::init(void)
{
	int err = app_bluetooth_init();
	if(err == 0) {
		mInitialized = true;
		return 0;
	}
	else {
		mInitialized = false;
		return -1;
	}
}

int BTHandler::hrsNotify(void)
{
	if(mInitialized){
		/* Heartrate measurements simulation */
		hrs_notify();
		return 0;
	}
	return -1;
}
	
int BTHandler::basNotify(void)
{
	if(mInitialized) {
		/* Battery level simulation */
		bas_notify();
		return 0;
	}
	return -1;
}

BTHandler myBT;

void main(void)
{
	printk("Initializing Bluetooth..\n");
	if(myBT.init() != 0) {
		printk("BT init error!");
		return;
	}

	printk("Starting main loop\n");
	while (1) {
		myBT.hrsNotify();
		myBT.basNotify();
		k_sleep(K_SECONDS(1));
	}
}
