significant progress on frontend
This commit is contained in:
@ -10,7 +10,7 @@
|
||||
|
||||
|
||||
|
||||
static volatile uint16_t frontendAdcThreshold = 0;
|
||||
static volatile int32_t frontendAdcThreshold = 240;
|
||||
static volatile bool frontendEnabled = false;
|
||||
|
||||
|
||||
@ -34,10 +34,36 @@ void frontendDisable() {
|
||||
}
|
||||
|
||||
void frontendAdcCallback(ADC_HandleTypeDef* hadc) {
|
||||
static int32_t holdValue = 0;
|
||||
static uint32_t cnt = 0;
|
||||
|
||||
HAL_GPIO_TogglePin(Debug_Signal_1_GPIO_Port, Debug_Signal_1_Pin);
|
||||
uint32_t rawValue = HAL_ADC_GetValue(hadc);
|
||||
if (rawValue > frontendAdcThreshold) {
|
||||
HAL_GPIO_TogglePin(Frontend_Out_GPIO_Port, Frontend_Out_Pin);
|
||||
|
||||
if (frontendEnabled) {
|
||||
int32_t currentValue = (int32_t) HAL_ADC_GetValue(hadc);
|
||||
|
||||
if (holdValue == 0) {
|
||||
holdValue = currentValue;
|
||||
logMsg("frontend enabled, hold: %d", holdValue);
|
||||
}
|
||||
|
||||
if (currentValue - holdValue > frontendAdcThreshold) {
|
||||
HAL_GPIO_WritePin(Frontend_Out_GPIO_Port, Frontend_Out_Pin, GPIO_PIN_SET);
|
||||
cnt++;
|
||||
if (cnt > 25) {
|
||||
logMsg("frontend, high: %d, hold: %d, diff: %d", currentValue, holdValue, currentValue - holdValue);
|
||||
cnt = 0;
|
||||
}
|
||||
} else {
|
||||
HAL_GPIO_WritePin(Frontend_Out_GPIO_Port, Frontend_Out_Pin, GPIO_PIN_RESET);
|
||||
cnt = 0;
|
||||
}
|
||||
} else {
|
||||
if (holdValue != 0) {
|
||||
holdValue = 0;
|
||||
HAL_GPIO_WritePin(Frontend_Out_GPIO_Port, Frontend_Out_Pin, GPIO_PIN_SET);
|
||||
logMsg("frontend disabled");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user