/
OpenTrollerSDK.pde
117 lines (96 loc) · 2.7 KB
/
OpenTrollerSDK.pde
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
#include <ScreenUi.h>
#include <LiquidCrystalFP.h>
#include <pin.h>
#include <encoder.h>
#include <Wire.h>
#include <ModbusMaster.h>
#include "HWProfile.h"
#include <NewDelete.h>
#include <DS2482.h>
#include <OneWire.h>
#include "OT_UI.h"
#include "OT_Inputs.h"
#include "OT_Outputs.h"
//Define 1-Wire Bus Object
#ifdef TS_ONEWIRE
#if defined TS_ONEWIRE_GPIO
#include <OneWire.h>
OneWire ds(TEMP_PIN);
#elif defined TS_ONEWIRE_I2C
#include <DS2482.h>
DS2482 ds(DS2482_ADDR);
#endif
#endif
outputs Outputs;
//Declare our worker function
void testCore(void);
//Create UI and pass worker function
screenUI ScreenUI(testCore);
void setup() {
#ifdef I2C_SUPPORT
Wire.begin(BT_I2C_ADDR);
#ifdef TS_ONEWIRE_I2C
ds.configure(DS2482_CONFIG_APU | DS2482_CONFIG_SPU);
#endif
#endif
//Attach Outputs to SWPWM
analogOutput_SWPWM::setup(&Outputs);
//Attach 1-Wire bus to tSensor_1Wire
tSensor_1Wire::setup(&ds, 1, 1, 1);
//Add Modbus bank
Outputs.newModbusBank(10,1000,8);
delay(1000);
Wire.begin();
pinMode(LCD_BRIGHT_PIN, OUTPUT);
pinMode(LCD_CONTRAST_PIN, OUTPUT);
TCCR2B = 0x01;
analogWrite(LCD_BRIGHT_PIN, 255 - LCD_DEFAULT_BRIGHTNESS);
analogWrite(LCD_CONTRAST_PIN, LCD_DEFAULT_CONTRAST);
Serial.begin(115200);
}
unsigned long outProfileX = 0;
byte pwmPinX = 0;
tSensorCfg_t sensorXCfg;
analogInCfg_t aInXCfg;
void mainMenu() {
Screen * screen = ScreenUI.create(20, 4);
Label titleLabel("ScreenUI Main Menu");
screen->add(&titleLabel, 0, 0);
ScrollContainer scrollContainer(screen, screen->width(), 3);
Button pwmPinBtn("Select Output");
scrollContainer.add(&pwmPinBtn, 0, 1);
Button profileXBtn("Cfg Output Profile");
scrollContainer.add(&profileXBtn, 0, 2);
Button tSensorBtn("Cfg Temp Sensor");
scrollContainer.add(&tSensorBtn, 0, 3);
Button aInBtn("Cfg AnalogIn");
scrollContainer.add(&aInBtn, 0, 4);
screen->add(&scrollContainer, 0, 1);
while (1) {
screen->update();
if (pwmPinBtn.pressed()) {
pwmPinX = ScreenUI.dlgSelectOutput("Select Output", &Outputs, pwmPinX);
screen->clear(); screen->repaint();
}
else if (profileXBtn.pressed()) {
outProfileX = ScreenUI.dlgCfgOutputProfile("Cfg Output Profile", &Outputs, outProfileX);
screen->clear(); screen->repaint();
}
else if (tSensorBtn.pressed()) {
ScreenUI.dlgCfgTSensor("Cfg Temp Sensor", &sensorXCfg);
screen->clear(); screen->repaint();
}
else if (aInBtn.pressed()) {
ScreenUI.dlgCfgAnalogIn("Cfg Analog Input", &aInXCfg);
screen->clear(); screen->repaint();
}
//Call worker process
ScreenUI.wait();
}
}
void loop() {
mainMenu();
}
void testCore (void) {
Outputs.update();
}