

#ifndef BLUETOOTH_CONTROL_H_
#define BLUETOOTH_CONTROL_H_

#include <stdint.h>
#include <stdbool.h>
#include "ble_needlite.h"
#include "event_log.h"


#define INTENSITY_TYPE       0x01
#define ONOFF_TYPE           0x02
#define USERNAME_TYPE        0x03

#define LAMP_OFF             0
#define LAMP_ON              1
#define LAMP_UNKNOWN         2

enum new_lamp_state_t { LAMP_STATE_ON=0, LAMP_STATE_OFF, LAMP_STATE_NO_CHANGE, LAMP_STATE_UNKNOWN};

#define BT_DISCONNECT_REASON_TIMEOUT 0x08 // from the BT 4.0 core spec.

#define NO_BRIGHTNESS_CHANGE 0xFF

extern int8_t rssi_result;
extern uint8_t rssi_ready;

void led_state(ble_needlite_t * p_needlite, uint8_t led_state);
void led_brightness(ble_needlite_t * p_needlite, uint8_t led_state);
void set_displayname(ble_needlite_t * p_needlite, uint8_t * data, uint32_t len);

/**
 * \param p_needlite
 * \param switch_state
 */
void set_dist_switch_state(ble_needlite_t * p_needlite, uint8_t switch_state);

uint8_t one_wire_go(void);
void bluetooth_init(uint32_t app_timer_prescaler_val);
bool is_bt_connected(void);
void start_rssi(void);
enum new_lamp_state_t get_bt_onoff(void);
uint8_t get_bt_brightness(void);
uint8_t get_rssi(void);
void ignore_rssi(void);
void set_bt_led_level(uint8_t local_app_data);
void set_bt_led_state(uint8_t local_app_data);
uint8_t get_bt_disconnect_reason(void);
void broadcast_proximity(void);
uint32_t bluetooth_send_event(event_log_entry_t * event);

#endif /* BLUETOOTH_CONTROL_H_ */
