Skip to content

Commit 76b3be3

Browse files
committed
work in progress
- button / switch off not reliable? - display of process not in all cases
1 parent 45fde04 commit 76b3be3

File tree

10 files changed

+44
-17
lines changed

10 files changed

+44
-17
lines changed

.github/fake-cc

100755100644
File mode changed.

.idea/codeStyles/Project.xml

Lines changed: 0 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

100755100644
File mode changed.

src/OpenBikeSensorFirmware.cpp

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ Gps gps;
7777
static const long BLUETOOTH_INTERVAL_MILLIS = 100;
7878
static long lastBluetoothInterval = 0;
7979

80-
static const long DISPLAY_INTERVAL_MILLIS = 200;
80+
static const long DISPLAY_INTERVAL_MILLIS = 300;
8181
static long lastDisplayInterval = 0;
8282

8383
float TemperatureValue = -1;
@@ -103,7 +103,7 @@ CircularBuffer<DataSet*, 10> dataBuffer;
103103
FileWriter* writer;
104104

105105
const uint8_t displayAddress = 0x3c;
106-
const uint16_t BUTTON_PRESS_THRESHOLD_FOR_SHUTDOWN_MS = 10000;
106+
constexpr uint16_t BUTTON_PRESS_THRESHOLD_FOR_SHUTDOWN_MS = 5000;
107107

108108
// Enable dev-mode. Allows to
109109
// - set wifi config
@@ -235,26 +235,29 @@ static uint8_t shutdownState = 0;
235235
static unsigned long timeOfLastPowerKeepAlive = 0;
236236
static void powerKeepAliveTimerISR()
237237
{
238+
unsigned long now = millis();
239+
238240
// Send "keep alive" trigger to power management module
239241
// This is done by toggling the pin every 300 ms or more
240242
if(shutdownState == 0)
241243
{
242-
unsigned long timeSinceLastPowerKeepAlive = millis() - timeOfLastPowerKeepAlive;
244+
unsigned long timeSinceLastPowerKeepAlive = now - timeOfLastPowerKeepAlive;
243245
bool ip5306ButtonState = digitalRead(IP5306_BUTTON);
244246

245247
if(!ip5306ButtonState && timeSinceLastPowerKeepAlive > POWER_KEEP_ALIVE_INTERVAL_MS)
246248
{
247-
timeOfLastPowerKeepAlive = millis();
249+
timeOfLastPowerKeepAlive = now;
248250
digitalWrite(IP5306_BUTTON, HIGH);
249251
}
250252
else if(ip5306ButtonState && timeSinceLastPowerKeepAlive > 300)
251253
{
252-
timeOfLastPowerKeepAlive = millis();
254+
timeOfLastPowerKeepAlive = now;
253255
digitalWrite(IP5306_BUTTON, LOW);
254256
}
255257
}
256258

257-
if(shutdownState == 0 && button.read() && button.getCurrentStateMillis() >= BUTTON_PRESS_THRESHOLD_FOR_SHUTDOWN_MS) {
259+
if(shutdownState == 0 && button.handle(now)
260+
&& button.getCurrentStateMillis() >= BUTTON_PRESS_THRESHOLD_FOR_SHUTDOWN_MS) {
258261
shutdownState = 1;
259262
}
260263
switch(shutdownState)

src/configServer.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -509,6 +509,7 @@ String getIp() {
509509
}
510510

511511
void updateDisplay(DisplayDevice * const display, String action = "") {
512+
obsDisplay->handleShutdownDisplay();
512513
if (action.isEmpty()) {
513514
display->showTextOnGrid(0, 0, "Ver.:");
514515
display->showTextOnGrid(1, 0, OBSVersion);
@@ -2068,6 +2069,7 @@ void configServerHandle() {
20682069
if (obsImprov) {
20692070
obsImprov->handle();
20702071
}
2072+
obsDisplay->handleShutdownDisplay();
20712073
}
20722074

20732075
std::vector<std::pair<String,String>> extractParameters(HTTPRequest *req) {

src/displays.cpp

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,30 @@ void DisplayDevice::displaySimple(uint16_t value) {
5454
this->prepareTextOnGrid(3, 2, "cm", MEDIUM_FONT, -7, -5);
5555
}
5656

57+
bool startedShutdownDisplay = false;
58+
59+
bool DisplayDevice::handleShutdownDisplay()
60+
{
61+
bool updated = false;
62+
#ifdef OBSPRO
63+
bool buttonPressed = button.getState();
64+
if (buttonPressed && button.getCurrentStateMillis() > 3000)
65+
{
66+
auto pressTimeMs = button.getCurrentStateMillis() - 3000;
67+
// black out the display from top to bottom for so that after 7000 ms the whole display is black
68+
auto linesToFill = (pressTimeMs * 64) / (BUTTON_PRESS_THRESHOLD_FOR_SHUTDOWN_MS - 3000);
69+
70+
m_display->drawBox(0, 0, 128, linesToFill);
71+
startedShutdownDisplay = true;
72+
} else if (startedShutdownDisplay) {
73+
startedShutdownDisplay = false;
74+
clear();
75+
updated = true;
76+
}
77+
#endif
78+
return updated;
79+
}
80+
5781
void DisplayDevice::showValues(
5882
uint16_t sensor1MinDistance, const char* sensor1Location, uint16_t sensor1RawDistance,
5983
uint16_t sensor2MinDistance, const char* sensor2Location, uint16_t sensor2RawDistance, uint16_t sensor2Distance,
@@ -138,9 +162,8 @@ void DisplayDevice::showValues(
138162
if(BMP280_active == true)
139163
showTemperatureValue(TemperaturValue);
140164
}
141-
165+
handleShutdownDisplay();
142166
m_display->updateDisplay();
143-
144167
}
145168

146169
void DisplayDevice::showGPS(uint8_t sats) {

src/displays.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ class DisplayDevice {
100100
uint8_t scrollUp();
101101
uint8_t startLine();
102102
void highlight(uint32_t highlightTimeMillis = 500);
103+
bool handleShutdownDisplay();
103104

104105
//##############################################################
105106
// Basic display configuration

src/globals.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,5 +73,6 @@ extern Gps gps;
7373

7474
extern const uint8_t LEFT_SENSOR_ID;
7575
extern const uint8_t RIGHT_SENSOR_ID;
76+
extern const uint16_t BUTTON_PRESS_THRESHOLD_FOR_SHUTDOWN_MS;
7677

7778
#endif

src/utils/button.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,11 @@ Button::Button(int pin) : mPin(pin) {
3131
mLastState = mLastRawState = read();
3232
}
3333

34-
void Button::handle() {
35-
handle(millis());
34+
bool Button::handle() {
35+
return handle(millis());
3636
}
3737

38-
void Button::handle(unsigned long millis) {
38+
bool Button::handle(unsigned long millis) {
3939
const int state = read();
4040

4141
if (state != mLastRawState) {
@@ -52,6 +52,7 @@ void Button::handle(unsigned long millis) {
5252
mReleaseEvents++;
5353
}
5454
}
55+
return state;
5556
}
5657

5758
bool Button::gotPressed() {

src/utils/button.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@
2828
class Button {
2929
public:
3030
explicit Button(int pin);
31-
void handle();
32-
void handle(unsigned long millis);
31+
bool handle();
32+
bool handle(unsigned long millis);
3333
int read() const;
3434
int getState() const;
3535
bool gotPressed();

0 commit comments

Comments
 (0)