Added OLED Display autoscroll during periods of OLED data inactivity (#6546)
* Added OLED Display autoscroll during periods of OLED data inactivity. * Fixing compile errors * Feedback from review
This commit is contained in:
committed by
Florian Didron
parent
ca5162b90e
commit
09c4e8ac5d
@@ -114,8 +114,11 @@ bool oled_active = false;
|
|||||||
bool oled_scrolling = false;
|
bool oled_scrolling = false;
|
||||||
uint8_t oled_rotation = 0;
|
uint8_t oled_rotation = 0;
|
||||||
uint8_t oled_rotation_width = 0;
|
uint8_t oled_rotation_width = 0;
|
||||||
#if !defined(OLED_DISABLE_TIMEOUT)
|
#if OLED_TIMEOUT > 0
|
||||||
uint16_t oled_last_activity;
|
uint32_t oled_timeout;
|
||||||
|
#endif
|
||||||
|
#if OLED_SCROLL_TIMEOUT > 0
|
||||||
|
uint32_t oled_scroll_timeout;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Internal variables to reduce math instructions
|
// Internal variables to reduce math instructions
|
||||||
@@ -209,6 +212,13 @@ bool oled_init(uint8_t rotation) {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if OLED_TIMEOUT > 0
|
||||||
|
oled_timeout = timer_read32() + OLED_TIMEOUT;
|
||||||
|
#endif
|
||||||
|
#if OLED_SCROLL_TIMEOUT > 0
|
||||||
|
oled_scroll_timeout = timer_read32() + OLED_SCROLL_TIMEOUT;
|
||||||
|
#endif
|
||||||
|
|
||||||
oled_clear();
|
oled_clear();
|
||||||
oled_initialized = true;
|
oled_initialized = true;
|
||||||
oled_active = true;
|
oled_active = true;
|
||||||
@@ -454,8 +464,8 @@ void oled_write_ln_P(const char *data, bool invert) {
|
|||||||
#endif // defined(__AVR__)
|
#endif // defined(__AVR__)
|
||||||
|
|
||||||
bool oled_on(void) {
|
bool oled_on(void) {
|
||||||
#if !defined(OLED_DISABLE_TIMEOUT)
|
#if OLED_TIMEOUT > 0
|
||||||
oled_last_activity = timer_read();
|
oled_timeout = timer_read32() + OLED_TIMEOUT;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static const uint8_t PROGMEM display_on[] = { I2C_CMD, DISPLAY_ON };
|
static const uint8_t PROGMEM display_on[] = { I2C_CMD, DISPLAY_ON };
|
||||||
@@ -519,6 +529,7 @@ bool oled_scroll_off(void) {
|
|||||||
return oled_scrolling;
|
return oled_scrolling;
|
||||||
}
|
}
|
||||||
oled_scrolling = false;
|
oled_scrolling = false;
|
||||||
|
oled_dirty = -1;
|
||||||
}
|
}
|
||||||
return !oled_scrolling;
|
return !oled_scrolling;
|
||||||
}
|
}
|
||||||
@@ -546,15 +557,32 @@ void oled_task(void) {
|
|||||||
|
|
||||||
oled_task_user();
|
oled_task_user();
|
||||||
|
|
||||||
|
#if OLED_SCROLL_TIMEOUT > 0
|
||||||
|
if (oled_dirty && oled_scrolling) {
|
||||||
|
oled_scroll_timeout = timer_read32() + OLED_SCROLL_TIMEOUT;
|
||||||
|
oled_scroll_off();
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
// Smart render system, no need to check for dirty
|
// Smart render system, no need to check for dirty
|
||||||
oled_render();
|
oled_render();
|
||||||
|
|
||||||
// Display timeout check
|
// Display timeout check
|
||||||
#if !defined(OLED_DISABLE_TIMEOUT)
|
#if OLED_TIMEOUT > 0
|
||||||
if (oled_active && timer_elapsed(oled_last_activity) > OLED_TIMEOUT) {
|
if (oled_active && timer_expired32(timer_read32(), oled_timeout)) {
|
||||||
oled_off();
|
oled_off();
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if OLED_SCROLL_TIMEOUT > 0
|
||||||
|
if (!oled_scrolling && timer_expired32(timer_read32(), oled_scroll_timeout)) {
|
||||||
|
#ifdef OLED_SCROLL_TIMEOUT_RIGHT
|
||||||
|
oled_scroll_right();
|
||||||
|
#else
|
||||||
|
oled_scroll_left();
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
__attribute__((weak))
|
__attribute__((weak))
|
||||||
|
|||||||
@@ -138,10 +138,21 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||||||
#define OLED_FONT_HEIGHT 8
|
#define OLED_FONT_HEIGHT 8
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define OLED_ROTATION_0 0x00
|
#if !defined(OLED_TIMEOUT)
|
||||||
#define OLED_ROTATION_90 0x01
|
#if defined(OLED_DISABLE_TIMEOUT)
|
||||||
#define OLED_ROTATION_180 0x02
|
#define OLED_TIMEOUT 0
|
||||||
#define OLED_ROTATION_270 0x03
|
#else
|
||||||
|
#define OLED_TIMEOUT 60000
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// OLED Rotation enum values are flags
|
||||||
|
typedef enum {
|
||||||
|
OLED_ROTATION_0 = 0,
|
||||||
|
OLED_ROTATION_90 = 1,
|
||||||
|
OLED_ROTATION_180 = 2,
|
||||||
|
OLED_ROTATION_270 = 3, // OLED_ROTATION_90 | OLED_ROTATION_180
|
||||||
|
} oled_rotation_t;
|
||||||
|
|
||||||
// Initialize the oled display, rotating the rendered output based on the define passed in.
|
// Initialize the oled display, rotating the rendered output based on the define passed in.
|
||||||
// Returns true if the OLED was initialized successfully
|
// Returns true if the OLED was initialized successfully
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||||||
#define TIMER_H 1
|
#define TIMER_H 1
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
#include <stdbool.h>
|
||||||
|
|
||||||
#if defined(__AVR__)
|
#if defined(__AVR__)
|
||||||
#include "avr/timer_avr.h"
|
#include "avr/timer_avr.h"
|
||||||
@@ -46,6 +47,16 @@ uint32_t timer_read32(void);
|
|||||||
uint16_t timer_elapsed(uint16_t last);
|
uint16_t timer_elapsed(uint16_t last);
|
||||||
uint32_t timer_elapsed32(uint32_t last);
|
uint32_t timer_elapsed32(uint32_t last);
|
||||||
|
|
||||||
|
// Utility functions to check if a future time has expired & autmatically handle time wrapping if checked / reset frequently (half of max value)
|
||||||
|
inline bool timer_expired(uint16_t current, uint16_t last)
|
||||||
|
{
|
||||||
|
return current - last < 0x8000;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline bool timer_expired32(uint32_t current, uint32_t future) {
|
||||||
|
return current - future < 0x80000000;
|
||||||
|
}
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -4,14 +4,13 @@
|
|||||||
#define __DELAY_BACKWARD_COMPATIBLE__
|
#define __DELAY_BACKWARD_COMPATIBLE__
|
||||||
#include <util/delay.h>
|
#include <util/delay.h>
|
||||||
#include "common/timer.h"
|
#include "common/timer.h"
|
||||||
#include "Arduino.h"
|
|
||||||
|
|
||||||
|
|
||||||
unsigned long millis()
|
unsigned long millis(void)
|
||||||
{
|
{
|
||||||
return timer_read32();
|
return timer_read32();
|
||||||
}
|
}
|
||||||
unsigned long micros()
|
unsigned long micros(void)
|
||||||
{
|
{
|
||||||
return timer_read32() * 1000UL;
|
return timer_read32() * 1000UL;
|
||||||
}
|
}
|
||||||
@@ -23,7 +22,7 @@ void delayMicroseconds(unsigned int us)
|
|||||||
{
|
{
|
||||||
_delay_us(us);
|
_delay_us(us);
|
||||||
}
|
}
|
||||||
void init()
|
void init(void)
|
||||||
{
|
{
|
||||||
timer_init();
|
timer_init();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user