mirror of
https://github.com/DashyFox/StackSport.git
synced 2025-05-04 07:10:17 +00:00
164 lines
3.2 KiB
C
164 lines
3.2 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 "Print.h"
|
|
#include "ShiftReg.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;
|
|
|
|
unsigned char b1 = 1;
|
|
unsigned char b2 = 1;
|
|
unsigned char b3 = 1;
|
|
|
|
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 inputNumberParam = NULL_NumberParam;
|
|
|
|
enum IR_MENU {
|
|
IR_MENU_Home,
|
|
|
|
IR_MENU_SHOT, IR_MENU_PROGR, IR_MENU_MACRO, IR_MENU_,
|
|
|
|
};
|
|
|
|
void IR_Home_Process();
|
|
void IR_Shot_Selection();
|
|
|
|
void IR_CMD_Clear();
|
|
|
|
void (*InputHandler)(void) = IR_Home_Process;
|
|
|
|
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) {
|
|
printNumber(data.command);
|
|
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;
|
|
inputNumberParam = NULL_NumberParam;
|
|
SetShiftReg_inline(0, 0xff, 0);
|
|
}
|
|
|
|
void IR_Home_Process() {
|
|
InputHandler = IR_Home_Process;
|
|
SetShiftReg_inline(0xff, 0, 0);
|
|
switch (data.command) {
|
|
case IR_FONT_RIGHT:
|
|
InputHandler = IR_Shot_Selection;
|
|
break;
|
|
|
|
// case IR_FONT_RIGHT:
|
|
// // if(!(b1>64 || b2> 64|| b3>64)) b1 = 64;
|
|
// // else
|
|
// // {
|
|
// // b1 = b1>>1;
|
|
// // b2 = b2<<1;
|
|
// // b3 = b3<<1;
|
|
// // }
|
|
// SetShiftReg_inline(b1, b2, b3);
|
|
// break;
|
|
case IR_FRONT_MID:
|
|
SetShiftReg_inline(0, 0, 0);
|
|
b1 = b2 = b3 = 0;
|
|
break;
|
|
case IR_FRONT_LEFT:
|
|
// if(!b3)
|
|
// b3 = 128;
|
|
// b3 = b3>>1;
|
|
// if(!b3)
|
|
// b2 = 64;
|
|
|
|
SetShiftReg_inline(++b1, ++b2, ++b3);
|
|
break;
|
|
|
|
default:
|
|
break;
|
|
}
|
|
|
|
}
|
|
|
|
void IR_Shot_Selection() { // Сделать общим
|
|
SetShiftReg_inline(0x03, 0, 0);
|
|
if (0 <= data.command && data.command <= 9) {
|
|
if (digitInputInProgerss) {
|
|
inputNumberParam = inputNumberParam * 10; // dec shift << 1
|
|
inputNumberParam += data.command + 1;
|
|
SetShiftReg_inline(0xF0, 0, 0);
|
|
} else {
|
|
inputNumberParam = data.command + 1;
|
|
}
|
|
digitInputInProgerss = 1;
|
|
} else {
|
|
digitInputInProgerss = 0;
|
|
switch (data.command) {
|
|
|
|
case IR_ENTER:
|
|
if(inputNumberParam != NULL_NumberParam){
|
|
SetShiftReg_inline(0, 0, inputNumberParam);
|
|
}
|
|
inputNumberParam = NULL_NumberParam;
|
|
digitInputInProgerss = 0;
|
|
break;
|
|
|
|
default:
|
|
IR_Home_Process();
|
|
break;
|
|
}
|
|
}
|
|
}
|