48 lines
1.5 KiB
C
48 lines
1.5 KiB
C
/**
|
|
* @file gadget_bridge.c
|
|
* @author Anatole SCHRAMM-HENRY
|
|
* @brief Source file implementing the API used to communicate/interact with the GadgetBridge Android application
|
|
* over BLE.
|
|
* @version 0.1
|
|
* @date 2023-04-05
|
|
*
|
|
* @copyright Copyright (c) 2023
|
|
*
|
|
*/
|
|
|
|
#include "gadget_bridge.h"
|
|
#include <string.h>
|
|
#include "ble_service.h"
|
|
|
|
/* Internal function definition */
|
|
const char *_gadget_bridge_toast_type_2_str(gadget_bridge_toast_type_e toast_type);
|
|
|
|
bool gadget_bridge_send_toast(gadget_bridge_toast_type_e toast_type, const char *message)
|
|
{
|
|
if(!message || !strlen(message))
|
|
return true;
|
|
|
|
bool to_return = true;
|
|
to_return &= ble_service_send_nus_data((const uint8_t *)"{\"t\":\"", 6);
|
|
to_return &= ble_service_send_nus_data((const uint8_t *)_gadget_bridge_toast_type_2_str(toast_type), strlen(_gadget_bridge_toast_type_2_str(toast_type)));
|
|
to_return &= ble_service_send_nus_data((const uint8_t *)"\",\"msg\",\"", 9);
|
|
to_return &= ble_service_send_nus_data((const uint8_t *)message, strlen(message));
|
|
to_return &= ble_service_send_nus_data((const uint8_t *)"\"}\n", 3);
|
|
|
|
return to_return;
|
|
}
|
|
|
|
/* Internal function declaration */
|
|
const char *_gadget_bridge_toast_type_2_str(gadget_bridge_toast_type_e toast_type)
|
|
{
|
|
switch(toast_type)
|
|
{
|
|
case GADGET_BRIDGE_TOAST_TYPE_ERROR:
|
|
return "error";
|
|
case GADGET_BRIDGE_TOAST_TYPE_WARN:
|
|
return "warn";
|
|
case GADGET_BRIDGE_TOAST_TYPE_INFO:
|
|
default:
|
|
return "info";
|
|
}
|
|
} |