Skip to content

Commit

Permalink
V0.92
Browse files Browse the repository at this point in the history
v0.92

- Adds christmas overlay, during holidays its enabled by default. You can turn it off by set let_it_snow to false in the dev.json

- Fixes bitmap y offset in drawing function.
- Allows to set the DFPlayer volume via settings api
- Fixes a bug where stats are not send if you set "sensor_reading" to false on the awtrix2_upgrade firmware.
- fixes x position movement for base64 icons
- base64 icons are detected by stringlength (>64) instead of trailing"="

Since everyone finds the brightness control either too bright or too dark, a few new factors (ldr_factor, ldr_gamma) have been added in dev.json that can be played with.
  • Loading branch information
Blueforcer committed Dec 23, 2023
1 parent 3867f68 commit 341dea2
Show file tree
Hide file tree
Showing 10 changed files with 119 additions and 38 deletions.
3 changes: 2 additions & 1 deletion docs/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,8 @@ You can adjust each property in the JSON object according to your preferences. I
| `HUM` | boolean | Enable or disable the native humidity app (requires reboot). | `true`/`false` | true |
| `TEMP` | boolean | Enable or disable the native temperature app (requires reboot). | `true`/`false` | true |
| `BAT` | boolean | Enable or disable the native battery app (requires reboot). | `true`/`false` | true |
| `MATP` | boolean | Enable or disable the matrix. Similar to `power` Endpoint but without the animation. | `true`/`false` | true |
| `MATP` | boolean | Enable or disable the matrix. Similar to `power` Endpoint but without the animation. | `true`/`false` | true |
| `VOL` | integer | Allows to set the Volume of the DFplayer (Only for **old** AWTRIX2.0 upgrades ) | 0-30 | true |

**Color Values**: Can either be an RGB array (e.g., `[255,0,0]`) or a valid 6-digit hexadecimal color value (e.g., "#FF0000" for red).

