Skip to content

Commit

Permalink
small fixes
Browse files Browse the repository at this point in the history
- build in led on esp32-s2 active low
- floyd steinberg dithering improved
- add tokyo time zone
  • Loading branch information
nlimper committed Aug 12, 2023
1 parent 2817aa7 commit 56e1e9e
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 30 deletions.
18 changes: 18 additions & 0 deletions ESP32_AP-Flasher/include/leds.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,24 @@
#include <FastLED.h>
#endif

const uint8_t PROGMEM gamma8[] = {
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2,
2, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 5, 5, 5,
5, 6, 6, 6, 6, 7, 7, 7, 7, 8, 8, 8, 9, 9, 9, 10,
10, 10, 11, 11, 11, 12, 12, 13, 13, 13, 14, 14, 15, 15, 16, 16,
17, 17, 18, 18, 19, 19, 20, 20, 21, 21, 22, 22, 23, 24, 24, 25,
25, 26, 27, 27, 28, 29, 29, 30, 31, 32, 32, 33, 34, 35, 35, 36,
37, 38, 39, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 50,
51, 52, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 66, 67, 68,
69, 70, 72, 73, 74, 75, 77, 78, 79, 81, 82, 83, 85, 86, 87, 89,
90, 92, 93, 95, 96, 98, 99, 101, 102, 104, 105, 107, 109, 110, 112, 114,
115, 117, 119, 120, 122, 124, 126, 127, 129, 131, 133, 135, 137, 138, 140, 142,
144, 146, 148, 150, 152, 154, 156, 158, 160, 162, 164, 167, 169, 171, 173, 175,
177, 180, 182, 184, 186, 189, 191, 193, 196, 198, 200, 203, 205, 208, 210, 213,
215, 218, 220, 223, 225, 228, 231, 233, 236, 239, 241, 244, 247, 249, 252, 255};

void ledTask(void* parameter);
void setBrightness(int brightness);
void updateBrightnessFromConfig();
Expand Down
25 changes: 6 additions & 19 deletions ESP32_AP-Flasher/src/leds.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include <FastLED.h>
#endif

#include "leds.h"
#include "settings.h"
#include "tag_db.h"

Expand Down Expand Up @@ -32,24 +33,6 @@ struct ledInstruction {
bool reQueue = false;
};

const uint8_t PROGMEM gamma8[] = {
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2,
2, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 5, 5, 5,
5, 6, 6, 6, 6, 7, 7, 7, 7, 8, 8, 8, 9, 9, 9, 10,
10, 10, 11, 11, 11, 12, 12, 13, 13, 13, 14, 14, 15, 15, 16, 16,
17, 17, 18, 18, 19, 19, 20, 20, 21, 21, 22, 22, 23, 24, 24, 25,
25, 26, 27, 27, 28, 29, 29, 30, 31, 32, 32, 33, 34, 35, 35, 36,
37, 38, 39, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 50,
51, 52, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 66, 67, 68,
69, 70, 72, 73, 74, 75, 77, 78, 79, 81, 82, 83, 85, 86, 87, 89,
90, 92, 93, 95, 96, 98, 99, 101, 102, 104, 105, 107, 109, 110, 112, 114,
115, 117, 119, 120, 122, 124, 126, 127, 129, 131, 133, 135, 137, 138, 140, 142,
144, 146, 148, 150, 152, 154, 156, 158, 160, 162, 164, 167, 169, 171, 173, 175,
177, 180, 182, 184, 186, 189, 191, 193, 196, 198, 200, 203, 205, 208, 210, 213,
215, 218, 220, 223, 225, 228, 231, 233, 236, 239, 241, 244, 247, 249, 252, 255};

#ifdef HAS_RGB_LED

void addToRGBQueue(struct ledInstructionRGB* rgb, bool requeue) {
Expand Down Expand Up @@ -197,7 +180,11 @@ void addFadeMono(uint8_t value) {
}

void showMono(uint8_t brightness) {
#ifdef CONFIG_IDF_TARGET_ESP32S2
ledcWrite(7, gamma8[brightness]);
#else
ledcWrite(7, 255 - gamma8[brightness]);
#endif
}

void quickBlink(uint8_t repeat) {
Expand Down Expand Up @@ -335,7 +322,7 @@ void ledTask(void* parameter) {
showMono(monoled->value);
}
} else {
//monoIdleStep();
// monoIdleStep();
}
} else {
if (monoled->fadeTime) {
Expand Down
26 changes: 15 additions & 11 deletions ESP32_AP-Flasher/src/makeimage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include <web.h>

#include "storage.h"
#include "leds.h"

TFT_eSPI tft = TFT_eSPI();
TFT_eSprite spr = TFT_eSprite(&tft);
Expand Down Expand Up @@ -64,16 +65,19 @@ struct Color {
};

struct Error {
float r;
float g;
float b;
int32_t r;
int32_t g;
int32_t b;
};

uint32_t colorDistance(const Color &c1, const Color &c2, const Error &e1) {
int32_t r_diff = c1.r + e1.r - c2.r;
int32_t g_diff = c1.g + e1.g - c2.g;
int32_t b_diff = c1.b + e1.b - c2.b;
return 3 * r_diff * r_diff + 6 * g_diff * g_diff + b_diff * b_diff;
uint32_t colorDistance(Color &c1, Color &c2, Error &e1) {
e1.r = constrain(e1.r, -255, 255);
e1.g = constrain(e1.g, -255, 255);
e1.b = constrain(e1.b, -255, 255);
int32_t r_diff = gamma8[c1.r] + e1.r - gamma8[c2.r];
int32_t g_diff = gamma8[c1.g] + e1.g - gamma8[c2.g];
int32_t b_diff = gamma8[c1.b] + e1.b - gamma8[c2.b];
return 22 * r_diff * r_diff + 50 * g_diff * g_diff + 20 * b_diff * b_diff;
}

void spr2color(TFT_eSprite &spr, imgParam &imageParams, uint8_t *buffer, size_t buffer_size, bool is_red) {
Expand Down Expand Up @@ -155,9 +159,9 @@ void spr2color(TFT_eSprite &spr, imgParam &imageParams, uint8_t *buffer, size_t

if (imageParams.dither) {
Error error = {
static_cast<float>(color.r) + error_bufferold[x].r - static_cast<float>(palette[best_color_index].r),
static_cast<float>(color.g) + error_bufferold[x].g - static_cast<float>(palette[best_color_index].g),
static_cast<float>(color.b) + error_bufferold[x].b - static_cast<float>(palette[best_color_index].b)};
color.r + error_bufferold[x].r - palette[best_color_index].r,
color.g + error_bufferold[x].g - palette[best_color_index].g,
color.b + error_bufferold[x].b - palette[best_color_index].b};

// Burkes Dithering
error_buffernew[x].r += error.r / 4.0f;
Expand Down
1 change: 1 addition & 0 deletions ESP32_AP-Flasher/wwwroot/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ <h3>Access Point config</h3>
<option value="NZST-12NZDT-13,M9.4.0/02:00:00,M4.1.0/03:00:00">New Zealand</option>
</optgroup>
<optgroup label="Asia">
<option value="JST-9">Tokyo</option>
<option value="WIB-7">Jakarta</option>
<option value="GMT+2">Jerusalem</option>
<option value="SGT-8">Singapore</option>
Expand Down

0 comments on commit 56e1e9e

Please sign in to comment.