diff --git a/Core/Inc/git_rev.h b/Core/Inc/git_rev.h index 0de6be3..c9cd8ba 100644 --- a/Core/Inc/git_rev.h +++ b/Core/Inc/git_rev.h @@ -7,6 +7,6 @@ // Auto generated header file containing the last git revision -#define GIT_HASH "6fd24bf" +#define GIT_HASH "ff0aed1" #endif //FLOATPUMP_GIT_REVISION_TEMPLATE_H \ No newline at end of file diff --git a/Core/Src/main.cpp b/Core/Src/main.cpp index b5d1c12..f994082 100644 --- a/Core/Src/main.cpp +++ b/Core/Src/main.cpp @@ -24,7 +24,6 @@ TIM_HandleTypeDef htim2; UART_HandleTypeDef huart1; - void SystemClock_Config(void); static void MX_GPIO_Init(void); @@ -62,81 +61,82 @@ int main(void) { MX_I2C1_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); LCD_I2C_Driver &display = floatpump::LCD_I2C_Driver::getInstance(hi2c1, SLAVE_ADDRESS_LCD); HAL_NVIC_EnableIRQ(TIM2_IRQn); + //Run init Sequence InitSequence initializer(display); initializer.runInitSequence(); + //Enable green led HAL_GPIO_WritePin(LED5_GPIO_Port, LED5_Pin, GPIO_PIN_RESET); + + /// + /// + /// EXPERIMENTAL CODE BEGIN + /// + /// + /// + using namespace floatpump::menu; - Menu mainmenu("Hauptmenue"); - Menu_Entry_Type_Checkable entry1bool(true); - entry1bool.linkConfig(globalConfig.testbool.getLink()); - Menu_Entry entry(entry1bool, "test"); + Menu mainmenu("Hauptmenu"); + Menu_Entry_Type_Checkable entry1bool(false), entry2bool(false); + 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 entry2(entry1perc, "Prozent"); + Menu_Entry entry3(entry1perc, "Pegel Schalten"); - Menu_Entry_Type_Time entry1time(23,44,12); - Menu_Entry entry3(entry1time, "Uhrzeit"); + Menu_Entry_Type_ReadOnly entry1read(0); + entry1read.linkConfig(¤t); + Menu_Entry entry4(entry1read, "Pegel"); + + Menu_Entry_Type_ReadOnly entry2read(0); + entry2read.linkConfig(&cur_perc); + Menu_Entry entry5(entry2read, "Pegel Proz"); mainmenu.addEntry(entry); mainmenu.addEntry(entry2); mainmenu.addEntry(entry3); - - Menu submenu("Submenu1"); - Menu_Entry_Type_Checkable entrysub(true); - Menu_Entry sube(entrysub, "yay dies sub!"); - Menu_Entry_Type_ReadOnly 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); + mainmenu.addEntry(entry4); + mainmenu.addEntry(entry5); 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) { - controller.execute(); - if(rot_button) { + if (rot_button) { rot_button = false; controller.pushEvent(Menu_Controller::Event::Push); } - if(old_pos < rot_counter) { + if (old_pos < rot_counter) { controller.pushEvent(Menu_Controller::Event::Increase); old_pos = rot_counter; } else if (old_pos > rot_counter) { @@ -145,13 +145,44 @@ int main(void) { } HAL_Delay(100); - wurst++; + timed_tp++; - if(globalConfig.testbool.getValue()) { - HAL_GPIO_WritePin(OCHAN0_GPIO_Port, OCHAN0_Pin, GPIO_PIN_SET); - } else { - HAL_GPIO_WritePin(OCHAN0_GPIO_Port, OCHAN0_Pin, GPIO_PIN_RESET); - } + //Execute each second + + uint32_t measured, avg = 0; + + 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.Rank = 1; - sConfig.SamplingTime = ADC_SAMPLETIME_3CYCLES; + sConfig.SamplingTime = ADC_SAMPLETIME_15CYCLES; if (HAL_ADC_ConfigChannel(&hadc1, &sConfig) != HAL_OK) { Error_Handler(); } @@ -292,10 +323,6 @@ static void MX_RTC_Init(void) { Error_Handler(); } - /* USER CODE BEGIN Check_RTC_BKUP */ - - /* USER CODE END Check_RTC_BKUP */ - /** Initialize RTC and set the Time and Date */ sTime.Hours = 0;