Skip to content

Commit e7c86a5

Browse files
2.0.9 Basic Surface screen
1 parent 64c3e15 commit e7c86a5

10 files changed

+145
-34
lines changed

DiveIno/include/screens/DiveInoScreen.h

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#ifndef DiveInoScreen_h
22
#define DiveInoScreen_h
33

4+
#define STAY_ON_SCREEN 456
45
#define SCREEN_HOME 310
56
#define SCREEN_DIVE 320
67
#define SCREEN_GAUGE 330

DiveIno/include/screens/DiveScreen.h

+5-2
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class DiveScreen : public DiveInoScreen {
2525

2626
void init(DiveInoSettings diveInoSettings, PressureSensorData sensorData, bool replayEnabled, bool emulatorEnabled);
2727

28-
void display(PressureSensorData sensorData);
28+
int display(PressureSensorData sensorData);
2929

3030
void displayStopwatch();
3131
void displayZeroTime();
@@ -37,6 +37,8 @@ class DiveScreen : public DiveInoScreen {
3737

3838
bool isRunning();
3939

40+
DiveResult* getDiveResult();
41+
4042
void handleButtonPress(String buttonName);
4143

4244
private:
@@ -49,7 +51,7 @@ class DiveScreen : public DiveInoScreen {
4951
bool _replayEnabled = false;
5052

5153
unsigned long _previousDiveDurationInSeconds = 0;
52-
void _replayDive();
54+
bool _replayDive();
5355

5456
bool _isStopWatchRunning = false;
5557
unsigned long _stopwatchStartTimestamp;
@@ -73,6 +75,7 @@ class DiveScreen : public DiveInoScreen {
7375

7476
void _clearDecoDisplay();
7577
DiveInfo _currentDiveInfo;
78+
DiveResult* _diveResult = NULL;
7679
void startDive();
7780
void _diveProgress(float temperatureInCelsius, float pressureInMillibar, float depthInMeter, unsigned int durationInSeconds);
7881
void stopDive();

DiveIno/include/screens/HomeScreen.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class HomeScreen : public DiveInoScreen {
1919
void updateDate();
2020
void updateAmPm();
2121

22-
void handleButtonPress(String buttonName);
22+
int handleButtonPress(String buttonName);
2323

2424
private:
2525
bool _isMinimalModeActive = false;

DiveIno/include/screens/SurfaceScreen.h

+5-3
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,17 @@
66
#include "ezTime.h"
77

88
#include "screens/DiveInoScreen.h"
9+
#include "deco/Buhlmann.h"
910

1011
class SurfaceScreen : public DiveInoScreen {
1112

1213
public:
13-
void init(DiveInoSettings diveInoSettings);
14-
14+
void init(DiveInoSettings diveInoSettings, DiveResult* diveResult);
1515
void handleButtonPress(String buttonName);
16-
1716
private:
17+
DiveResult* _diveResult;
18+
DiveInoSettings _diveInoSettings;
19+
void _display();
1820
};
1921

2022
#endif

DiveIno/src/main.cpp

+31-14
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424

2525
#include "deco/Buhlmann.h"
2626

27-
const String VERSION_NUMBER = "2.0.8";
27+
const String VERSION_NUMBER = "2.0.9";
2828

2929
struct PressureSensorData _sensorData;
3030

@@ -66,6 +66,25 @@ MainMenu mainMenuScreen = MainMenu();
6666

6767
SettingsPicker settingsPicker;
6868

69+
/////////////////////
70+
// Utility methods //
71+
/////////////////////
72+
73+
void openDiveScreen()
74+
{
75+
_backToMenu = false;
76+
_currentScreen = SCREEN_DIVE;
77+
diveScreen.init(settingsUtils.getDiveInoSettings(), _sensorData, serialApi.isReplayEnabled(), serialApi.isEmulatorEnabled());
78+
serialApi.reset();
79+
}
80+
81+
void openSurfaceScreen()
82+
{
83+
_backToMenu = false;
84+
_currentScreen = SCREEN_SURFACE;
85+
surfaceScreen.init(settingsUtils.getDiveInoSettings(), diveScreen.getDiveResult());
86+
}
87+
6988
///////////////////////
7089
// Lifecycle methods //
7190
///////////////////////
@@ -126,10 +145,7 @@ void loop()
126145
homeScreen.initHomeScreen(settingsUtils.getDiveInoSettings());
127146
break;
128147
case 1:
129-
_backToMenu = false;
130-
_currentScreen = SCREEN_DIVE;
131-
diveScreen.init(settingsUtils.getDiveInoSettings(), _sensorData, serialApi.isReplayEnabled(), serialApi.isEmulatorEnabled());
132-
serialApi.reset();
148+
openDiveScreen();
133149
break;
134150
case 2:
135151
_backToMenu = false;
@@ -143,9 +159,7 @@ void loop()
143159
logbookScreen.init(settingsUtils.getDiveInoSettings());
144160
break;
145161
case 4:
146-
_backToMenu = false;
147-
_currentScreen = SCREEN_SURFACE;
148-
surfaceScreen.init(settingsUtils.getDiveInoSettings());
162+
openSurfaceScreen();
149163
break;
150164
case 5:
151165
settingsPicker.runOnce("Settings");
@@ -164,8 +178,10 @@ void loop()
164178
//Handle button press on the current screen
165179
switch (_currentScreen)
166180
{
167-
case SCREEN_HOME:
168-
homeScreen.handleButtonPress(buttonPressed);
181+
case SCREEN_HOME:
182+
if (homeScreen.handleButtonPress(buttonPressed) == SCREEN_DIVE) {
183+
openDiveScreen();
184+
}
169185
break;
170186
case SCREEN_DIVE:
171187
diveScreen.handleButtonPress(buttonPressed);
@@ -197,11 +213,12 @@ void loop()
197213
case SCREEN_DIVE:
198214
if (minuteChanged())
199215
{
200-
diveScreen.refreshClockWidget();
201-
diveScreen.display(_sensorData);
216+
diveScreen.refreshClockWidget();
202217
}
203-
if (secondChanged()) {
204-
diveScreen.display(_sensorData);
218+
if (minuteChanged() || secondChanged()) {
219+
if (diveScreen.display(_sensorData) == SCREEN_SURFACE) {
220+
openSurfaceScreen();
221+
}
205222
}
206223
break;
207224
case SCREEN_GAUGE:

DiveIno/src/screens/DiveScreen.cpp

+16-5
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ void DiveScreen::_drawCurrentDepth(float depthInMeter)
5959
ez.canvas.color(ez.theme->foreground);
6060
ez.canvas.font(numonly7seg48);
6161

62-
ez.canvas.pos(210, 150);
62+
ez.canvas.pos(200, 150);
6363

6464
if (depthInMeter < 10) {
6565
ez.canvas.color(ez.theme->background);
@@ -382,7 +382,7 @@ void DiveScreen::stopDive()
382382

383383
Serial.println(F("DIVE - Finished"));
384384

385-
DiveResult* diveResult = _buhlmann->stopDive(ez.clock.tz.now());
385+
this->_diveResult = _buhlmann->stopDive(ez.clock.tz.now());
386386

387387
//TODO Navigate to the surface display screen
388388
}
@@ -391,14 +391,22 @@ void DiveScreen::_diveProgress(float temperatureInCelsius, float pressureInMilli
391391
_currentDiveInfo = _buhlmann->progressDive(pressureInMillibar, durationInSeconds);
392392
}
393393

394+
DiveResult* DiveScreen::getDiveResult()
395+
{
396+
return _diveResult;
397+
}
398+
394399
/////////////
395400
// Display //
396401
/////////////
397402

398-
void DiveScreen::display(PressureSensorData sensorData)
403+
int DiveScreen::display(PressureSensorData sensorData)
399404
{
400405
if (_replayEnabled) {
401-
_replayDive();
406+
if (_replayDive()) {
407+
//Once the dive was completed open the Surface Screen
408+
return SCREEN_SURFACE;
409+
}
402410
} else {
403411
if (minuteChanged())
404412
{
@@ -418,9 +426,10 @@ void DiveScreen::display(PressureSensorData sensorData)
418426
_drawCurrentDepth(currentDepthInMeter);
419427
_drawDiveIndicator();
420428
}
429+
return STAY_ON_SCREEN;
421430
}
422431

423-
void DiveScreen::_replayDive()
432+
bool DiveScreen::_replayDive()
424433
{
425434
// Check if test data is available, which comes through the serial interface
426435
if (Serial.available() > 0) {
@@ -481,8 +490,10 @@ void DiveScreen::_replayDive()
481490
_diveProgress(temperatureInCelsius, pressureInMillibar, depthInMeter, diveDurationInSeconds);
482491
this->stopDive();
483492
_replayEnabled = false;
493+
return true;
484494
}
485495
}
496+
return false;
486497
}
487498

488499
/////////////

DiveIno/src/screens/GaugeScreen.cpp

+13-2
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,19 @@ void GaugeScreen::_drawCurrentDepth(float depthInMeter)
5959
ez.canvas.color(ez.theme->foreground);
6060
ez.canvas.font(numonly7seg48);
6161

62-
ez.canvas.pos(210, 150);
63-
ez.canvas.print(depthInMeter, 1);
62+
ez.canvas.pos(200, 150);
63+
64+
if (depthInMeter < 10) {
65+
ez.canvas.color(ez.theme->background);
66+
ez.canvas.print("0");
67+
ez.canvas.color(ez.theme->foreground);
68+
ez.canvas.print(zeropad((int)depthInMeter, 1));
69+
} else {
70+
ez.canvas.print(zeropad((int)depthInMeter, 2));
71+
}
72+
73+
ez.canvas.print(".");
74+
ez.canvas.print(zeropad((int)(depthInMeter*10) % 10, 1));
6475
}
6576

6677
void GaugeScreen::_drawMaximumDepth(float depthInMeter)

DiveIno/src/screens/HomeScreen.cpp

+5-4
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ void HomeScreen::updateAmPm()
4141

4242
void HomeScreen::initHomeScreen(DiveInoSettings diveInoSettings)
4343
{
44-
_diveInoSettings = diveInoSettings;
44+
_diveInoSettings = diveInoSettings;
4545

4646
ez.screen.clear();
4747
ez.header.show("DiveIno");
@@ -112,7 +112,7 @@ void HomeScreen::displayHomeClock()
112112
}
113113
}
114114

115-
void HomeScreen::handleButtonPress(String buttonName)
115+
int HomeScreen::handleButtonPress(String buttonName)
116116
{
117117
if (buttonName == "Update")
118118
{
@@ -127,7 +127,8 @@ void HomeScreen::handleButtonPress(String buttonName)
127127
initHomeScreen(_diveInoSettings);
128128
}
129129
else if (buttonName == "Dive")
130-
{
131-
//TODO Show Dive Screen
130+
{
131+
return SCREEN_DIVE;
132132
}
133+
return STAY_ON_SCREEN;
133134
}

DiveIno/src/screens/LogbookScreen.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ void LogbookScreen::init(DiveInoSettings diveInoSettings)
55
ez.screen.clear();
66
ez.header.show("Logbook");
77

8-
ez.buttons.show("# # Menu");
8+
ez.buttons.show("Menu");
99
}
1010

1111
void LogbookScreen::handleButtonPress(String buttonName)

DiveIno/src/screens/SurfaceScreen.cpp

+67-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,76 @@
11
#include "screens/SurfaceScreen.h"
22

3-
void SurfaceScreen::init(DiveInoSettings diveInoSettings)
3+
void SurfaceScreen::init(DiveInoSettings diveInoSettings, DiveResult* diveResult)
44
{
5+
_diveInoSettings = diveInoSettings;
6+
_diveResult = diveResult;
7+
58
ez.screen.clear();
69
ez.header.show("Surface");
710

8-
ez.buttons.show("# # Menu");
11+
ez.buttons.show("Menu");
12+
13+
_display();
14+
}
15+
16+
void SurfaceScreen::_display()
17+
{
18+
19+
if (ez.theme->name == "Default") {
20+
M5.Lcd.drawJpg((uint8_t *)ok_small_jpg, (sizeof(ok_small_jpg) / sizeof(ok_small_jpg[0])), 105, 35, 32, 32);
21+
M5.Lcd.drawJpg((uint8_t *)airplane_small_jpg, (sizeof(airplane_small_jpg) / sizeof(airplane_small_jpg[0])), 105, 75, 32, 32);
22+
M5.Lcd.drawJpg((uint8_t *)max_depth_small_jpg, (sizeof(max_depth_small_jpg) / sizeof(max_depth_small_jpg[0])), 105, 115, 32, 32);
23+
M5.Lcd.drawJpg((uint8_t *)deco_stop_small_jpg, (sizeof(deco_stop_small_jpg) / sizeof(deco_stop_small_jpg[0])), 105, 155, 32, 32);
24+
}
25+
if (ez.theme->name == "Dark") {
26+
M5.Lcd.drawJpg((uint8_t *)ok_small_jpg_dark, (sizeof(ok_small_jpg_dark) / sizeof(ok_small_jpg_dark[0])), 105, 35, 32, 32);
27+
M5.Lcd.drawJpg((uint8_t *)airplane_small_jpg, (sizeof(airplane_small_jpg) / sizeof(airplane_small_jpg[0])), 105, 75, 32, 32);
28+
M5.Lcd.drawJpg((uint8_t *)max_depth_small_jpg, (sizeof(max_depth_small_jpg) / sizeof(max_depth_small_jpg[0])), 105, 115, 32, 32);
29+
M5.Lcd.drawJpg((uint8_t *)deco_stop_small_jpg_dark, (sizeof(deco_stop_small_jpg_dark) / sizeof(deco_stop_small_jpg_dark[0])), 105, 155, 32, 32);
30+
}
31+
32+
ez.canvas.color(ez.theme->foreground);
33+
ez.canvas.font(sans26);
34+
35+
if (_diveResult != NULL) {
36+
ez.canvas.pos(150, 40);
37+
ez.canvas.print(zeropad(_diveResult->durationInSeconds/60, 2)); //minutes
38+
ez.canvas.print(":");
39+
ez.canvas.print(zeropad(_diveResult->durationInSeconds%60, 2)); //seconds
40+
41+
ez.canvas.pos(150, 80);
42+
ez.canvas.print(zeropad(_diveResult->noFlyTimeInMinutes/60, 2)); //hours
43+
ez.canvas.print(":");
44+
ez.canvas.print(zeropad(_diveResult->noFlyTimeInMinutes%60, 2)); //minutes
45+
46+
ez.canvas.pos(150, 120);
47+
if (_diveInoSettings.imperialUnitsSetting) {
48+
ez.canvas.print(_diveResult->maxDepthInMeters*3.28, 0);
49+
ez.canvas.print(" ft");
50+
} else {
51+
ez.canvas.print(_diveResult->maxDepthInMeters);
52+
ez.canvas.print(" m");
53+
}
54+
55+
ez.canvas.pos(150, 160);
56+
if (_diveResult->wasDecoDive) {
57+
ez.canvas.print("yes");
58+
} else {
59+
ez.canvas.print("no");
60+
}
61+
} else {
62+
ez.canvas.pos(150, 40);
63+
ez.canvas.print("00:00");
64+
65+
ez.canvas.pos(150, 80);
66+
ez.canvas.print("00:00");
67+
68+
ez.canvas.pos(150, 120);
69+
ez.canvas.print("n/a");
70+
71+
ez.canvas.pos(150, 160);
72+
ez.canvas.print("n/a");
73+
}
974
}
1075

1176
void SurfaceScreen::handleButtonPress(String buttonName)

0 commit comments

Comments
 (0)