Lots of refactoring

This commit is contained in:
2025-06-11 10:55:00 -05:00
parent a437bcf8b5
commit aaa7f0dc29
35 changed files with 1165 additions and 809 deletions

View File

@@ -8,7 +8,11 @@
#ifndef PORTS_H_
#define PORTS_H_
typedef struct ACCESSORY_s ACCESSORY_t;
typedef int (*AccessoryHandler_t)(ACCESSORY_t *accy);
typedef enum {
ID_BROADCAST = -1,
ID_ERROR = 0, //0V should never happen. Error condition
ID_TX_SINGLE_DIRECT, //Transmitter accessory
ID_TX_DUAL_DIRECT, //Transmitter accessory
@@ -24,14 +28,46 @@ typedef enum {
ID_NUM
}ACCY_ID_t;
typedef enum
{
PORT_STATE_DEINIT = -1,
PORT_STATE_INIT = 0,
} PortState_t;
typedef struct {
typedef enum
{
ACCY_PORT_INDUCTION = -1,
ACCY_PORT_1 = 0,
ACCY_PORT_2 = 1,
NUM_PORTS
} AccessoryPortId_t;
typedef enum
{
CHANNEL_A = 0,
CHANNEL_B,
NUM_CHANNELS
} AccyChannelId_t;
typedef struct
{
AccyChannelId_t id;
bool connected;
} AccessoryChannel_t;
struct ACCESSORY_s {
bool isConnected; //Accessory is connected
ACCY_ID_t connected; //Currently connected accessory
ACCY_ID_t lastDetected; //accessory detected last scan
uint32_t consecutiveScans; //number of consecutive scans of same accessory
float *idVoltage;
PortState_t state;
bool initState;
AccessoryHandler_t handler;
}ACCESSORY_t;
AccessoryChannel_t channels[NUM_CHANNELS];
};
#define DELAY_100MS 10
#define DELAY_ONE_SECOND 100
@@ -57,6 +93,7 @@ typedef enum {
void ACCY_Init(void);
bool ACCY_isKnown(ACCY_ID_t id);
void ACCY_Update1(void);
void ACCY_Update2(void);
void Read_Tx_Ports(void); // check for whats plugged in at the ports.