FEATURE: history tracking
This commit is contained in:
parent
2c47d7385b
commit
53ba4faa70
@ -1,10 +0,0 @@
|
||||
//
|
||||
// Created by robtor on 16.12.22.
|
||||
//
|
||||
|
||||
#ifndef FLOATPUMP_BUTTON_INPUT_H
|
||||
#define FLOATPUMP_BUTTON_INPUT_H
|
||||
|
||||
#include <stdbool.h>
|
||||
|
||||
#endif //FLOATPUMP_BUTTON_INPUT_H
|
@ -7,6 +7,6 @@
|
||||
|
||||
// Auto generated header file containing the last git revision
|
||||
|
||||
#define GIT_HASH "af8a022"
|
||||
#define GIT_HASH "8f1aed9"
|
||||
|
||||
#endif //FLOATPUMP_GIT_REVISION_TEMPLATE_H
|
@ -56,6 +56,7 @@ void DebugMon_Handler(void);
|
||||
void PendSV_Handler(void);
|
||||
void SysTick_Handler(void);
|
||||
void TIM2_IRQHandler(void);
|
||||
void TIM3_IRQHandler(void);
|
||||
void OTG_FS_IRQHandler(void);
|
||||
/* USER CODE BEGIN EFP */
|
||||
|
||||
|
@ -1,30 +0,0 @@
|
||||
//
|
||||
// Created by robtor on 16.12.22.
|
||||
//
|
||||
#include "main.h"
|
||||
#include "button_input.h"
|
||||
|
||||
bool rot_button = false;
|
||||
uint16_t rot_counter = 0;
|
||||
|
||||
void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim) {
|
||||
static uint16_t rot_state = 0;
|
||||
static uint16_t btn_state = 0;
|
||||
|
||||
rot_state = (rot_state << 1) | (HAL_GPIO_ReadPin(RRCLK_GPIO_Port, RRCLK_Pin) == GPIO_PIN_SET ? 0x1 : 0x0) | 0xe000;
|
||||
|
||||
btn_state = (btn_state << 1) | (HAL_GPIO_ReadPin(RRSW_GPIO_Port, RRSW_Pin) == GPIO_PIN_SET ? 0x1 : 0x0) | 0xe000;
|
||||
|
||||
if (rot_state == 0xf000) {
|
||||
rot_state = 0x0000;
|
||||
if (HAL_GPIO_ReadPin(RRDT_GPIO_Port, RRDT_Pin) == GPIO_PIN_SET) {
|
||||
rot_counter++;
|
||||
} else {
|
||||
rot_counter--;
|
||||
}
|
||||
}
|
||||
|
||||
if (btn_state == 0xf000) {
|
||||
rot_button = true;
|
||||
}
|
||||
}
|
41
Core/Src/custom_callbacks.c
Normal file
41
Core/Src/custom_callbacks.c
Normal file
@ -0,0 +1,41 @@
|
||||
//
|
||||
// Created by robtor on 16.12.22.
|
||||
//
|
||||
#include "main.h"
|
||||
|
||||
extern TIM_HandleTypeDef htim2;
|
||||
extern TIM_HandleTypeDef htim3;
|
||||
|
||||
bool rot_button = false;
|
||||
uint16_t rot_counter = 0;
|
||||
uint16_t minute_counter = 0;
|
||||
|
||||
void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim) {
|
||||
static uint16_t rot_state = 0;
|
||||
static uint16_t btn_state = 0;
|
||||
|
||||
if(htim == &htim2) {
|
||||
|
||||
rot_state =
|
||||
(rot_state << 1) | (HAL_GPIO_ReadPin(RRCLK_GPIO_Port, RRCLK_Pin) == GPIO_PIN_SET ? 0x1 : 0x0) | 0xe000;
|
||||
|
||||
btn_state =
|
||||
(btn_state << 1) | (HAL_GPIO_ReadPin(RRSW_GPIO_Port, RRSW_Pin) == GPIO_PIN_SET ? 0x1 : 0x0) | 0xe000;
|
||||
|
||||
if (rot_state == 0xf000) {
|
||||
rot_state = 0x0000;
|
||||
if (HAL_GPIO_ReadPin(RRDT_GPIO_Port, RRDT_Pin) == GPIO_PIN_SET) {
|
||||
rot_counter++;
|
||||
} else {
|
||||
rot_counter--;
|
||||
}
|
||||
}
|
||||
|
||||
if (btn_state == 0xf000) {
|
||||
rot_button = true;
|
||||
}
|
||||
|
||||
} else if (htim == &htim3) {
|
||||
minute_counter++;
|
||||
}
|
||||
}
|
@ -4,7 +4,6 @@
|
||||
|
||||
#include "LCD_I2C_Driver.h"
|
||||
#include "InitSequence.h"
|
||||
#include "button_input.h"
|
||||
#include "Config_Store.h"
|
||||
#include "Menu_Controller.h"
|
||||
#include "PressureChannel.h"
|
||||
@ -18,6 +17,7 @@ ADC_HandleTypeDef hadc1;
|
||||
I2C_HandleTypeDef hi2c1;
|
||||
RTC_HandleTypeDef hrtc;
|
||||
TIM_HandleTypeDef htim2;
|
||||
TIM_HandleTypeDef htim3;
|
||||
UART_HandleTypeDef huart1;
|
||||
|
||||
|
||||
@ -33,10 +33,13 @@ static void MX_I2C1_Init(void);
|
||||
|
||||
static void MX_TIM2_Init(void);
|
||||
|
||||
static void MX_TIM3_Init(void);
|
||||
|
||||
static void MX_USART1_UART_Init(void);
|
||||
|
||||
extern int16_t rot_counter;
|
||||
extern uint16_t rot_counter;
|
||||
extern bool rot_button;
|
||||
extern uint16_t minute_counter;
|
||||
|
||||
using namespace floatpump;
|
||||
|
||||
@ -124,6 +127,7 @@ int main(void) {
|
||||
MX_GPIO_Init();
|
||||
//MX_RTC_Init();
|
||||
MX_TIM2_Init();
|
||||
MX_TIM3_Init();
|
||||
MX_USB_DEVICE_Init();
|
||||
MX_ADC1_Init();
|
||||
MX_I2C1_Init();
|
||||
@ -195,6 +199,12 @@ int main(void) {
|
||||
Menu_Controller controller(&mainmenu, display);
|
||||
static int old_pos = 0;
|
||||
|
||||
static int8_t history_h[59];
|
||||
static int8_t history_d[23];
|
||||
|
||||
static uint16_t old_minute_counter = minute_counter;
|
||||
|
||||
|
||||
while (1) {
|
||||
|
||||
display.LCDSetBacklight(S_backlight);
|
||||
@ -323,6 +333,13 @@ int main(void) {
|
||||
CheckTankConditions(Config_Store::getInstance(), tankLevel0, tankPump);
|
||||
CheckRefillConditions(Config_Store::getInstance(), tankLevel0, refillBlocker0, refillPump);
|
||||
|
||||
//Create history
|
||||
if(old_minute_counter < minute_counter) {
|
||||
old_minute_counter = minute_counter;
|
||||
history_h[minute_counter%60] = tankLevel0.getPercent();
|
||||
history_d[minute_counter/60] = tankLevel0.getPercent();
|
||||
}
|
||||
|
||||
HAL_GPIO_WritePin(LED2_GPIO_Port, LED2_Pin, GPIO_PIN_SET);
|
||||
HAL_Delay(1000);
|
||||
}
|
||||
@ -534,6 +551,44 @@ static void MX_TIM2_Init(void) {
|
||||
|
||||
}
|
||||
|
||||
static void MX_TIM3_Init(void) {
|
||||
//Timer has input of 24MHZ
|
||||
//Scale down with prescaler to 10kHz
|
||||
//Auto reload each ms
|
||||
|
||||
/* USER CODE BEGIN TIM2_Init 0 */
|
||||
|
||||
/* USER CODE END TIM2_Init 0 */
|
||||
|
||||
TIM_ClockConfigTypeDef sClockSourceConfig = {0};
|
||||
|
||||
/* USER CODE BEGIN TIM2_Init 1 */
|
||||
|
||||
/* USER CODE END TIM2_Init 1 */
|
||||
htim3.Instance = TIM3;
|
||||
htim3.Init.Prescaler = 24000;
|
||||
htim3.Init.CounterMode = TIM_COUNTERMODE_UP;
|
||||
htim3.Init.Period = 59000;
|
||||
htim3.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
|
||||
htim3.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_ENABLE;
|
||||
if (HAL_TIM_Base_Init(&htim3) != HAL_OK) {
|
||||
Error_Handler();
|
||||
|
||||
}
|
||||
sClockSourceConfig.ClockSource = TIM_CLOCKSOURCE_INTERNAL;
|
||||
if (HAL_TIM_ConfigClockSource(&htim3, &sClockSourceConfig) != HAL_OK) {
|
||||
Error_Handler();
|
||||
}
|
||||
|
||||
//HAL_TIM_Base_Start(&htim2);
|
||||
//Directly start timer base generation in interrupt mode
|
||||
HAL_TIM_Base_Start_IT(&htim3);
|
||||
/* USER CODE BEGIN TIM2_Init 2 */
|
||||
|
||||
/* USER CODE END TIM2_Init 2 */
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USART1 Initialization Function
|
||||
* @param None
|
||||
|
@ -276,9 +276,13 @@ void HAL_TIM_Base_MspInit(TIM_HandleTypeDef* htim_base)
|
||||
/* USER CODE END TIM2_MspInit 0 */
|
||||
/* Peripheral clock enable */
|
||||
__HAL_RCC_TIM2_CLK_ENABLE();
|
||||
__HAL_RCC_TIM3_CLK_ENABLE();
|
||||
/* TIM2 interrupt Init */
|
||||
HAL_NVIC_SetPriority(TIM2_IRQn, 0, 0);
|
||||
HAL_NVIC_EnableIRQ(TIM2_IRQn);
|
||||
|
||||
HAL_NVIC_SetPriority(TIM3_IRQn, 0, 0);
|
||||
HAL_NVIC_EnableIRQ(TIM3_IRQn);
|
||||
/* USER CODE BEGIN TIM2_MspInit 1 */
|
||||
|
||||
/* USER CODE END TIM2_MspInit 1 */
|
||||
@ -309,6 +313,12 @@ void HAL_TIM_Base_MspDeInit(TIM_HandleTypeDef* htim_base)
|
||||
/* USER CODE END TIM2_MspDeInit 1 */
|
||||
}
|
||||
|
||||
if(htim_base->Instance==TIM3)
|
||||
{
|
||||
__HAL_RCC_TIM3_CLK_DISABLE();
|
||||
HAL_NVIC_DisableIRQ(TIM3_IRQn);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -57,6 +57,7 @@
|
||||
/* External variables --------------------------------------------------------*/
|
||||
extern PCD_HandleTypeDef hpcd_USB_OTG_FS;
|
||||
extern TIM_HandleTypeDef htim2;
|
||||
extern TIM_HandleTypeDef htim3;
|
||||
/* USER CODE BEGIN EV */
|
||||
|
||||
/* USER CODE END EV */
|
||||
@ -214,6 +215,11 @@ void TIM2_IRQHandler(void)
|
||||
/* USER CODE END TIM2_IRQn 1 */
|
||||
}
|
||||
|
||||
void TIM3_IRQHandler(void)
|
||||
{
|
||||
HAL_TIM_IRQHandler(&htim3);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief This function handles USB On The Go FS global interrupt.
|
||||
*/
|
||||
|
Loading…
Reference in New Issue
Block a user