USART2 Ausgabe gefixt 2.0

This commit is contained in:
Dorian Karl Strohmayr 2026-02-10 22:20:36 +00:00
parent d3a9560d79
commit 6547cc23c5

62
main.c
View File

@ -1,7 +1,7 @@
#include <stm32f10x.h> #include <stm32f10x.h>
#include <armv30_std.h> #include <armv30_std.h>
#include <Nextion.h> #include <Nextion.h>
#include "nex_ui.h" //#include "nex_ui.h"
#include <stdbool.h> #include <stdbool.h>
@ -86,7 +86,7 @@ void PortConfig(void)
void uart2_init(void) void uart2_init(void)
{ {
RCC->APB2ENR |= RCC_APB2ENR_AFIOEN | RCC_APB2ENR_IOPAEN; RCC->APB2ENR |= RCC_APB2ENR_AFIOEN | RCC_APB2ENR_IOPAEN; // 0x4
RCC->APB1ENR |= 0x20000; // UART2 Taktversorgung RCC->APB1ENR |= 0x20000; // UART2 Taktversorgung
GPIOA->CRL &= 0xFFFFF0FF; GPIOA->CRL &= 0xFFFFF0FF;
@ -146,7 +146,7 @@ void configNexObjects(void)
void fehler(bool state) void fehler(bool state)
{ {
static bool lastStateF = true; static bool lastStateF = true;
static bool firstCallF = true; static bool firstCallF = true;
if (firstCallF) if (firstCallF)
@ -179,7 +179,7 @@ void fehler(bool state)
void leerBlasen(bool state) void leerBlasen(bool state)
{ {
static bool lastStateB; static bool lastStateB;
static bool firstCallB = true; static bool firstCallB = true;
if (firstCallB) if (firstCallB)
@ -194,7 +194,7 @@ void leerBlasen(bool state)
} }
lastStateB = state; lastStateB = state;
if(state) if(state)
{ {
NexProgressBar_setValue(&leerInd, 100); NexProgressBar_setValue(&leerInd, 100);
@ -213,7 +213,7 @@ void leerBlasen(bool state)
void fein(bool state) void fein(bool state)
{ {
static bool lastStateFein; static bool lastStateFein;
static bool firstCallFein = true; static bool firstCallFein = true;
if (firstCallFein) if (firstCallFein)
@ -228,7 +228,6 @@ void fein(bool state)
} }
lastStateFein = state; lastStateFein = state;
if(state) if(state)
{ {
NexProgressBar_setValue(&feinInd, 100); NexProgressBar_setValue(&feinInd, 100);
@ -247,7 +246,7 @@ void fein(bool state)
void grob(bool state) void grob(bool state)
{ {
static bool lastStateGrob; static bool lastStateGrob;
static bool firstCallGrob = true; static bool firstCallGrob = true;
if (firstCallGrob) if (firstCallGrob)
@ -262,7 +261,7 @@ void grob(bool state)
} }
lastStateGrob = state; lastStateGrob = state;
if(state) if(state)
{ {
NexProgressBar_setValue(&grobInd, 100); NexProgressBar_setValue(&grobInd, 100);
@ -281,7 +280,7 @@ void grob(bool state)
void pumpe(bool state) void pumpe(bool state)
{ {
static bool lastState; static bool lastState;
static bool firstCall = true; static bool firstCall = true;
if (firstCall) if (firstCall)
@ -296,12 +295,12 @@ void pumpe(bool state)
} }
lastState = state; lastState = state;
if(state) if(state)
{ {
NexProgressBar_setValue(&pumpeInd, 100); NexProgressBar_setValue(&pumpeInd, 100);
PUMPE = 1; PUMPE = 1;
uart2_putString("Pumpe eingeschaltet!\r\n"); //uart2_putString("Pumpe eingeschaltet!\r\n");
} }
else else
{ {
@ -323,25 +322,24 @@ void fuellstand(int8_t value)
NexProgressBar_setValue(&fuellstandInd, 0); NexProgressBar_setValue(&fuellstandInd, 0);
return; return;
} }
else if (value == lastValue)
if (value == lastValue)
{ {
return; // nichts geändert ? nichts tun return;
}
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");
} }
lastValue = 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");
}
} }
uint8_t toPercent(uint8_t value, uint8_t max) uint8_t toPercent(uint8_t value, uint8_t max)
{ {
if (value > max) value = max; if (value > max) value = max;
@ -449,11 +447,19 @@ int main(void)
if(leitungBenutzt) if(leitungBenutzt)
{ {
int time = 3000 / NACHLAUF; int time = 3000 / NACHLAUF;
int rest = 3000 % NACHLAUF;
uint8_t i = 0; uint8_t i = 0;
for(i = 0; i < NACHLAUF; i++) for(i = 0; i < NACHLAUF; i++)
{ {
wait_sys_ms(time); wait_sys_ms(time);
if(rest > 0)
{
wait_sys_ms(1);
rest -= 1;
}
nachlaufOffset += 1; nachlaufOffset += 1;
setFuellstand(istWert + nachlaufOffset); setFuellstand(istWert + nachlaufOffset);
} }