SystemK/Events/KEvents.h
Joe Kearney edf80ba83b Cleanup
2025-11-22 14:16:01 -06:00

108 lines
4.2 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/>.
*/
/** \file
* \brief This file defines the events used by the KTag system (SystemK).
*
*/
#ifndef EVENTS_H
#define EVENTS_H
//! Event identifiers used by the SystemK.
typedef enum
{
KEVENT_NO_EVENT = 0,
//! For #KEVENT_UNSUCCESSFUL_SYSTEMK_RESULT, #KEvent_T::Data contains a #SystemKResult_T indicating the nature of the failure.
KEVENT_UNSUCCESSFUL_SYSTEMK_RESULT = 1,
KEVENT_AUTOMATIC_TRANSITION = 2,
KEVENT_CAPSENSE_ONE_PRESSED = 3,
KEVENT_CAPSENSE_ONE_RELEASED = 4,
KEVENT_CAPSENSE_TWO_PRESSED = 5,
KEVENT_CAPSENSE_TWO_RELEASED = 6,
KEVENT_TRIGGER_SWITCH_PRESSED = 7,
KEVENT_CENTER_SWITCH_PRESSED = KEVENT_TRIGGER_SWITCH_PRESSED,
KEVENT_TRIGGER_SWITCH_RELEASED = 8,
//! For #KEVENT_CENTER_SWITCH_RELEASED, #KEvent_T::Data contains the duration of the press in milliseconds.
KEVENT_CENTER_SWITCH_RELEASED = KEVENT_TRIGGER_SWITCH_RELEASED,
KEVENT_UP_SWITCH_PRESSED = 9,
KEVENT_UP_SWITCH_LONG_PRESSED = 10,
KEVENT_UP_SWITCH_RELEASED = 11,
KEVENT_DOWN_SWITCH_PRESSED = 12,
KEVENT_DOWN_SWITCH_LONG_PRESSED = 13,
KEVENT_DOWN_SWITCH_RELEASED = 14,
KEVENT_FORWARD_SWITCH_PRESSED = 15,
KEVENT_FORWARD_SWITCH_LONG_PRESSED = 16,
KEVENT_FORWARD_SWITCH_RELEASED = 17,
KEVENT_BACKWARD_SWITCH_PRESSED = 18,
KEVENT_BACKWARD_SWITCH_LONG_PRESSED = 19,
KEVENT_BACKWARD_SWITCH_RELEASED = 20,
KEVENT_TAG_SENT = 21,
//! For #KEVENT_TAG_RECEIVED, #KEvent_T::Data points to #TagPacket_T.
KEVENT_TAG_RECEIVED = 22,
KEVENT_TAGGED_OUT = 23,
KEVENT_MISFIRE = 24,
KEVENT_NEAR_MISS = 25,
//! For #KEVENT_BLE_PACKET_RECEIVED, #KEvent_T::Data points to #COMM_BLE_Packet_T.
KEVENT_BLE_PACKET_RECEIVED = 26,
//! For #KEVENT_COMMAND_RECEIVED, #KEvent_T::Data points to #CommandPacket_T.
KEVENT_COMMAND_RECEIVED = 27,
KEVENT_MENU_ENTER = 28,
KEVENT_MENU_SELECT = 29,
KEVENT_MENU_BACK = 30,
KEVENT_MENU_UP = 31,
KEVENT_MENU_DOWN = 32,
KEVENT_MENU_EXIT = 33,
KEVENT_REPROGRAM = 34,
//! For #KEVENT_ACCESSORY_SWITCH_PRESSED, #KEvent_T::Data contains the duration the switch has not been pressed in milliseconds.
KEVENT_ACCESSORY_SWITCH_PRESSED = 35,
//! For #KEVENT_ACCESSORY_SWITCH_PRESSED, #KEvent_T::Data contains the duration of the press in milliseconds.
KEVENT_ACCESSORY_SWITCH_RELEASED = 36,
//! For #KEVENT_AUDIO_COMPLETED, #KEvent_T::Data contains the AudioActionID_T of the completed action.
KEVENT_AUDIO_COMPLETED = 37,
KEVENT_GAME_OVER = 38,
KEVENT_PLAY_PRESSED_ON_REMOTE = 39,
//! For #KEVENT_BLE_EVENT_RECEIVED, #KEvent_T::Data contains the BLE_EventID_T of the received event.
KEVENT_BLE_EVENT_RECEIVED = 40,
// KEVENT_IS_OUT_OF_RANGE is one more than the last valid event.
KEVENT_IS_OUT_OF_RANGE
} KEvent_ID_T;
//! Events used by the SystemK.
/*!
* The #Data is event-dependent.
*/
typedef struct
{
KEvent_ID_T ID;
void *Data;
} KEvent_T;
// Verify the pointer size, since sometimes we store uint32_t's in the KEvent_T::Data pointer.
_Static_assert(sizeof(uintptr_t) >= sizeof(uint32_t), "Pointer size is less than 32 bits! KEvents will not work properly on this system.");
void Init_KEvents(void);
void Post_KEvent(KEvent_T *event);
void Post_KEvent_From_ISR(KEvent_T *event, portBASE_TYPE *xHigherPriorityTaskWoken);
portBASE_TYPE Receive_KEvent(KEvent_T *event);
#endif // EVENTS_H