Expand Down
5 changes: 4 additions & 1 deletion docs/dev.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,14 @@ The JSON object has the following properties:
| `hum_offset` | float | Sets the offset for the internal humidity measurement | `0` |
| `min_brightness` | integer | Sets minimum brightness level for the Autobrightness control | `2` |
| `max_brightness` | integer | Sets maximum brightness level for the Autobrightness control. On high levels, this could result in overheating! | `180` |
| `ldr_gamma` | float | Allows to set the gammacorrection of the brightness control | 3.0 |
| `ldr_factor` | float | This factor is calculated into the raw ldr value wich is 0-1023 | 1.0 |
| `min_battery` | integer | Calibrates the minimum battery measurement by the given raw value. You will get that from the stats api | `475` |
| `max_battery` | integer | Calibrates the maximum battery measurement by the given raw value. You will get that from the stats api | `665` |
| `ha_prefix` | string | Sets the prefix for Homassistant discovery | `homeassistant` |
| `background_effect` | string | Sets an [effect](https://blueforcer.github.io/awtrix-light/#/effects) as global background layer | - |
| `stats_interval` | integer | Sets the interval in milliseconds when awtrix should send its stats to HA and MQTT | 10000 |
| `debug_mode` | boolean | Enables serial debug outputs. | false |
| `dfplayer` | boolean | Enables DFPLayer for Awtrix2_conversation builds. | false |
| `button_callback` | string | http callback url for button presses. | - |
| `button_callback` | string | http callback url for button presses. | - |
| `let_it_snow` | boolean | Let it snow as a global Overlay. | true for christmastime |
18 changes: 14 additions & 4 deletions src/DisplayManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -621,7 +621,7 @@ bool DisplayManager_::generateCustomPage(const String &name, JsonObject doc, boo
{
String newIconName = doc["icon"].as<String>();

if (newIconName.endsWith("="))
if (newIconName.length()>64)
{
customApp.jpegDataSize = decode_base64((const unsigned char *)newIconName.c_str(), customApp.jpegDataBuffer);
customApp.isGif = false;
Expand Down Expand Up @@ -901,7 +901,7 @@ bool DisplayManager_::generateNotification(uint8_t source, const char *json)
{
String iconValue = doc["icon"].as<String>();

if (iconValue.endsWith("="))
if (iconValue.length()>64)
{
newNotification.jpegDataSize = decode_base64((const unsigned char *)iconValue.c_str(), newNotification.jpegDataBuffer);
newNotification.isGif = false;
Expand Down Expand Up @@ -1094,7 +1094,7 @@ void DisplayManager_::setup()
ui->setTargetFPS(MATRIX_FPS);
ui->setTimePerApp(TIME_PER_APP);
ui->setTimePerTransition(TIME_PER_TRANSITION);
ui->setOverlays(overlays, 3);
ui->setOverlays(overlays, 4);
ui->setBackgroundEffect(BACKGROUND_EFFECT);
setAutoTransition(AUTO_TRANSITION);
ui->init();
Expand Down Expand Up @@ -1951,6 +1951,7 @@ String DisplayManager_::getSettings()
doc["HUM"] = SHOW_HUM;
doc["TEMP"] = SHOW_TEMP;
doc["BAT"] = SHOW_BAT;

String jsonString;
return serializeJson(doc, jsonString), jsonString;
}
Expand Down Expand Up @@ -2001,6 +2002,15 @@ void DisplayManager_::setNewSettings(const char *json)
SHOW_HUM = doc.containsKey("HUM") ? doc["HUM"].as<bool>() : SHOW_HUM;
SHOW_TEMP = doc.containsKey("TEMP") ? doc["TEMP"].as<bool>() : SHOW_TEMP;
SHOW_BAT = doc.containsKey("BAT") ? doc["BAT"].as<bool>() : SHOW_BAT;

#ifndef ULANZI
if (doc.containsKey("VOL"))
{
DFP_VOLUME = doc["VOL"];
PeripheryManager.setVolume(DFP_VOLUME);
}
#endif

if (doc.containsKey("CCORRECTION"))
{
auto colorValue = doc["CCORRECTION"];
Expand Down Expand Up @@ -2310,7 +2320,7 @@ void DisplayManager_::processDrawInstructions(int16_t xOffset, int16_t yOffset,
{
for (int col = 0; col < width; ++col)
{
matrix->drawPixel(x + col, y + row, bitmap[bitmapIndex++]);
matrix->drawPixel(x + col + xOffset, y + row + yOffset, bitmap[bitmapIndex++]);
}
}
}
Expand Down
32 changes: 24 additions & 8 deletions src/Globals.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,16 @@ void loadDevSettings()
MAX_BRIGHTNESS = doc["max_brightness"];
}

if (doc.containsKey("ldr_factor"))
{
LDR_FACTOR = doc["ldr_factor"].as<float>();
}

if (doc.containsKey("ldr_gamma"))
{
LDR_GAMMA = doc["ldr_gamma"].as<float>();
}

if (doc.containsKey("hum_offset"))
{
HUM_OFFSET = doc["hum_offset"];
Expand Down Expand Up @@ -156,7 +166,12 @@ void loadDevSettings()
DEBUG_MODE = doc["debug_mode"].as<bool>();
}

if (doc.containsKey("button_callback"))
if (doc.containsKey("let_it_snow"))
{
SNOW = doc["let_it_snow"].as<bool>();
}

if (doc.containsKey("button_callback"))
{
BUTTON_CALLBACK = doc["button_callback"].as<String>();
}
Expand Down Expand Up @@ -245,8 +260,7 @@ void loadSettings()
#endif
SOUND_ACTIVE = Settings.getBool("SOUND", true);
#ifndef ULANZI
VOLUME_PERCENT = Settings.getUInt("VOL", 50);
VOLUME = map(VOLUME_PERCENT, 0, 100, 0, 30);
DFP_VOLUME = Settings.getUInt("VOL", 20);
#endif
Settings.end();
uniqueID = getID();
Expand Down Expand Up @@ -296,7 +310,7 @@ void saveSettings()
#endif
Settings.putBool("SOUND", SOUND_ACTIVE);
#ifndef ULANZI
Settings.putUInt("VOL", VOLUME_PERCENT);
Settings.putUInt("VOL", DFP_VOLUME);
#endif
Settings.end();
}
Expand All @@ -307,7 +321,7 @@ IPAddress gateway;
IPAddress subnet;
IPAddress primaryDNS;
IPAddress secondaryDNS;
const char *VERSION = "0.91";
const char *VERSION = "0.92";

String MQTT_HOST = "";
uint16_t MQTT_PORT = 1883;
Expand Down Expand Up @@ -378,8 +392,7 @@ bool SOUND_ACTIVE;
String BOOT_SOUND = "";
int TEMP_DECIMAL_PLACES = 0;
#ifndef ULANZI
uint8_t VOLUME_PERCENT;
uint8_t VOLUME;
uint8_t DFP_VOLUME;
#endif
int MATRIX_LAYOUT = 0;
bool UPDATE_AVAILABLE = false;
Expand Down Expand Up @@ -415,4 +428,7 @@ double movementFactor = 0.5;
int8_t TRANS_EFFECT = 1;
String AUTH_USER = "";
String AUTH_PASS = "awtrix";
String BUTTON_CALLBACK = "";
String BUTTON_CALLBACK = "";
bool SNOW = true;
float LDR_GAMMA = 3.0;
float LDR_FACTOR = 1.0;
8 changes: 5 additions & 3 deletions src/Globals.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,7 @@ extern bool SOUND_ACTIVE;
extern String BOOT_SOUND;
extern int TEMP_DECIMAL_PLACES;
#ifndef ULANZI
extern uint8_t VOLUME_PERCENT;
extern uint8_t VOLUME;
extern uint8_t DFP_VOLUME;
#endif
extern int MATRIX_LAYOUT;
extern bool UPDATE_AVAILABLE;
Expand Down Expand Up @@ -135,8 +134,11 @@ extern bool MOODLIGHT_MODE;
extern double movementFactor;
extern uint8_t MIN_BRIGHTNESS;
extern uint8_t MAX_BRIGHTNESS;
extern float LDR_GAMMA;
extern float LDR_FACTOR;
extern bool DEBUG_MODE;
extern String AUTH_USER;
extern String AUTH_PASS;
extern String BUTTON_CALLBACK;
#endif // Globals_H
extern bool SNOW;
#endif // Globals_H
17 changes: 8 additions & 9 deletions src/MenuManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ String MenuManager_::menutext()
break;
#ifndef ULANZI
case VolumeMenu:
return String(VOLUME_PERCENT) + "%";
return String(DFP_VOLUME);
#endif
default:
break;
Expand Down Expand Up @@ -272,10 +272,10 @@ void MenuManager_::rightButton()
break;
#ifdef awtrix2_upgrade
case VolumeMenu:
if ((VOLUME_PERCENT + 1) > 100)
VOLUME_PERCENT = 0;
if ((DFP_VOLUME + 1) > 30)
DFP_VOLUME = 0;
else
VOLUME_PERCENT++;
DFP_VOLUME++;
#endif
default:
break;
Expand Down Expand Up @@ -333,10 +333,10 @@ void MenuManager_::leftButton()
break;
#ifdef awtrix2_upgrade
case VolumeMenu:
if ((VOLUME_PERCENT - 1) < 0)
VOLUME_PERCENT = 100;
if ((DFP_VOLUME - 1) < 0)
DFP_VOLUME = 30;
else
VOLUME_PERCENT--;
DFP_VOLUME--;
#endif
default:
break;
Expand Down Expand Up @@ -492,8 +492,7 @@ void MenuManager_::selectButtonLong()
break;
#ifdef awtrix2_upgrade
case VolumeMenu:
VOLUME = map(VOLUME_PERCENT, 0, 100, 0, 30);
PeripheryManager.setVolume(VOLUME);
PeripheryManager.setVolume(DFP_VOLUME);
saveSettings();
break;
#endif
Expand Down
47 changes: 43 additions & 4 deletions src/Overlays.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,54 @@ void StatusOverlay(FastLED_NeoMatrix *matrix, MatrixDisplayUiState *state, GifPl

void MenuOverlay(FastLED_NeoMatrix *matrix, MatrixDisplayUiState *state, GifPlayer *gifPlayer)
{

if (!MenuManager.inMenu)
return;

matrix->fillScreen(0);
DisplayManager.setTextColor(0xFFFFFF);
DisplayManager.printText(0, 6, utf8ascii(MenuManager.menutext()).c_str(), true, 2);
}

CRGB snowLeds[32][8];
uint8_t updateFrame = 0;

void SnowOverlay(FastLED_NeoMatrix *matrix, MatrixDisplayUiState *state, GifPlayer *gifPlayer)
{
if (!SNOW)
return;

if (random8() < 20)
{
int randomColumn = random8(32);
snowLeds[randomColumn][0] = CHSV(0, 0, 255);
}

if (++updateFrame >= 5)
{
for (int i = 0; i < 32; i++)
{
for (int j = 7; j > 0; j--)
{
snowLeds[i][j] = snowLeds[i][j - 1];
}
snowLeds[i][0] = CRGB::Black;
}
updateFrame = 0;
}

for (int i = 0; i < 32; i++)
{
for (int j = 0; j < 8; j++)
{
if (snowLeds[i][j])
{
matrix->drawPixel(i, j, snowLeds[i][j]);
}
}
}
}

void NotifyOverlay(FastLED_NeoMatrix *matrix, MatrixDisplayUiState *state, GifPlayer *gifPlayer)
{
// Check if notification flag is set
Expand Down Expand Up @@ -143,7 +182,7 @@ void NotifyOverlay(FastLED_NeoMatrix *matrix, MatrixDisplayUiState *state, GifPl
iconWidth = 8;
if (notifications[0].jpegDataSize > 0)
{
DisplayManager.drawJPG(0, 0, notifications[0].jpegDataBuffer, notifications[0].jpegDataSize);
DisplayManager.drawJPG(notifications[0].iconPosition + notifications[0].iconOffset, 0, notifications[0].jpegDataBuffer, notifications[0].jpegDataSize);
}
else
{
Expand Down Expand Up @@ -363,4 +402,4 @@ void NotifyOverlay(FastLED_NeoMatrix *matrix, MatrixDisplayUiState *state, GifPl
DisplayManager.getInstance().resetTextColor();
}

OverlayCallback overlays[] = {MenuOverlay, NotifyOverlay, StatusOverlay};
OverlayCallback overlays[] = {MenuOverlay, NotifyOverlay, StatusOverlay, SnowOverlay};
2 changes: 2 additions & 0 deletions src/Overlays.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,5 +60,7 @@ void MenuOverlay(FastLED_NeoMatrix *matrix, MatrixDisplayUiState *state, GifPlay

void NotifyOverlay(FastLED_NeoMatrix *matrix, MatrixDisplayUiState *state, GifPlayer *gifPlayer);

void SnowOverlay(FastLED_NeoMatrix *matrix, MatrixDisplayUiState *state, GifPlayer *gifPlayer);

extern OverlayCallback overlays[];
#endif
22 changes: 15 additions & 7 deletions src/PeripheryManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ void PeripheryManager_::setup()
{
dfmp3.begin();
delay(100);
setVolume(VOLUME);
setVolume(DFP_VOLUME);
}

#endif
Expand Down Expand Up @@ -442,7 +442,8 @@ void PeripheryManager_::tick()
uint16_t ADCVALUE = analogRead(BATTERY_PIN);
// Discard values that are totally out of range, especially the first value read after a reboot.
// Meaningful values for a Ulanzi are in the range 400..700
if ((ADCVALUE > 100) && (ADCVALUE < 1000)) {
if ((ADCVALUE > 100) && (ADCVALUE < 1000))
{
BATTERY_PERCENT = max(min((int)map(ADCVALUE, MIN_BATTERY, MAX_BATTERY, 0, 100), 100), 0);
BATTERY_RAW = ADCVALUE;
SENSORS_STABLE = true;
Expand Down Expand Up @@ -479,8 +480,13 @@ void PeripheryManager_::tick()
CURRENT_TEMP += TEMP_OFFSET;
CURRENT_HUM += HUM_OFFSET;
}
else
{
SENSORS_STABLE = true;
}
}


unsigned long currentMillis_LDR = millis();
if (currentMillis_LDR - previousMillis_LDR >= interval_LDR)
{
Expand All @@ -498,8 +504,8 @@ void PeripheryManager_::tick()
CURRENT_LUX = (roundf(photocell.getSmoothedLux() * 1000) / 1000);
if (AUTO_BRIGHTNESS && !MATRIX_OFF)
{
brightnessPercent = sampleAverage / 1023.0 * 100.0;
brightnessPercent = (brightnessPercent * brightnessPercent * brightnessPercent) / (100.0 * 100.0); // apply gamma correction (gamma = 3)
brightnessPercent = (sampleAverage * LDR_FACTOR) / 1023.0 * 100.0;
brightnessPercent = pow(brightnessPercent, LDR_GAMMA) / pow(100.0, LDR_GAMMA - 1);
BRIGHTNESS = map(brightnessPercent, 0, 100, MIN_BRIGHTNESS, MAX_BRIGHTNESS);
DisplayManager.setBrightness(BRIGHTNESS);
}
Expand All @@ -512,10 +518,13 @@ unsigned long long PeripheryManager_::readUptime()
static unsigned long long totalElapsed = 0;

unsigned long currentTime = millis();
if (currentTime < lastTime) {
if (currentTime < lastTime)
{
// millis() overflow
totalElapsed += 4294967295UL - lastTime + currentTime + 1;
} else {
}
else
{
totalElapsed += currentTime - lastTime;
}
lastTime = currentTime;
Expand All @@ -524,7 +533,6 @@ unsigned long long PeripheryManager_::readUptime()
return uptimeSeconds;
}


void PeripheryManager_::r2d2(const char *msg)
{
#ifdef ULANZI
Expand Down
Loading

0 comments on commit 341dea2

Please sign in to comment.