Skip to content

Commit 754316d

Browse files
author
Wegmann Peter
committed
rudimentatry mainscreen function works
1 parent ca409aa commit 754316d

File tree

3 files changed

+67
-119
lines changed

3 files changed

+67
-119
lines changed

DispAdapter.c

Lines changed: 29 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
#include <stdint.h>
1010
#include <stdio.h>
1111
#include <string.h>
12+
#include <stdlib.h>
13+
#include <math.h>
1214

1315
#include "DispAdapter.h"
1416
#include "config.h"
@@ -21,18 +23,7 @@
2123

2224

2325

24-
MainscreenType MainScreen = {
25-
.Value.x = X_LEFT_EDGE,
26-
.Value.y = Y_VALUES_START,
27-
.Volume.x = X_LEFT_EDGE,
28-
.Volume.y = Y_VALUES_START + FONT2_H * 1,
29-
.Corr.x = X_LEFT_EDGE,
30-
.Corr.y = Y_VALUES_START + FONT2_H * 2,
31-
.Temp.x = X_LEFT_EDGE,
32-
.Temp.y = Y_VALUES_START + FONT2_H * 3,
33-
.Press.x = X_LEFT_EDGE,
34-
.Press.y = Y_VALUES_START + FONT2_H * 4,
35-
};
26+
3627

3728

3829
void lcd_init(void){
@@ -141,61 +132,38 @@ void paint_info_line(char * line, _Bool update){
141132
}
142133

143134

144-
void paint_value(char* text,uint8_t update,char* unit){
145-
if (update)
146-
{
147-
lcd_Print(" ",MainScreen.Value.x + DESCRUPTOR_LEN * FONT2_W,MainScreen.Value.y,2,1,1,FGC,BGC);
148-
}
149-
lcd_Print(text,MainScreen.Value.x + DESCRUPTOR_LEN * FONT2_W,MainScreen.Value.y,2,1,1,FGC,BGC);
150-
151-
lcd_Print(unit,HALF_SPACE_WIDTH_FONT_2 + MainScreen.Value.x + (DESCRUPTOR_LEN+strlen(text)) * FONT2_W, MainScreen.Value.y,2,1,1,FGC,BGC);
152-
}
153-
void paint_volume(char* text,uint8_t update,char* unit){
154-
if (update)
155-
{
156-
lcd_Print(" ",MainScreen.Volume.x + DESCRUPTOR_LEN * FONT2_W,MainScreen.Volume.y,2,1,1,FGC,BGC);
157-
}
158-
lcd_Print(text,MainScreen.Volume.x + DESCRUPTOR_LEN * FONT2_W,MainScreen.Volume.y,2,1,1,FGC,BGC);
159-
160-
lcd_Print(unit,HALF_SPACE_WIDTH_FONT_2 + MainScreen.Volume.x + (DESCRUPTOR_LEN+strlen(text)) * FONT2_W, MainScreen.Volume.y,2,1,1,FGC,BGC);
161-
162-
}
163135

164-
void paint_corr(char* text,uint8_t update,char* unit){
165-
if (update)
166-
{
167-
lcd_Print(" ",MainScreen.Corr.x + DESCRUPTOR_LEN * FONT2_W,MainScreen.Corr.y,2,1,1,FGC,BGC);
168-
}
169-
lcd_Print(text,MainScreen.Corr.x + DESCRUPTOR_LEN * FONT2_W,MainScreen.Corr.y,2,1,1,FGC,BGC);
170-
171-
lcd_Print(unit,HALF_SPACE_WIDTH_FONT_2 + MainScreen.Corr.x + (DESCRUPTOR_LEN+strlen(text)) * FONT2_W, MainScreen.Corr.y,2,1,1,FGC,BGC);
172-
}
173-
void paint_temp(char* text,uint8_t update,char* unit){
174-
if (update)
175-
{
176-
lcd_Print(" ",MainScreen.Temp.x + DESCRUPTOR_LEN * FONT2_W,MainScreen.Temp.y,2,1,1,FGC,BGC);
177-
}
178-
lcd_Print(text,MainScreen.Temp.x + DESCRUPTOR_LEN * FONT2_W,MainScreen.Temp.y,2,1,1,FGC,BGC);
179-
180-
lcd_Print(unit,HALF_SPACE_WIDTH_FONT_2 + MainScreen.Temp.x + (DESCRUPTOR_LEN+strlen(text)) * FONT2_W, MainScreen.Temp.y,2,1,1,FGC,BGC);
181-
}
182136

183-
void paint_press(char* text,uint8_t update,char* unit){
184-
if (update)
185-
{
186-
lcd_Print(" ",MainScreen.Press.x + DESCRUPTOR_LEN * FONT2_W,MainScreen.Press.y,2,1,1,FGC,BGC);
187-
}
188-
lcd_Print(text,MainScreen.Press.x + DESCRUPTOR_LEN * FONT2_W,MainScreen.Press.y,2,1,1,FGC,BGC);
189137

190-
lcd_Print(unit,HALF_SPACE_WIDTH_FONT_2 + MainScreen.Press.x + (DESCRUPTOR_LEN+strlen(text)) * FONT2_W, MainScreen.Press.y,2,1,1,FGC,BGC);
138+
139+
void paint_string_row(char *text,ROW_NAME row,uint8_t update,char* unit,uint16_t color){
140+
if (update)
141+
{
142+
lcd_Print(" ",X_LEFT_EDGE + DESCRUPTOR_LEN * FONT2_W,Y_VALUES_START + FONT2_H * row,2,1,1,color,BGC);
143+
}
144+
lcd_Print(text,X_LEFT_EDGE + DESCRUPTOR_LEN * FONT2_W,Y_VALUES_START + FONT2_H * row,2,1,1,color,BGC);
145+
146+
lcd_Print(unit,HALF_SPACE_WIDTH_FONT_2 + X_LEFT_EDGE + (DESCRUPTOR_LEN+strlen(text)) * FONT2_W, Y_VALUES_START + FONT2_H * row,2,1,1,color,BGC);
191147
}
192148

193149
void paint_Main(void){
194-
lcd_Print("Val:",MainScreen.Value.x ,MainScreen.Value.y,2,1,1,FGC,BGC);
195-
lcd_Print("Vol:",MainScreen.Volume.x ,MainScreen.Volume.y,2,1,1,FGC,BGC);
196-
lcd_Print("Cor:",MainScreen.Corr.x ,MainScreen.Corr.y,2,1,1,FGC,BGC);
197-
lcd_Print("Tmp:",MainScreen.Temp.x ,MainScreen.Temp.y,2,1,1,FGC,BGC);
198-
lcd_Print("Prs:",MainScreen.Press.x ,MainScreen.Press.y,2,1,1,FGC,BGC);
150+
lcd_Print("Val:",X_LEFT_EDGE ,Y_VALUES_START + FONT2_H * VALUE ,2,1,1,FGC,BGC);
151+
lcd_Print("Vol:",X_LEFT_EDGE ,Y_VALUES_START + FONT2_H * VOLUME ,2,1,1,FGC,BGC);
152+
lcd_Print("Cor:",X_LEFT_EDGE ,Y_VALUES_START + FONT2_H * CORRVOL,2,1,1,FGC,BGC);
153+
lcd_Print("Tmp:",X_LEFT_EDGE ,Y_VALUES_START + FONT2_H * TEMP ,2,1,1,FGC,BGC);
154+
lcd_Print("Prs:",X_LEFT_EDGE ,Y_VALUES_START + FONT2_H * PRESS ,2,1,1,FGC,BGC);
199155
}
200156

201157

158+
159+
void paint_Value(uint64_t val,ROW_NAME row,uint8_t precision,char* unit){
160+
char numberbuffer[30];
161+
dtostrf(((double)val)/pow(10,precision),3,precision,numberbuffer);
162+
163+
paint_string_row(numberbuffer,row,1,unit,FGC);
164+
}
165+
166+
void paint_Error(char* text, ROW_NAME row){
167+
paint_string_row(text,row,1,"",red);
168+
}
169+

DispAdapter.h

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,14 @@
3636
#define HZB_Blue 0b0000001011010011
3737
#define HZB_Cyan 0b0000010011111100
3838

39+
typedef enum {
40+
VALUE,
41+
VOLUME,
42+
CORRVOL,
43+
TEMP,
44+
PRESS,
45+
INFO
46+
}ROW_NAME;
3947

4048
typedef struct {
4149
uint16_t ForeColor;
@@ -48,18 +56,9 @@ typedef struct {
4856
uint8_t YScale;
4957
}InitScreenType;
5058

51-
typedef struct{
52-
uint16_t x;
53-
uint16_t y;
54-
}PointType;
5559

56-
typedef struct {
57-
PointType Value;
58-
PointType Volume;
59-
PointType Corr;
60-
PointType Temp;
61-
PointType Press;
62-
}MainscreenType;
60+
61+
6362

6463
void lcd_init(void);
6564
void lcd_Print(const char* Text, uint16_t X, uint16_t Y, unsigned char FontNr, unsigned char XScale, unsigned char YScale, unsigned int ForeColor, unsigned int BackColor);
@@ -75,10 +74,8 @@ void lcd_Draw_Cross(uint16_t x0,uint16_t y0,uint16_t x1,uint16_t y1);
7574
void Print_add_Line(char* Text,uint8_t first_line );
7675
void setInitScreen(uint16_t fore, uint16_t back, uint8_t nextLine, uint8_t FontNr, uint8_t XScale, uint8_t YScale);
7776
void paint_info_line(char * line, _Bool update);
78-
void paint_press(char* text,uint8_t update,char* unit);
79-
void paint_temp(char* text,uint8_t update,char* unit);
80-
void paint_value(char* text,uint8_t update,char* unit);
81-
void paint_volume(char* text,uint8_t update,char* unit);
82-
void paint_corr(char* text,uint8_t update,char* unit);
83-
77+
void paint_string_row(char *text,ROW_NAME row,uint8_t update,char* unit,uint16_t color);
78+
void paint_Value(uint64_t val,ROW_NAME row,uint8_t precision,char* unit);
79+
void paint_Error(char* text, ROW_NAME row);
80+
void paint_Main(void);
8481
#endif /* DISPADAPTER_H_ */

Gascounter_main.c

Lines changed: 24 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -488,7 +488,7 @@ void init(void)
488488

489489

490490
#ifdef ili9341
491-
setInitScreen(white,white,6,1,1,1);
491+
setInitScreen(black,white,6,1,1,1);
492492
Print_add_Line("HZB Gascount",0);
493493
#endif
494494

@@ -589,9 +589,7 @@ void init(void)
589589
xbee_hardware_version();
590590
Print_add_Line("Init done",0);
591591

592-
while (1)
593-
{
594-
}
592+
595593

596594
}
597595

@@ -665,47 +663,45 @@ void displayTemPreVol(void){
665663

666664
if ( CHECK_ERROR(TEMPPRESS_ERROR))
667665
{
668-
paint_temp("TEMP ERR",1,"");
666+
paint_Error("TEMP ERR",TEMP);
669667
}
670668
if (CHECK_ERROR(TEMPPRESS_ERROR))
671669
{
672-
paint_press("PRESS ERR",1,"");
670+
paint_Error("PRESS ERR",PRESS);
673671
if (options.T_Compensation_enable){
674-
paint_temp("TEMP ERR",1,"");
672+
paint_Error("TEMP ERR",TEMP);
675673
}
676674

677675
}
678676

679677
// TEMPERATURE
680678
if (!(options.T_Compensation_enable && (CHECK_ERROR(TEMPPRESS_ERROR))))
681679
{
682-
LCD_Clear_row_from_column(2, 3);
683-
LCD_Value((int32_t) options.Temperature_value - 2732, 1, 2, 3, "°C");
680+
681+
paint_Value( options.Temperature_value - 2732,TEMP, 1, "°C");
684682
}
685683
else{
686-
LCD_Clear_row_from_column(2, 3);
687-
LCD_String("TEMP ERR",3,3);
684+
685+
paint_Error("TEMP ERR",TEMP);
688686
}
689687

690688

691689
//PRESSURE
692690
if(!(options.p_Compensation_enable && (CHECK_ERROR(TEMPPRESS_ERROR))))
693691
{
694692
LCD_Clear_row_from_column(2, 4);
695-
LCD_Value(options.Pressure_value, 1, 2, 4, "mbar");
693+
paint_Value(options.Pressure_value,PRESS, 1, "mbar");
696694
}
697695
else{
698696
LCD_Clear_row_from_column(2, 3);
699-
LCD_String("PRESS ERR",3,4);
697+
paint_Error("PRESS ERR",PRESS);
700698
}
701699

702700

703701
if (!connected.BMP && connected.BMP_on_Startup)
704702
{
705-
LCD_Clear_row_from_column(2, 3);
706-
LCD_String("BMP Sensor",2,3);
707-
LCD_Clear_row_from_column(2, 4);
708-
LCD_String("Error",2,4);
703+
paint_Error("BMP Sensor",TEMP);
704+
paint_Error("Error",PRESSURE);
709705

710706

711707
}
@@ -715,30 +711,24 @@ void displayTemPreVol(void){
715711

716712
//VOLUME
717713
#ifndef FUNCTION_TRACE
718-
LCD_Clear_row_from_column(3, 0);
719-
LCD_Value(options.Value / options.step_Volume, position_volume_dot_point, 2, 0, "m³");
714+
715+
paint_Value(options.Value / options.step_Volume,VALUE, position_volume_dot_point,"m³");
720716
#endif
721717

722-
LCD_Clear_row_from_column(3, 1);
723-
LCD_Value(options.Volume / options.step_Volume, position_volume_dot_point, 2, 1, "m³");
718+
719+
paint_Value(options.Volume / options.step_Volume,VOLUME, position_volume_dot_point, "m³");
720+
721+
722+
paint_Value(options.CorrVolume / options.step_Volume, CORRVOL, position_volume_dot_point,"m³");
724723

725-
LCD_Clear_row_from_column(3, 2);
726-
LCD_Value(options.CorrVolume / options.step_Volume, position_volume_dot_point, 2, 2, "m³");
727724

728725
DS3231M_read_time();
729726

730727

731728
if (connected.TWI && connected.DS3231M)
732729
{
733-
if ((Time.tm_hour < 10))
734-
{ if (Time.tm_min < 10) sprintf(print_temp,"0%i:0%i", Time.tm_hour, Time.tm_min);
735-
else sprintf(print_temp,"0%i:%i", Time.tm_hour, Time.tm_min);
736-
}
737-
if (!(Time.tm_hour < 10))
738-
{ if (Time.tm_min < 10) sprintf(print_temp,"%i:0%i", Time.tm_hour, Time.tm_min);
739-
else sprintf(print_temp,"%i:%i", Time.tm_hour, Time.tm_min);
740-
}
741-
730+
sprintf(print_temp,"%02i:%02i", Time.tm_hour, Time.tm_min);
731+
742732
}
743733
else
744734
{
@@ -767,7 +757,7 @@ void displayTemPreVol(void){
767757
}
768758

769759

770-
LCD_String(print_temp, 0, 5);
760+
paint_string_row(print_temp,INFO,0,"", green);
771761

772762
activity_indicator++;
773763

@@ -782,14 +772,7 @@ void displayTemPreVol(void){
782772
}
783773

784774

785-
#ifndef FUNCTION_TRACE
786-
LCD_String("A:", 0, 0); // Value
787-
#endif
788-
789-
LCD_String("V:", 0, 1); // Volume
790-
LCD_String("C:", 0, 2); // CorrVolume
791-
LCD_String("T:", 0, 3); // Temperature
792-
LCD_String("P:", 0, 4); // Pressure
775+
paint_Main();
793776

794777

795778
#endif

0 commit comments

Comments
 (0)