Formula Student Electronics & Software
The code for the embedded software
Loading...
Searching...
No Matches
display.cpp
Go to the documentation of this file.
1
#include "
display.h
"
2
#include "
apps.h
"
3
4
#include <EasyNextionLibrary.h>
5
#include <FlexCAN_T4.h>
6
7
#define NEXTION_PORT Serial1
8
9
EasyNex
myNex
(
NEXTION_PORT
);
10
11
int
rpm
= 0;
12
int
soc
= 0;
13
int
current
= 0;
14
int
speedInt
= 0;
15
int
switchPin
= 14;
16
int
ACCurrent
= 0;
17
int
motorTemp
= 0;
18
int
lowTemp
= 0;
19
int
sensorValue
= 0;
20
int
highTemp
= 0;
21
int
currentPage
= 0;
22
int
packVoltage
= 0;
23
int
powerStageTemp
= 0;
24
25
int
mapSensorValueToSwitchNumber
(
int
sensorValue
) {
26
int
rotswitchNumber = 0;
27
28
float
posicao =
sensorValue
;
29
30
posicao /= 93;
31
32
rotswitchNumber = round(posicao);
33
return
rotswitchNumber;
34
}
35
36
void
displaySetup
() {
37
myNex
.begin(9600);
38
pinMode(
switchPin
, INPUT);
39
}
40
41
void
displayUpdate
() {
42
myNex
.NextionListen();
43
44
int
sensorValue
= analogRead(
switchPin
);
45
46
// Map the sensor value to the switch position
47
int
switchPosition =
mapSensorValueToSwitchNumber
(
sensorValue
);
48
49
char
mode[28];
50
51
sprintf(mode,
"MODE %d"
, switchPosition);
52
53
myNex
.writeStr(
"t3.txt"
, mode);
54
55
myNex
.writeNum(
"n0.val"
,
speedInt
);
56
myNex
.writeNum(
"x0.val"
,
soc
* 10);
57
myNex
.writeNum(
"x1.val"
,
highTemp
* 10);
58
myNex
.writeNum(
"x2.val"
,
packVoltage
);
59
myNex
.writeNum(
"x3.val"
,
current
);
60
myNex
.writeNum(
"x4.val"
,
motorTemp
);
61
myNex
.writeNum(
"x5.val"
,
powerStageTemp
);
62
myNex
.writeNum(
"x7.val"
,
ACCurrent
);
63
myNex
.writeNum(
"x8.val"
,
rpm
);
64
myNex
.writeNum(
"x9.val"
,
highTemp
);
65
myNex
.writeNum(
"x10.val"
,
lowTemp
);
66
}
apps.h
currentPage
int currentPage
Definition
display.cpp:21
packVoltage
int packVoltage
Definition
display.cpp:22
powerStageTemp
int powerStageTemp
Definition
display.cpp:23
myNex
EasyNex myNex(NEXTION_PORT)
motorTemp
int motorTemp
Definition
display.cpp:17
speedInt
int speedInt
Definition
display.cpp:14
rpm
int rpm
Definition
display.cpp:11
soc
int soc
Definition
display.cpp:12
highTemp
int highTemp
Definition
display.cpp:20
displaySetup
void displaySetup()
Definition
display.cpp:36
NEXTION_PORT
#define NEXTION_PORT
Definition
display.cpp:7
current
int current
Definition
display.cpp:13
sensorValue
int sensorValue
Definition
display.cpp:19
ACCurrent
int ACCurrent
Definition
display.cpp:16
displayUpdate
void displayUpdate()
Definition
display.cpp:41
switchPin
int switchPin
Definition
display.cpp:15
mapSensorValueToSwitchNumber
int mapSensorValueToSwitchNumber(int sensorValue)
Definition
display.cpp:25
lowTemp
int lowTemp
Definition
display.cpp:18
display.h
c3
src
display.cpp
Generated by
1.9.8