mirror of
https://github.com/DashyFox/StackSport.git
synced 2025-05-04 15:20:16 +00:00
128 lines
2.5 KiB
C
128 lines
2.5 KiB
C
/*
|
|
* IR_CMD_Handler.c
|
|
*
|
|
* Created on: Aug 25, 2024
|
|
* Author: DashyFox
|
|
*/
|
|
|
|
#include "IR_CMD_Handler.h"
|
|
#include "IR.h"
|
|
#include "SimpleTimer.h"
|
|
#include "ShiftReg.h"
|
|
#include "Print.h"
|
|
|
|
|
|
#define IR_Timeout 137
|
|
#define ResetInputProgerss_Timeout 2500
|
|
#define NULL_NumberParam 0xFFFF
|
|
|
|
//extern unsigned char IR_Command;
|
|
//extern unsigned char IR_Address;
|
|
extern unsigned char IRStatus;
|
|
|
|
IRData data;
|
|
IRData old_data;
|
|
|
|
uint32_t IR_Timeout_timer = 0;
|
|
uint8_t dataHandled_flag = 0;
|
|
|
|
uint32_t inputInProgerss_timer = 0;
|
|
uint8_t inputInProgerss = 0;
|
|
uint8_t digitInputInProgerss = 0;
|
|
|
|
uint8_t inputDigit = 0; // left = 0 to right
|
|
|
|
uint16_t inputParam = NULL_NumberParam;
|
|
|
|
void IR_Home_Process();
|
|
|
|
|
|
void IR_ParamEnter();
|
|
void IR_CMD_Clear();
|
|
void (*InputHandler)(void) = IR_Home_Process;
|
|
void NullFunc(){};
|
|
void (*onParamEnter)() = NullFunc;
|
|
void paramEnter(void(*onEnter_)()){
|
|
InputHandler = IR_ParamEnter;
|
|
onParamEnter = onEnter_;
|
|
|
|
}
|
|
|
|
void IR_CMD_Handler() {
|
|
|
|
// timeout tick
|
|
if (dataHandled_flag && (millis() - IR_Timeout_timer > IR_Timeout)) {
|
|
dataHandled_flag = 0;
|
|
}
|
|
if (inputInProgerss
|
|
&& (millis() - inputInProgerss_timer > ResetInputProgerss_Timeout)) {
|
|
IR_CMD_Clear();
|
|
}
|
|
|
|
// cmd handler
|
|
if (IR_Available()) {
|
|
data = getIRData();
|
|
|
|
IR_Timeout_timer = millis();
|
|
// works once per button press
|
|
if (memcmp(&data, &old_data, sizeof(IRData)) != 0
|
|
|| !dataHandled_flag) {
|
|
dataHandled_flag = 1;
|
|
if (IR_Address == 0x01) {
|
|
InputHandler();
|
|
inputInProgerss = 1;
|
|
inputInProgerss_timer = millis();
|
|
}
|
|
memcpy(&old_data, &data, sizeof(IRData));
|
|
}
|
|
IR_Timeout_timer = millis();
|
|
ClearIRStatus();
|
|
}
|
|
}
|
|
|
|
void IR_CMD_Clear() {
|
|
|
|
InputHandler = IR_Home_Process;
|
|
inputDigit = 0;
|
|
inputInProgerss = 0;
|
|
digitInputInProgerss = 0;
|
|
inputParam = NULL_NumberParam;
|
|
SetShiftReg_inline(0, 0xff, 0);
|
|
}
|
|
|
|
void IR_ParamEnter() {
|
|
SetShiftReg_inline(0x03, 0, 0);
|
|
if (0 <= data.command && data.command <= 9) {
|
|
if (digitInputInProgerss) {
|
|
inputParam = inputParam * 10; // dec shift << 1
|
|
inputParam += (data.command + 1) % 10;
|
|
SetShiftReg_inline(0xF0, 0, 0);
|
|
} else {
|
|
inputParam = (data.command + 1) % 10;
|
|
}
|
|
digitInputInProgerss = 1;
|
|
} else {
|
|
digitInputInProgerss = 0;
|
|
switch (data.command) {
|
|
|
|
case IR_ENTER:
|
|
if(inputParam != NULL_NumberParam){
|
|
print("Enter: ");
|
|
printNumber(inputParam);
|
|
SetShiftReg_inline(0, 0, inputParam);
|
|
onParamEnter();
|
|
}
|
|
inputParam = NULL_NumberParam;
|
|
digitInputInProgerss = 0;
|
|
break;
|
|
|
|
default:
|
|
IR_Home_Process();
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|