Implemented BLE Quiet.
This commit is contained in:
parent
c514219ccc
commit
1a27af361d
5 changed files with 68 additions and 6 deletions
|
@ -22,6 +22,7 @@
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
#include "SystemK.h"
|
||||||
|
|
||||||
const uint8_t BLE_BROADCAST_ADDRESS[6] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
|
const uint8_t BLE_BROADCAST_ADDRESS[6] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
|
||||||
|
|
||||||
|
@ -52,3 +53,59 @@ const char *BLE_ADDR_To_Str(const uint8_t bd_addr[6])
|
||||||
str_addr[17] = '\0'; // Ensure null termination.
|
str_addr[17] = '\0'; // Ensure null termination.
|
||||||
return str_addr;
|
return str_addr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SystemKResult_T BLE_HandleCommonEvents(KEvent_T *event)
|
||||||
|
{
|
||||||
|
SystemKResult_T result = SYSTEMK_RESULT_EVENT_NOT_HANDLED;
|
||||||
|
|
||||||
|
if (event->ID == KEVENT_BLE_PACKET_RECEIVED)
|
||||||
|
{
|
||||||
|
BLE_Packet_T * packet = (BLE_Packet_T *)event->Data;
|
||||||
|
|
||||||
|
if (packet->Generic.type == BLE_PACKET_TYPE_EVENT)
|
||||||
|
{
|
||||||
|
BLE_EventPacket_T * event_packet = (BLE_EventPacket_T *)packet;
|
||||||
|
|
||||||
|
if (BLE_IsBLEPacketForMe(event_packet->target_BD_ADDR))
|
||||||
|
{
|
||||||
|
if (BLE_IsPacketNew(event_packet->BD_ADDR, BLE_PACKET_TYPE_EVENT, event_packet->event_number))
|
||||||
|
{
|
||||||
|
if (event_packet->event_ID == BLE_EVENT_QUIET)
|
||||||
|
{
|
||||||
|
uint32_t duration_ms = event_packet->event_data;
|
||||||
|
if (BLE_Quiet(duration_ms) == SYSTEMK_RESULT_SUCCESS)
|
||||||
|
{
|
||||||
|
if (duration_ms > 0)
|
||||||
|
{
|
||||||
|
KLOG_INFO("BLE", "Quiet mode activated for %lu ms.", duration_ms);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
KLOG_INFO("BLE", "Quiet mode activated until further notice.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
KLOG_ERROR("BLE", "Failed to activate quiet mode.");
|
||||||
|
}
|
||||||
|
result = SYSTEMK_RESULT_SUCCESS;
|
||||||
|
}
|
||||||
|
else if (event_packet->event_ID == BLE_EVENT_UNQUIET)
|
||||||
|
{
|
||||||
|
if (BLE_Unquiet() == SYSTEMK_RESULT_SUCCESS)
|
||||||
|
{
|
||||||
|
KLOG_INFO("BLE", "Quiet mode deactivated.");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
KLOG_ERROR("BLE", "Failed to deactivate quiet mode.");
|
||||||
|
}
|
||||||
|
result = SYSTEMK_RESULT_SUCCESS;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
|
@ -22,3 +22,4 @@
|
||||||
extern const uint8_t BLE_BROADCAST_ADDRESS[6];
|
extern const uint8_t BLE_BROADCAST_ADDRESS[6];
|
||||||
|
|
||||||
const char* BLE_ADDR_To_Str(const uint8_t bd_addr[6]);
|
const char* BLE_ADDR_To_Str(const uint8_t bd_addr[6]);
|
||||||
|
SystemKResult_T BLE_HandleCommonEvents(KEvent_T *event);
|
|
@ -61,8 +61,12 @@ void Init_KEvents(void)
|
||||||
void Post_KEvent(KEvent_T *event)
|
void Post_KEvent(KEvent_T *event)
|
||||||
{
|
{
|
||||||
Remap_Event(event);
|
Remap_Event(event);
|
||||||
|
if (BLE_HandleCommonEvents(event) == SYSTEMK_RESULT_EVENT_NOT_HANDLED)
|
||||||
|
{
|
||||||
|
// If the event was not handled by the BLE subsystem, post it to the global event queue.
|
||||||
xQueueSend(xQueueEvents, event, 0);
|
xQueueSend(xQueueEvents, event, 0);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void Post_KEvent_From_ISR(KEvent_T *event, portBASE_TYPE *xHigherPriorityTaskWoken)
|
void Post_KEvent_From_ISR(KEvent_T *event, portBASE_TYPE *xHigherPriorityTaskWoken)
|
||||||
{
|
{
|
||||||
|
|
|
@ -44,7 +44,8 @@ typedef enum
|
||||||
SYSTEMK_RESULT_READ_FAILED,
|
SYSTEMK_RESULT_READ_FAILED,
|
||||||
SYSTEMK_RESULT_WRITE_FAILED,
|
SYSTEMK_RESULT_WRITE_FAILED,
|
||||||
SYSTEMK_RESULT_OVERFLOW,
|
SYSTEMK_RESULT_OVERFLOW,
|
||||||
SYSTEMK_RESULT_UNDERFLOW
|
SYSTEMK_RESULT_UNDERFLOW,
|
||||||
|
SYSTEMK_RESULT_EVENT_NOT_HANDLED
|
||||||
} SystemKResult_T;
|
} SystemKResult_T;
|
||||||
|
|
||||||
#endif // RESULTS_H
|
#endif // RESULTS_H
|
||||||
|
|
|
@ -34,8 +34,7 @@ static TickType_t xBLEConfigurationResponseTimerPeriod = 3000 / portTICK_PERIOD_
|
||||||
|
|
||||||
static void BLEConfigurationResponseTimerCallback(TimerHandle_t xTimer)
|
static void BLEConfigurationResponseTimerCallback(TimerHandle_t xTimer)
|
||||||
{
|
{
|
||||||
// Don't send HELLO packets once configuration has started.
|
BLE_UpdateHelloPacket();
|
||||||
BLE_StopAdvertising();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#define MAX_MENU_DEPTH 10
|
#define MAX_MENU_DEPTH 10
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue