Skip to content

Commit d5ce869

Browse files
committed
perf: improve performance on pixel brightness
1 parent 35551d9 commit d5ce869

File tree

2 files changed

+17
-18
lines changed

2 files changed

+17
-18
lines changed

src/plugins/DrawPlugin.cpp

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,14 @@
22

33
void DrawPlugin::setup()
44
{
5-
delay(1000);
5+
delay(50);
66
Screen.clear();
7-
if (Screen.isCacheEmpty())
8-
{
9-
Screen.loadFromStorage();
10-
}
11-
else
12-
{
13-
Screen.restoreCache();
14-
}
7+
Screen.loadFromStorage();
158
#ifdef ENABLE_SERVER
169
sendInfo();
1710
#endif
1811
}
1912

20-
void DrawPlugin::teardown()
21-
{
22-
Screen.cacheCurrent();
23-
}
24-
2513
void DrawPlugin::websocketHook(DynamicJsonDocument &request)
2614
{
2715
const char *event = request["event"];

src/screen.cpp

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ void Screen_::setBrightness(uint8_t brightness, bool shouldStore)
1717
brightness_ = brightness;
1818

1919
#ifndef ESP8266
20-
// analogWrite disable the timer1 interrupt on esp8266
21-
analogWrite(PIN_ENABLE, 255 - brightness);
20+
pinMode(PIN_ENABLE, OUTPUT);
21+
digitalWrite(PIN_ENABLE, LOW);
2222
#endif
2323

2424
#ifdef ENABLE_STORAGE
@@ -157,6 +157,10 @@ void Screen_::setup()
157157

158158
// TODO find proper unused pins for MISO and SS
159159
#ifdef ESP8266
160+
// Initialize control pins
161+
pinMode(PIN_LATCH, OUTPUT);
162+
digitalWrite(PIN_LATCH, LOW);
163+
160164
SPI.pins(PIN_CLOCK, 12, PIN_DATA, 15); // SCLK, MISO, MOSI, SS);
161165
SPI.begin();
162166
SPI.beginTransaction(SPISettings(10000000, MSBFIRST, SPI_MODE0));
@@ -167,7 +171,13 @@ void Screen_::setup()
167171
#endif
168172

169173
#ifdef ESP32
170-
SPI.begin(PIN_CLOCK, 34, PIN_DATA, 25); // SCLK, MISO, MOSI, SS
174+
// Initialize control pins
175+
pinMode(PIN_LATCH, OUTPUT);
176+
pinMode(PIN_ENABLE, OUTPUT);
177+
digitalWrite(PIN_LATCH, LOW);
178+
digitalWrite(PIN_ENABLE, LOW);
179+
180+
SPI.begin(PIN_CLOCK, -1, PIN_DATA, -1); // SCLK, MISO, MOSI, SS (-1 for unused pins)
171181
SPI.beginTransaction(SPISettings(10000000, MSBFIRST, SPI_MODE0));
172182

173183
hw_timer_t *Screen_timer = timerBegin(1000000);
@@ -262,7 +272,8 @@ ICACHE_RAM_ATTR void Screen_::_render()
262272

263273
for (int idx = 0; idx < ROWS * COLS; idx++)
264274
{
265-
bits[idx >> 3] |= (buf[positions[idx]] > counter ? 0x80 : 0) >> (idx & 7);
275+
uint16_t scaledValue = ((uint16_t)buf[positions[idx]] * brightness_) / 255;
276+
bits[idx >> 3] |= (scaledValue > counter ? 0x80 : 0) >> (idx & 7);
266277
}
267278

268279
counter += (256 / GRAY_LEVELS);

0 commit comments

Comments
 (0)