76 lines
2.1 KiB
C
Executable file
76 lines
2.1 KiB
C
Executable file
|
|
/*
|
|
* This program source code file is part of SystemK, a library in the KTag project.
|
|
*
|
|
* 🛡️ <https://ktag.clubk.club> 🃞
|
|
*
|
|
* Copyright © 2016-2025 Joseph P. Kearney and the KTag developers.
|
|
*
|
|
* This program is free software: you can redistribute it and/or modify it under
|
|
* the terms of the GNU Affero General Public License as published by the Free
|
|
* Software Foundation, either version 3 of the License, or (at your option) any
|
|
* later version.
|
|
*
|
|
* This program is distributed in the hope that it will be useful, but WITHOUT
|
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
|
* FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
|
|
* details.
|
|
*
|
|
* There should be a copy of the GNU Affero General Public License in the LICENSE
|
|
* file in the root of this repository. If not, see <http://www.gnu.org/licenses/>.
|
|
*/
|
|
|
|
#include <stdbool.h>
|
|
#include <stdio.h>
|
|
|
|
#include "SystemK.h"
|
|
#include "Command_Mapping.h"
|
|
|
|
#define QUEUE_LENGTH 10
|
|
#define ITEM_SIZE sizeof(KEvent_T)
|
|
static StaticQueue_t StaticQueue;
|
|
static uint8_t QueueStorageArea[QUEUE_LENGTH * ITEM_SIZE];
|
|
QueueHandle_t xQueueEvents;
|
|
|
|
static void Remap_Event(KEvent_T *event)
|
|
{
|
|
switch (event->ID)
|
|
{
|
|
case KEVENT_COMMAND_RECEIVED:
|
|
{
|
|
if (((DecodedPacket_T *)(event->Data))->Command.protocol == NEC_PROTOCOL)
|
|
{
|
|
uint32_t NEC_data = ((DecodedPacket_T *)(event->Data))->Command.data;
|
|
Remap_NEC_Command(event, NEC_data);
|
|
}
|
|
FreeDecodedPacketBuffer(event->Data);
|
|
}
|
|
break;
|
|
|
|
default:
|
|
// No remapping necessary.
|
|
break;
|
|
}
|
|
}
|
|
|
|
void Init_KEvents(void)
|
|
{
|
|
xQueueEvents = xQueueCreateStatic(QUEUE_LENGTH, ITEM_SIZE, QueueStorageArea, &StaticQueue);
|
|
}
|
|
|
|
void Post_KEvent(KEvent_T *event)
|
|
{
|
|
Remap_Event(event);
|
|
xQueueSend(xQueueEvents, event, 0);
|
|
}
|
|
|
|
void Post_KEvent_From_ISR(KEvent_T *event, portBASE_TYPE *xHigherPriorityTaskWoken)
|
|
{
|
|
Remap_Event(event);
|
|
xQueueSendFromISR(xQueueEvents, event, xHigherPriorityTaskWoken);
|
|
}
|
|
|
|
portBASE_TYPE Receive_KEvent(KEvent_T *event)
|
|
{
|
|
return xQueueReceive(xQueueEvents, event, 0);
|
|
}
|