From bd178f66325ec6b805cf66c4b94eefbae1029717 Mon Sep 17 00:00:00 2001 From: Fabian Schieder Date: Mon, 2 Feb 2026 23:55:01 +0000 Subject: [PATCH] main.c aktualisiert --- main.c | 147 ++++++++++++++++++++++++--------------------------------- 1 file changed, 61 insertions(+), 86 deletions(-) diff --git a/main.c b/main.c index 63e88ee..e71b807 100644 --- a/main.c +++ b/main.c @@ -37,6 +37,9 @@ NexEventObj fuellstandText; //---------------------Variablen------------------------ +#define NEX_PID_MAIN 0 +#define NEX_CID_PROG 1 + #define SOLLWERT 0x7F // 127d #define GAP 0x5F // 95d #define NACHLAUF 0x5 @@ -84,20 +87,20 @@ void PortConfig(void) void uart2_init(void) { RCC->APB2ENR |= RCC_APB2ENR_AFIOEN | RCC_APB2ENR_IOPAEN; - RCC->APB1ENR |= 0x20000; // UART2 Taktversorgung - - GPIOA->CRL &= 0xFFFFF0FF; - GPIOA->CRL |= 0xB00; - - GPIOA->CRL &= 0xFFFF0FFF; - GPIOA->CRL |= 0x4000; - - USART2->CR1 &= ~0x1000; // M:--> Start bit, 8 Data bits, n Stop bit - USART2->CR1 &= ~0x0400; // PCE: 0: Parity control disabled - USART2->CR2 &= ~0x3000; // STOP: 00: 1 Stop bit afungsbil - USART2->BRR = 0x1D4C; // set Baudrate to 9600 Baud (SysClk 72Mhz) - USART2->CR1 |= 0x0C; // enable Receiver and Transmitter - USART2->CR1 |= 0x2000; // Set USART Enable Bit + RCC->APB1ENR |= 0x20000; // UART2 Taktversorgung + + GPIOA->CRL &= 0xFFFFF0FF; + GPIOA->CRL |= 0xB00; + + GPIOA->CRL &= 0xFFFF0FFF; + GPIOA->CRL |= 0x4000; + + USART2->CR1 &= ~0x1000; // M:--> Start bit, 8 Data bits, n Stop bit + USART2->CR1 &= ~0x0400; // PCE: 0: Parity control disabled + USART2->CR2 &= ~0x3000; // STOP: 00: 1 Stop bit afungsbil + USART2->BRR = 0x1D4C; // set Baudrate to 9600 Baud (SysClk 72Mhz) + USART2->CR1 |= 0x0C; // enable Receiver and Transmitter + USART2->CR1 |= 0x2000; // Set USART Enable Bit } void uart2_putChar(char zeichen) @@ -120,75 +123,48 @@ char uart2_getChar(void) return ((char) (USART2->DR & 0xFF)); } -void configProgressBar(void) +static void NexEventObj_Init(NexEventObj *obj, uint8_t pid, uint8_t cid, const char *name) { - fuellstandInd.pid = 0; - fuellstandInd.cid = 1; - fuellstandInd.name = "fuellstand"; - fuellstandInd.pophandler = NULL; - fuellstandInd.pushhandler = NULL; - - fehlerInd.pid = 0; - fehlerInd.cid = 1; - fehlerInd.name = "fehlerInd"; - fehlerInd.pophandler = NULL; - fehlerInd.pushhandler = NULL; - - leerInd.pid = 0; - leerInd.cid = 1; - leerInd.name = "leerInd"; - leerInd.pophandler = NULL; - leerInd.pushhandler = NULL; - - feinInd.pid = 0; - feinInd.cid = 1; - feinInd.name = "feinInd"; - feinInd.pophandler = NULL; - feinInd.pushhandler = NULL; - - grobInd.pid = 0; - grobInd.cid = 1; - grobInd.name = "grobInd"; - grobInd.pophandler = NULL; - grobInd.pushhandler = NULL; - - pumpeInd.pid = 0; - pumpeInd.cid = 1; - pumpeInd.name = "pumpeInd"; - pumpeInd.pophandler = NULL; - pumpeInd.pushhandler = NULL; + obj->pid = pid; + obj->cid = cid; + obj->name = name; + obj->pophandler = NULL; + obj->pushhandler = NULL; } -void configTextFields(void) +void configNexObjects(void) { - fuellstandText.pid = 0; - fuellstandText.cid = 1; // Component ID aus Nextion Editor - fuellstandText.name = "fuellstandn"; // Exakter Name! - fuellstandText.pophandler = NULL; - fuellstandText.pushhandler = NULL; + NexEventObj_Init(&fuellstandInd, NEX_PID_MAIN, NEX_CID_PROG, "fuellstand"); + NexEventObj_Init(&fehlerInd, NEX_PID_MAIN, NEX_CID_PROG, "fehlerInd"); + NexEventObj_Init(&leerInd, NEX_PID_MAIN, NEX_CID_PROG, "leerInd"); + NexEventObj_Init(&feinInd, NEX_PID_MAIN, NEX_CID_PROG, "feinInd"); + NexEventObj_Init(&grobInd, NEX_PID_MAIN, NEX_CID_PROG, "grobInd"); + NexEventObj_Init(&pumpeInd, NEX_PID_MAIN, NEX_CID_PROG, "pumpeInd"); + + NexEventObj_Init(&fuellstandText, NEX_PID_MAIN, NEX_CID_PROG, "fuellstandn"); } -void fehler(int8_t state) +void fehler(bool state) { - if(state == 1) + if(state) { NexProgressBar_setValue(&fehlerInd, 100); FEHLER = 1; - uart2_putString("Fehler aufgetreten!\r\n"); + //uart2_putString("Fehler aufgetreten!\r\n"); } else { NexProgressBar_setValue(&fehlerInd, 0); FEHLER = 0; - uart2_putString("Fehler behoben!\r\n"); + //uart2_putString("Fehler behoben!\r\n"); } return; } -void leerBlasen(int8_t state) +void leerBlasen(bool state) { - if(state == 1) + if(state) { NexProgressBar_setValue(&leerInd, 100); LEERBLASEN = 1; @@ -204,9 +180,9 @@ void leerBlasen(int8_t state) return; } -void fein(int8_t state) +void fein(bool state) { - if(state == 1) + if(state) { NexProgressBar_setValue(&feinInd, 100); FEIN = 1; @@ -222,9 +198,9 @@ void fein(int8_t state) return; } -void grob(int8_t state) +void grob(bool state) { - if(state == 1) + if(state) { NexProgressBar_setValue(&grobInd, 100); GROB = 1; @@ -240,9 +216,9 @@ void grob(int8_t state) return; } -void pumpe(int8_t state) +void pumpe(bool state) { - if(state == 1) + if(state) { NexProgressBar_setValue(&pumpeInd, 100); PUMPE = 1; @@ -309,17 +285,16 @@ int main(void) uart2_init(); NexEventObj *nextlisten_list[] = {NULL}; - configProgressBar(); - configTextFields(); + configNexObjects(); Nex_Init(0); Init_Nex_UI(); fuellstand(0); - fehler(0); - leerBlasen(0); - fein(0); - grob(0); - pumpe(0); + fehler(false); + leerBlasen(false); + fein(false); + grob(false); + pumpe(false); wait_sys_ms(20); bool leerGeblasen = false; @@ -339,30 +314,30 @@ int main(void) leerGeblasen = true; leitungBenutzt = false; - pumpe(1); + pumpe(true); if(effektiverWert < SOLLWERT - NACHLAUF) { - fein(1); + fein(true); leitungBenutzt = true; } else if(effektiverWert >= SOLLWERT - NACHLAUF) { - fein(0); + fein(false); } if(effektiverWert < GAP) { - grob(1); + grob(true); leitungBenutzt = true; } else if(effektiverWert < SOLLWERT) { - grob(0); + grob(false); } else { - grob(0); + grob(false); } setFuellstand(effektiverWert); @@ -372,10 +347,10 @@ int main(void) { if(leerGeblasen) { - pumpe(0); - grob(0); - fein(0); - leerBlasen(1); + pumpe(false); + grob(false); + fein(false); + leerBlasen(true); if(leitungBenutzt) { @@ -394,7 +369,7 @@ int main(void) wait_sys_ms(3000); } - leerBlasen(0); + leerBlasen(false); leerGeblasen = false; } }