Skip to content

Commit

Permalink
V0.55
Browse files Browse the repository at this point in the history
- fix color correction and temperature in settings API
- deactivates auto update search and following crashes (can be activated in dev.json) closes #59
- fixes colored fragments in customapps
- adds Linechart to notify and customapps
- adds option to disable autoscaling for barchart and linechart. closes #64
  • Loading branch information
Blueforcer committed Apr 16, 2023
1 parent 7bb3741 commit 0563ea8
Show file tree
Hide file tree
Showing 16 changed files with 343 additions and 228 deletions.
17 changes: 11 additions & 6 deletions docs/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,7 @@ With HTTP, make GET request to `http://[IP]/api/stats`

| Topic | URL | Payload/Body | HTTP method |
| --- | --- | --- | --- |
| `[PREFIX]/power` | `http://[IP]/api/power` | `{"state":value}` | POST |


Valid values are:
- `0` => off
- `1` => on
| `[PREFIX]/power` | `http://[IP]/api/power` | true/false or 1/0 | POST |


## Colored indicators
Expand Down Expand Up @@ -43,6 +38,7 @@ You can also send a one-time notification with the same JSON format. Simply send
| Topic | URL | Payload/Body | Query parameters | HTTP method |
| --- | --- | --- | --- | --- |
| `[PREFIX]/custom/[appname]` |`http://[IP]/api/custom` | JSON | name = [appname] | POST |
| `[PREFIX]/notify` |`http://[IP]/notify` | JSON | - | POST |


### JSON Properties
Expand All @@ -63,6 +59,8 @@ All keys are optional, so you can send just the properties you want to use.
| `sound` | string | The filename of your RTTTL ringtone file (without extension). | |
| `pushIcon` | number | 0 = Icon doesn't move. 1 = Icon moves with text and will not appear again. 2 = Icon moves with text but appears again when the text starts to scroll again. | 0 |
| `bar` | array of integers | draws a bargraph. Without icon maximum 16 values, with icon 11 values | |
| `line` | array of integers | draws a linechart. Without icon maximum 16 values, with icon 11 values | |
| `autoscale` | boolean | enables or disables autoscaling for bar and linechart | true |
| `lifetime` | integer | Removes the custom app when there is no update after the given time in seconds | 0 |
| `textCase` | integer | Changes the Uppercase setting. 0=global setting, 1=forces uppercase; 2=shows as it sent. | 0 |
| `textOffset` | integer | Sets an offset for the x position of a starting text. | 0 |
Expand Down Expand Up @@ -307,3 +305,10 @@ You can start the update with update button in HA or:
| Topic | URL | Payload/Body | HTTP Header | HTTP method |
| --- | --- | --- | --- | --- |
| `[PREFIX]/doupdate` |`http://[IP]/api/doupdate` | JSON | empty payload/body | POST |


## Reboot Awtrix

| Topic | URL | Payload/Body | HTTP method |
| --- | --- | --- | --- |
| `[PREFIX]/reboot` | `http://[IP]/api/reboot` | - | POST |
1 change: 1 addition & 0 deletions docs/dev.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,4 @@ The JSON object has the following properties:
| `color_correction` | array of int | Sets the colorcorrection of the matrix | `[255,255,255]` |
| `color_temperature` | array of int | Sets the colortemperature of the matrix | `[255,255,255]` |
| `gamma` |float | Sets the gamma of the matrix | `2.5` |
| `update_check` | boolean | Enables searchf or new version every 1 hour. This could cause in loop stack overflow! | `false` |
7 changes: 3 additions & 4 deletions lib/webserver/src/esp-fs-webserver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ void FSWebServer::addHandler(const Uri &uri, HTTPMethod method, WebServerClass::
webserver->on(uri, method, fn);
}


