From e4506d41e63d9c4025a8a3fa6726d75501aca37d Mon Sep 17 00:00:00 2001 From: Dorian Karl Strohmayr Date: Tue, 10 Feb 2026 21:50:49 +0000 Subject: [PATCH] USART2 Ausgabe gefixt --- main.c | 146 +++++++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 116 insertions(+), 30 deletions(-) diff --git a/main.c b/main.c index 4b3769d..a48da56 100644 --- a/main.c +++ b/main.c @@ -86,7 +86,7 @@ void PortConfig(void) void uart2_init(void) { - RCC->APB2ENR |= RCC_APB2ENR_AFIOEN | RCC_APB2ENR_IOPAEN; // 0x4 + RCC->APB2ENR |= RCC_APB2ENR_AFIOEN | RCC_APB2ENR_IOPAEN; RCC->APB1ENR |= 0x20000; // UART2 Taktversorgung GPIOA->CRL &= 0xFFFFF0FF; @@ -146,17 +146,32 @@ void configNexObjects(void) void fehler(bool state) { + static bool lastStateF = true; + static bool firstCallF = true; + + if (firstCallF) + { + firstCallF = false; + NexProgressBar_setValue(&fehlerInd, 0); + return; + } + else if (state == lastStateF) + { + return; + } + + lastStateF = state; 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; @@ -164,17 +179,33 @@ void fehler(bool state) void leerBlasen(bool state) { + static bool lastStateB; + static bool firstCallB = true; + + if (firstCallB) + { + firstCallB = false; + NexProgressBar_setValue(&leerInd, 0); + return; + } + else if (state == lastStateB) + { + return; + } + + lastStateB = state; + if(state) { NexProgressBar_setValue(&leerInd, 100); LEERBLASEN = 1; - //uart2_putString("Leerblasventil geoeffnet!\r\n"); + uart2_putString("Leerblasventil geoeffnet!\r\n"); } else { NexProgressBar_setValue(&leerInd, 0); LEERBLASEN = 0; - //uart2_putString("Leerblasventil geschlossen!\r\n"); + uart2_putString("Leerblasventil geschlossen!\r\n"); } return; @@ -182,17 +213,33 @@ void leerBlasen(bool state) void fein(bool state) { + static bool lastStateFein; + static bool firstCallFein = true; + + if (firstCallFein) + { + firstCallFein = false; + NexProgressBar_setValue(&feinInd, 0); + return; + } + else if (state == lastStateFein) + { + return; + } + + lastStateFein = state; + if(state) { NexProgressBar_setValue(&feinInd, 100); FEIN = 1; - //uart2_putString("Feinventil geoeffnet!\r\n"); + uart2_putString("Feinventil geoeffnet!\r\n"); } else { NexProgressBar_setValue(&feinInd, 0); FEIN = 0; - //uart2_putString("Feinventil geschlossen!\r\n"); + uart2_putString("Feinventil geschlossen!\r\n"); } return; @@ -200,17 +247,33 @@ void fein(bool state) void grob(bool state) { + static bool lastStateGrob; + static bool firstCallGrob = true; + + if (firstCallGrob) + { + firstCallGrob = false; + NexProgressBar_setValue(&grobInd, 0); + return; + } + else if (state == lastStateGrob) + { + return; + } + + lastStateGrob = state; + if(state) { NexProgressBar_setValue(&grobInd, 100); GROB = 1; - //uart2_putString("Grobventil geoeffnet!\r\n"); + uart2_putString("Grobventil geoeffnet!\r\n"); } else { NexProgressBar_setValue(&grobInd, 0); GROB = 0; - //uart2_putString("Grobventil geoeffnet!\r\n"); + uart2_putString("Grobventil geschlossen!\r\n"); } return; @@ -218,17 +281,33 @@ void grob(bool state) void pumpe(bool state) { + static bool lastState; + static bool firstCall = true; + + if (firstCall) + { + firstCall = false; + NexProgressBar_setValue(&pumpeInd, 0); + return; + } + else if (state == lastState) + { + return; + } + + lastState = state; + if(state) { NexProgressBar_setValue(&pumpeInd, 100); PUMPE = 1; - //uart2_putString("Pumpe eingeschaltet!\r\n"); + uart2_putString("Pumpe eingeschaltet!\r\n"); } else { NexProgressBar_setValue(&pumpeInd, 0); PUMPE = 0; - //uart2_putString("Pumpe ausgeschaltet!\r\n"); + uart2_putString("Pumpe ausgeschaltet!\r\n"); } return; @@ -236,18 +315,33 @@ void pumpe(bool state) void fuellstand(int8_t value) { - if(value >= 0 && value <= 100) - { - NexProgressBar_setValue(&fuellstandInd, value); - //uart2_putString("Fuellstand geaendert!\r\n"); - } - else - { - NexProgressBar_setValue(&fuellstandInd, 0); - //uart2_putString("Uengueltiger Fuellstandswert!\r\n"); - } -} + static bool firstCall = true; + static int8_t lastValue = -1; // ungültiger Startwert + if(firstCall) + { + firstCall = false; + NexProgressBar_setValue(&fuellstandInd, 0); + return; + } + if (value == lastValue) + { + return; // nichts geändert ? nichts tun + } + + lastValue = value; + + if (value >= 0 && value <= 100) + { + NexProgressBar_setValue(&fuellstandInd, value); + uart2_putString("Fuellstand geaendert!\r\n"); + } + else + { + NexProgressBar_setValue(&fuellstandInd, 0); + uart2_putString("Ungueltiger Fuellstandswert!\r\n"); + } +} uint8_t toPercent(uint8_t value, uint8_t max) { if (value > max) value = max; @@ -355,19 +449,11 @@ int main(void) if(leitungBenutzt) { int time = 3000 / NACHLAUF; - int rest = 3000 % NACHLAUF; uint8_t i = 0; for(i = 0; i < NACHLAUF; i++) { wait_sys_ms(time); - - if(rest > 0) - { - wait_sys_ms(1); - rest -= 1; - } - nachlaufOffset += 1; setFuellstand(istWert + nachlaufOffset); }