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;
|
static volatile bool frontendEnabled = false;
|
||||||
|
|
||||||
|
|
||||||
@ -34,10 +34,36 @@ void frontendDisable() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void frontendAdcCallback(ADC_HandleTypeDef* hadc) {
|
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);
|
HAL_GPIO_TogglePin(Debug_Signal_1_GPIO_Port, Debug_Signal_1_Pin);
|
||||||
uint32_t rawValue = HAL_ADC_GetValue(hadc);
|
|
||||||
if (rawValue > frontendAdcThreshold) {
|
if (frontendEnabled) {
|
||||||
HAL_GPIO_TogglePin(Frontend_Out_GPIO_Port, Frontend_Out_Pin);
|
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");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -39,7 +39,7 @@ void my_setup_2() {
|
|||||||
|
|
||||||
frontendInit();
|
frontendInit();
|
||||||
|
|
||||||
schAdd(helloMeterbus, NULL, 0, 10000);
|
schAdd(helloMeterbus, NULL, 0, 1000);
|
||||||
}
|
}
|
||||||
|
|
||||||
void my_loop() {
|
void my_loop() {
|
||||||
|
@ -5,13 +5,16 @@
|
|||||||
#include <loopCtrl.h>
|
#include <loopCtrl.h>
|
||||||
#include <led.h>
|
#include <led.h>
|
||||||
#include <logger.h>
|
#include <logger.h>
|
||||||
|
#include <frontend.h>
|
||||||
|
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
IDLE,
|
IDLE,
|
||||||
SEND,
|
SEND,
|
||||||
SEND_CONT,
|
SEND_CONT,
|
||||||
SENDING
|
SENDING,
|
||||||
|
ENABLE_FRONTEND,
|
||||||
|
DISABLE_FRONTEND
|
||||||
} e_mbusCommState;
|
} e_mbusCommState;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
@ -56,19 +59,34 @@ static void handleRequestEngine(void *handle) {
|
|||||||
localMbusCommHandle->retryCnt = 0;
|
localMbusCommHandle->retryCnt = 0;
|
||||||
HAL_UART_Transmit_IT(&mbusUart, localMbusCommHandle->sendBuf, 5);
|
HAL_UART_Transmit_IT(&mbusUart, localMbusCommHandle->sendBuf, 5);
|
||||||
localMbusCommHandle->state = SENDING;
|
localMbusCommHandle->state = SENDING;
|
||||||
schAdd(handleRequestEngine, handle, 5, 0); // ask me again in 1ms in the next state ...
|
schAdd(handleRequestEngine, handle, 15, 0); // ask me again in 15ms in the next state ...
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case SENDING:
|
case SENDING:
|
||||||
logMsg("hre state SENDING");
|
logMsg("hre state SENDING");
|
||||||
if (HAL_UART_GetState(&mbusUart) == HAL_UART_STATE_READY) { // ... whether I'm done
|
if (HAL_UART_GetState(&mbusUart) == HAL_UART_STATE_READY) { // ... whether I'm done
|
||||||
localMbusCommHandle->state = IDLE;
|
localMbusCommHandle->state = ENABLE_FRONTEND;
|
||||||
|
schAdd(handleRequestEngine, handle, 3, 0);
|
||||||
} else {
|
} else {
|
||||||
schAdd(handleRequestEngine, handle, 5, 0); // not yet done, ask me again in 1ms
|
schAdd(handleRequestEngine, handle, 1, 0); // not yet done, ask me again in 1ms
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case ENABLE_FRONTEND:
|
||||||
|
logMsg("hre state ENABLE_FRONTEND");
|
||||||
|
frontendEnable();
|
||||||
|
localMbusCommHandle->state = DISABLE_FRONTEND;
|
||||||
|
schAdd(handleRequestEngine, handle, 20, 0);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case DISABLE_FRONTEND:
|
||||||
|
logMsg("hre state DISABLE_FRONTEND");
|
||||||
|
frontendDisable();
|
||||||
|
localMbusCommHandle->state = IDLE;
|
||||||
|
break;
|
||||||
|
|
||||||
|
|
||||||
default:
|
default:
|
||||||
localMbusCommHandle->state = IDLE;
|
localMbusCommHandle->state = IDLE;
|
||||||
break;
|
break;
|
||||||
|
Reference in New Issue
Block a user