void FSWebServer::onNotFound(WebServerClass::THandlerFunction fn)
{
webserver->onNotFound(fn);
Expand Down Expand Up @@ -115,10 +114,10 @@ bool FSWebServer::begin(const char *path)
// OTA update via webbrowser
m_httpUpdater.setup(webserver);

#ifdef ESP32
webserver->enableCrossOrigin(true);
#endif
webserver->setContentLength(50);
webserver->enableCORS(true);

webserver->setContentLength(1024);
webserver->begin();

return true;
Expand Down
3 changes: 2 additions & 1 deletion platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ upload_speed = 921600
framework = arduino
monitor_speed = 115200
board_build.f_cpu = 240000000L
build_flags = -DULANZI -D MQTT_MAX_PACKET_SIZE=1024
build_flags = -DULANZI -D MQTT_MAX_PACKET_SIZE=1024 -DARDUINO_LOOP_STACK_SIZE=32768

lib_deps =
adafruit/Adafruit SHT31 Library@^2.2.0
bblanchon/ArduinoJson@^6.20.0
Expand Down
90 changes: 17 additions & 73 deletions src/Apps.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@ struct CustomApp
int16_t iconPosition = 0;
bool iconWasPushed = false;
int barData[16] = {0};
int lineData[16] = {0};
int barSize;
int lineSize;
long lastUpdate;
int16_t lifetime;
std::vector<uint16_t> colors;
Expand Down Expand Up @@ -76,7 +78,9 @@ struct Notification
int16_t iconPosition = 0;
bool iconWasPushed = false;
int barData[16] = {0};
int lineData[16] = {0};
int barSize;
int lineSize;
std::vector<uint16_t> colors;
std::vector<String> fragments;
uint8_t textOffset;
Expand Down Expand Up @@ -364,6 +368,10 @@ void ShowCustomApp(String name, FastLED_NeoMatrix *matrix, MatrixDisplayUiState
{
DisplayManager.drawBarChart(x, y, ca->barData, ca->barSize, hasIcon, ca->color);
}
else if (ca->lineSize > 0)
{
DisplayManager.drawLineChart(x, y, ca->lineData, ca->lineSize, hasIcon, ca->color);
}
else
{
if ((ca->repeat > 0) && (getTextWidth(ca->text.c_str(), ca->textCase) > availableWidth) && (state->appState == FIXED))
Expand Down Expand Up @@ -425,12 +433,11 @@ void ShowCustomApp(String name, FastLED_NeoMatrix *matrix, MatrixDisplayUiState
}
}
}
int16_t textX = (hasIcon) ? ((24 - getTextWidth(ca->text.c_str(), ca->textCase)) / 2) + 9 + ca->textOffset : ((32 - getTextWidth(ca->text.c_str(), ca->textCase)) / 2);
matrix->setTextColor(ca->color);

int16_t textX = hasIcon ? ((24 - textWidth) / 2) + 9 : ((32 - textWidth) / 2);
if (noScrolling)
{
ca->repeat = -1; // Disable repeat if text is too short for scrolling
// Display text with rainbow effect if enabled

if (!ca->fragments.empty())
{
Expand All @@ -444,13 +451,15 @@ void ShowCustomApp(String name, FastLED_NeoMatrix *matrix, MatrixDisplayUiState
}
else
{

if (ca->rainbow)
{
DisplayManager.HSVtext(x + textX, 6 + y, ca->text.c_str(), false, ca->textCase);
}
else
{
// Display text
matrix->setTextColor(ca->color);
DisplayManager.printText(x + textX, y + 6, ca->text.c_str(), false, ca->textCase);
}
}
Expand All @@ -475,6 +484,7 @@ void ShowCustomApp(String name, FastLED_NeoMatrix *matrix, MatrixDisplayUiState
}
else
{
matrix->setTextColor(ca->color);
DisplayManager.printText(x + ca->scrollposition, 6 + y, ca->text.c_str(), false, ca->textCase);
}
}
Expand Down Expand Up @@ -580,6 +590,10 @@ void NotifyApp(FastLED_NeoMatrix *matrix, MatrixDisplayUiState *state, GifPlayer
{
DisplayManager.drawBarChart(0, 0, notify.barData, notify.barSize, hasIcon, notify.color);
}
else if (notify.lineSize > 0)
{
DisplayManager.drawLineChart(0, 0, notify.lineData, notify.lineSize, hasIcon, notify.color);
}
else
{
// Check if text needs to be scrolled
Expand Down Expand Up @@ -858,75 +872,5 @@ void CApp20(FastLED_NeoMatrix *matrix, MatrixDisplayUiState *state, int16_t x, i
ShowCustomApp(name, matrix, state, x, y, firstFrame, lastFrame, gifPlayer);
}

const uint16_t *getWeatherIcon(int code)
{
switch (code)
{
case 1:
return icon_475;
break;

default:
return icon_475;
break;
}
}

void WeatherApp(FastLED_NeoMatrix *matrix, MatrixDisplayUiState *state, int16_t x, int16_t y, bool firstFrame, bool lastFrame)
{
if (notify.flag)
return;
CURRENT_APP = "Weather";
DisplayManager.getInstance().resetTextColor();
matrix->drawRGBBitmap(x, y, getWeatherIcon(WEATHER_CODE), 8, 8);
String text = WEATHER_TEMP + "°" + WEATHER_HUM + "%";
uint16_t textWidth = getTextWidth(text.c_str(), 0);
int16_t textX = ((23 - textWidth) / 2);
matrix->setCursor(textX + 11, 6 + y);
matrix->print(utf8ascii(text));
}

void getWeatherData()
{
Serial.println("UPDATE");
String weatherUrl = "https://wttr.in/" + CITY + "?format=p1";
if ((WiFi.status() == WL_CONNECTED))
{
HTTPClient http;
http.begin(weatherUrl);
http.setTimeout(5000);
int httpCode = http.GET();

if (httpCode > 0)
{
String payload = http.getString();
int temperatureIndex = payload.indexOf("temperature_celsius{forecast=\"current\"}");
int humIndex = payload.indexOf("humidity_percentage{forecast=\"current\"}");
int weatherCodeIndex = payload.indexOf("weather_code{forecast=\"current\"}");

if (temperatureIndex >= 0 && weatherCodeIndex >= 0)
{
int tempEndIndex = payload.indexOf('\n', temperatureIndex);
int codeEndIndex = payload.indexOf('\n', weatherCodeIndex);
int humEndIndex = payload.indexOf('\n', humIndex);
String temperatureValue = payload.substring(temperatureIndex + 40, tempEndIndex);
String humValue = payload.substring(humIndex + 40, humEndIndex);
String weatherCodeValue = payload.substring(weatherCodeIndex + 33, codeEndIndex);

WEATHER_TEMP = temperatureValue;
WEATHER_HUM = humValue;
WEATHER_CODE = weatherCodeValue.toInt();
}
}
http.end();
}
}

void StartAppUpdater()
{
// downloader.attach(60,getWeatherData);
// getWeatherData();
}

OverlayCallback overlays[] = {MenuApp, NotifyApp, AlarmApp, TimerApp};
#endif
3 changes: 3 additions & 0 deletions src/Dictionary.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,3 +125,6 @@ const char HumKey[] PROGMEM = {"hum"};
const char UpTimeKey[] PROGMEM = {"uptime"};
const char SignalStrengthKey[] PROGMEM = {"wifi_signal"};
const char UpdateKey[] PROGMEM = {"up_available"};
const char MessagesKey[] PROGMEM = {"messages"};
const char VersionKey[] PROGMEM = {"version"};
const char RamKey[] PROGMEM = {"ram"};
3 changes: 3 additions & 0 deletions src/Dictionary.h
Original file line number Diff line number Diff line change
Expand Up @@ -127,4 +127,7 @@ extern const char HumKey[];
extern const char UpTimeKey[];
extern const char SignalStrengthKey[];
extern const char UpdateKey[];
extern const char MessagesKey[];
extern const char VersionKey[];
extern const char RamKey[];
#endif
Loading

0 comments on commit 0563ea8

Please sign in to comment.