WIP: Pressure sensing

This commit is contained in:
Robin Dietzel 2023-01-06 16:01:02 +01:00
parent 5c6c69ae10
commit ac2deb5001
2 changed files with 84 additions and 57 deletions

View File

@ -7,6 +7,6 @@
// Auto generated header file containing the last git revision // Auto generated header file containing the last git revision
#define GIT_HASH "6fd24bf" #define GIT_HASH "ff0aed1"
#endif //FLOATPUMP_GIT_REVISION_TEMPLATE_H #endif //FLOATPUMP_GIT_REVISION_TEMPLATE_H

View File

@ -24,7 +24,6 @@ TIM_HandleTypeDef htim2;
UART_HandleTypeDef huart1; UART_HandleTypeDef huart1;
void SystemClock_Config(void); void SystemClock_Config(void);
static void MX_GPIO_Init(void); static void MX_GPIO_Init(void);
@ -62,81 +61,82 @@ int main(void) {
MX_I2C1_Init(); MX_I2C1_Init();
MX_USART1_UART_Init(); MX_USART1_UART_Init();
//Simple dummy lcd test
// char buf[] = "Hallo THM -- es funktioniert";
//
// auto &display = floatpump::LCD_I2C_Driver::getInstance(hi2c1, SLAVE_ADDRESS_LCD);
// display.LCDSetBacklight(false);
// HAL_Delay(1000);
// display.LCDSetBacklight(true);
// display.LCDSendCString(buf);
// HAL_Delay(1000);
// display.LCDPower(false);
// HAL_Delay(1000);
// display.LCDPower(true);
// HAL_Delay(1000);
// display.LCDCursor(true);
// display.LCDCursorBlink(true);
//
// HAL_Delay(1000);
// display.LCDSetCursor(18, 3);
//Disable Interrupt for Debouncing timer during display initalisation (exact timings are necessary)
//Disable Interrupt for Debouncing timer during display initialisation (exact timings are necessary)
HAL_NVIC_DisableIRQ(TIM2_IRQn); HAL_NVIC_DisableIRQ(TIM2_IRQn);
LCD_I2C_Driver &display = floatpump::LCD_I2C_Driver::getInstance(hi2c1, SLAVE_ADDRESS_LCD); LCD_I2C_Driver &display = floatpump::LCD_I2C_Driver::getInstance(hi2c1, SLAVE_ADDRESS_LCD);
HAL_NVIC_EnableIRQ(TIM2_IRQn); HAL_NVIC_EnableIRQ(TIM2_IRQn);
//Run init Sequence
InitSequence initializer(display); InitSequence initializer(display);
initializer.runInitSequence(); initializer.runInitSequence();
//Enable green led
HAL_GPIO_WritePin(LED5_GPIO_Port, LED5_Pin, GPIO_PIN_RESET); HAL_GPIO_WritePin(LED5_GPIO_Port, LED5_Pin, GPIO_PIN_RESET);
///
///
/// EXPERIMENTAL CODE BEGIN
///
///
///
using namespace floatpump::menu; using namespace floatpump::menu;
Menu mainmenu("Hauptmenue"); Menu mainmenu("Hauptmenu");
Menu_Entry_Type_Checkable entry1bool(true); Menu_Entry_Type_Checkable entry1bool(false), entry2bool(false);
entry1bool.linkConfig(globalConfig.testbool.getLink());
Menu_Entry entry(entry1bool, "test");
bool l_calib = false, h_calib = false;
uint16_t lcb = 0, hcb = 4096;
uint8_t perc = 50;
uint8_t cur_perc = 0;
uint32_t current = 0;
entry1bool.linkConfig(&l_calib);
entry2bool.linkConfig(&h_calib);
Menu_Entry entry(entry1bool, "Low Calib");
Menu_Entry entry2(entry2bool, "High Calib");
Menu_Entry_Type_Percent entry1perc(15); Menu_Entry_Type_Percent entry1perc(15);
Menu_Entry entry2(entry1perc, "Prozent"); Menu_Entry entry3(entry1perc, "Pegel Schalten");
Menu_Entry_Type_Time entry1time(23,44,12); Menu_Entry_Type_ReadOnly<uint32_t> entry1read(0);
Menu_Entry entry3(entry1time, "Uhrzeit"); entry1read.linkConfig(&current);
Menu_Entry entry4(entry1read, "Pegel");
Menu_Entry_Type_ReadOnly<uint8_t> entry2read(0);
entry2read.linkConfig(&cur_perc);
Menu_Entry entry5(entry2read, "Pegel Proz");
mainmenu.addEntry(entry); mainmenu.addEntry(entry);
mainmenu.addEntry(entry2); mainmenu.addEntry(entry2);
mainmenu.addEntry(entry3); mainmenu.addEntry(entry3);
mainmenu.addEntry(entry4);
Menu submenu("Submenu1"); mainmenu.addEntry(entry5);
Menu_Entry_Type_Checkable entrysub(true);
Menu_Entry sube(entrysub, "yay dies sub!");
Menu_Entry_Type_ReadOnly<uint16_t> entryread(42);
uint16_t wurst = 0;
entryread.linkConfig(&wurst);
Menu_Entry sube2(entryread, "Read Only test ");
submenu.addEntry(sube);
submenu.addEntry(sube2);
mainmenu.addSubmenu(&submenu);
Menu_Controller controller(&mainmenu, display); Menu_Controller controller(&mainmenu, display);
static int old_pos = 0; HAL_GPIO_WritePin(MPWR0_GPIO_Port, MPWR0_Pin, GPIO_PIN_SET);
HAL_GPIO_WritePin(MPWR2_GPIO_Port, MPWR2_Pin, GPIO_PIN_SET);
uint16_t timed_tp = 0;
uint16_t averaging[25];
int index_avg = 0;
static int old_pos = 0;
while (1) { while (1) {
controller.execute(); controller.execute();
if(rot_button) { if (rot_button) {
rot_button = false; rot_button = false;
controller.pushEvent(Menu_Controller::Event::Push); controller.pushEvent(Menu_Controller::Event::Push);
} }
if(old_pos < rot_counter) { if (old_pos < rot_counter) {
controller.pushEvent(Menu_Controller::Event::Increase); controller.pushEvent(Menu_Controller::Event::Increase);
old_pos = rot_counter; old_pos = rot_counter;
} else if (old_pos > rot_counter) { } else if (old_pos > rot_counter) {
@ -145,13 +145,44 @@ int main(void) {
} }
HAL_Delay(100); HAL_Delay(100);
wurst++; timed_tp++;
if(globalConfig.testbool.getValue()) { //Execute each second
HAL_GPIO_WritePin(OCHAN0_GPIO_Port, OCHAN0_Pin, GPIO_PIN_SET);
} else { uint32_t measured, avg = 0;
HAL_GPIO_WritePin(OCHAN0_GPIO_Port, OCHAN0_Pin, GPIO_PIN_RESET);
} HAL_ADC_Start(&hadc1);
HAL_ADC_PollForConversion(&hadc1, 1);
measured = HAL_ADC_GetValue(&hadc1);
averaging[index_avg % 25] = measured;
for(int i = 0; i < 25; i++) {
avg += averaging[i];
}
current = avg/25;
index_avg++;
//calibrate
if(l_calib) {
l_calib = false;
lcb = current - 10;
}
if(h_calib) {
h_calib = false;
hcb = current + 10;
}
cur_perc = ((current - lcb) *100)/(hcb-lcb);
if(cur_perc > perc + 5) {
HAL_GPIO_WritePin(OCHAN0_GPIO_Port, OCHAN0_Pin, GPIO_PIN_SET);
} else if(cur_perc < perc - 5) {
HAL_GPIO_WritePin(OCHAN0_GPIO_Port, OCHAN0_Pin, GPIO_PIN_RESET);
}
} }
} }
@ -229,7 +260,7 @@ static void MX_ADC1_Init(void) {
*/ */
sConfig.Channel = ADC_CHANNEL_8; sConfig.Channel = ADC_CHANNEL_8;
sConfig.Rank = 1; sConfig.Rank = 1;
sConfig.SamplingTime = ADC_SAMPLETIME_3CYCLES; sConfig.SamplingTime = ADC_SAMPLETIME_15CYCLES;
if (HAL_ADC_ConfigChannel(&hadc1, &sConfig) != HAL_OK) { if (HAL_ADC_ConfigChannel(&hadc1, &sConfig) != HAL_OK) {
Error_Handler(); Error_Handler();
} }
@ -292,10 +323,6 @@ static void MX_RTC_Init(void) {
Error_Handler(); Error_Handler();
} }
/* USER CODE BEGIN Check_RTC_BKUP */
/* USER CODE END Check_RTC_BKUP */
/** Initialize RTC and set the Time and Date /** Initialize RTC and set the Time and Date
*/ */
sTime.Hours = 0; sTime.Hours = 0;