Skip to content

Keep display highlight after confirm for 500ms (fixes #254) #271

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 5, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 1 addition & 12 deletions src/OpenBikeSensorFirmware.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -462,12 +462,7 @@ void loop() {
reportBluetooth();
if (button.gotPressed()) { // after button was released, detect long press here
// immediate user feedback - we start the action
// invert state might be a bit long - it does not block next confirmation.
if (config.displayConfig & DisplayInvert) {
displayTest->normalDisplay();
} else {
displayTest->invert();
}
displayTest->highlight();

transmitConfirmedData = true;
numButtonReleased++;
Expand Down Expand Up @@ -535,12 +530,6 @@ void loop() {
log_i("Confirmed data flushed to sd.");
transmitConfirmedData = false;
}
// back to normal display mode
if (config.displayConfig & DisplayInvert) {
displayTest->invert();
} else {
displayTest->normalDisplay();
}
}
log_d("Time in loop: %lums %d inner loops, %d measures, %s , %d",
currentTimeMillis - startTimeMillis, loops, lastMeasurements,
Expand Down
25 changes: 25 additions & 0 deletions src/displays.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ void SSD1306DisplayDevice::showValues(
HCSR04SensorInfo sensor1, HCSR04SensorInfo sensor2, uint16_t minDistanceToConfirm, int16_t batteryPercentage,
int16_t TemperaturValue, int lastMeasurements, boolean insidePrivacyArea,
double speed, uint8_t satellites) {

handleHighlight();
// Show sensor1, when DisplaySimple or DisplayLeft is configured
if (config.displayConfig & DisplaySimple || config.displayConfig & DisplayLeft) {
uint16_t value1 = sensor1.minDistance;
Expand Down Expand Up @@ -270,3 +272,26 @@ uint8_t SSD1306DisplayDevice::scrollUp() {
uint8_t SSD1306DisplayDevice::startLine() {
return mCurrentLine = 0;
}

void SSD1306DisplayDevice::highlight(uint32_t highlightTimeMillis) {
mHighlightTill = millis() + highlightTimeMillis;
if (!mHighlighted) {
if (mInverted) {
m_display->normalDisplay();
} else {
m_display->invertDisplay();
}
mHighlighted = true;
}
}

void SSD1306DisplayDevice::handleHighlight() {
if (mHighlighted && mHighlightTill < millis()) {
if (mInverted) {
m_display->invertDisplay();
} else {
m_display->normalDisplay();
}
mHighlighted = false;
}
}
7 changes: 7 additions & 0 deletions src/displays.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,14 @@ class DisplayDevice {

class SSD1306DisplayDevice : public DisplayDevice {
private:
void handleHighlight();
SSD1306* m_display;
String gridText[ 4 ][ 6 ];
uint8_t mLastProgress = 255;
uint8_t mCurrentLine = 0;
bool mInverted = false;
uint32_t mHighlightTill = 0;
bool mHighlighted = false;

public:
SSD1306DisplayDevice() : DisplayDevice() {
Expand All @@ -95,6 +99,7 @@ class SSD1306DisplayDevice : public DisplayDevice {
uint8_t newLine();
uint8_t scrollUp();
uint8_t startLine();
void highlight(uint32_t highlightTimeMillis = 500);

//##############################################################
// Basic display configuration
Expand All @@ -103,11 +108,13 @@ class SSD1306DisplayDevice : public DisplayDevice {
void invert() {
m_display->invertDisplay();
m_display->display();
mInverted = true;
}

void normalDisplay() {
m_display->normalDisplay();
m_display->display();
mInverted = false;
}

void flipScreen() {
Expand Down