Skip to content

Commit

Permalink
Server dictated client refresh times
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisjtwomey committed Jul 5, 2023
1 parent 2119536 commit e1d6083
Show file tree
Hide file tree
Showing 33 changed files with 1,191 additions and 938 deletions.
20 changes: 0 additions & 20 deletions .vscode/settings.json

This file was deleted.

4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ See the [server/README.md](server/README.md) for more features.

- **Optional: 2 GB microSD card ~€5**

**Note: microSD cards are now no longer required and disabled by default. Use build flag `HAS_SDCARD` to re-enable**
**Note: microSD cards are now no longer required and disabled by default. Use build flag `USE_SDCARD` to re-enable**

Whatever is the cheapest microSD card you can find, you will not likely need more than few hundred kilobytes of storage. It will be mainly used by Inkplate to cache downloaded images from the server until it needs to refresh the next day. The config file for the code will also need to be stored here.

Expand Down Expand Up @@ -130,7 +130,7 @@ Make sure to update:

**Note: The new/current _SolderedElectronics_ version of Inkplate10 has a MOSFET to control power to the SD card during deep sleep, making this option viable for battery life. https://github.com/SolderedElectronics/Inkplate-Arduino-library/issues/209**

**Note: Use build flag `HAS_SDCARD` to enable SD card usage.**
**Note: Use build flag `USE_SDCARD` to enable SD card usage.**

Insert an SD card into your Inkplate board and place a new file `config.yaml` in the root directory:

Expand Down
33 changes: 33 additions & 0 deletions doc/config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# This is an example config.yaml to place at the root directory
# of your SD card. The values in these parameters are just examples
# so be sure to update them to suit your own setup.
#
# These parameters override what is set in config.h if SD card is enabled.
server:
# The URL on the server which the client will attempt to download the first image from.
url: http://localhost:8080/download.png
# The number of times to attempt downloading or drawing the server image.
retries: 3
wifi:
ssid: XXXX
pass: XXXX
# The number of times to attempt WiFi connection before timeout.
retries: 6
ntp:
# The time server host (keep as pool.ntp.org if in doubt).
host: pool.ntp.org
# The timezone you live in ("Olson" format).
timezone: Europe/Dublin
mqtt_logger:
# Set to true to send publish logs to an MQTT broker.
enabled: false
# The MQTT broker to publish logs to.
broker: localhost
# The port of the MQTT broker.
port: 1883
# The unique identifier for this project in your MQTT broker.
clientId: inkplate10-weather-calendar
# The name of the MQTT topic to publish to.
topic: mqtt/inkplate10-weather-calendar
# The number of times to attempt MQTT connection before timeout.
retries: 3
39 changes: 0 additions & 39 deletions include/README

This file was deleted.

16 changes: 16 additions & 0 deletions include/battery.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#ifndef __BATTERY_H__
#define __BATTERY_H__
// Define a battery capacity lookup table as an array of structs
struct BatteryCapacity {
double voltage;
int percentage;
};

/**
Look up battery capacity percentage based on voltage.
@param voltage the current voltage of the battery.
@returns the capacity remaining as a percentage integer.
*/
int getBatteryCapacity(double voltage);
#endif
43 changes: 43 additions & 0 deletions include/defaults.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#ifndef __DEFAULTS_H__
#define __DEFAULTS_H__
/**
* Manually define config params.
*
* Only use this if you are not using the SD card (Inkplate10 V1).
* Otherwise add USE_SDCARD flag to load from SD card config.yaml
*
* These parameters are overriden by the config.yaml if SD card is enabled.
*/

// The URL on the server which the client will try to download the first
// image from.
extern char serverURL[];
// The number of times to attempt downloading or drawing the server image.
extern int serverRetries;

// Wifi config.
extern char wifiSSID[];
extern char wifiPass[];
// The number of times to attempt WiFi connection before timeout.
extern int wifiRetries;

// NTP config.
// The time server (keep as pool.ntp.org if in doubt).
extern char ntpHost[];
// The timezone you live in ("Olson" format).
extern char ntpTimezone[];

// Remote logging config.
// Set to true to send publish logs to an MQTT broker.
extern bool mqttLoggerEnabled;
// The MQTT broker to publish logs to.
extern char mqttLoggerBroker[];
// The port of the MQTT broker.
extern int mqttLoggerPort;
// The unique identifier for this project in your MQTT broker.
extern char mqttLoggerClientID[];
// The name of the MQTT topic to publish to.
extern char mqttLoggerTopic[];
// The number of times to attempt MQTT connection before timeout.
extern int mqttLoggerRetries;
#endif
60 changes: 60 additions & 0 deletions include/display_utils.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
#ifndef __DISPLAY_H__
#define __DISPLAY_H__
#include "error_utils.h"

// Guestimate file size for PNG image @ 1200x825
#define DEFAULT_BUFFER_SIZE E_INK_WIDTH* E_INK_HEIGHT * 4 + 100

/**
Load an image to the display buffer.
@param filePath the path of the file on disk.
error.
@returns the esp_err_t code:
- ESP_OK if successful.
- ESP_ERR_EFILER if writing file to filePath fails.
*/
esp_err_t loadImage(const char* filePath);

/**
Load a PNG image to the display buffer from a data buffer.
@param buf the data buffer of png.
@param len the size of buffer.
@returns the esp_err_t code:
- ESP_OK if successful.
- ESP_ERR_EDL if download file fails.
- ESP_ERR_EFILEW if writing file to filePath fails.
*/
esp_err_t loadImage(uint8_t* buf, int32_t len);

/**
Load a BMP image to the display buffer.
@param buf the byte array data
@returns the esp_err_t code:
- ESP_OK if successful.
- ESP_ERR_EDL if download file fails.
- ESP_ERR_EFILEW if writing file to filePath fails.
*/
esp_err_t loadImage(uint8_t* buf, int x, int y, int w, int h);

/**
Draw the battery status to the display.
@param batteryRemainingPercent the percentage capacity remaining in the
battery. error.
@param invert flag to invert battery status due to black banner.
*/
void displayBatteryStatus(int batteryRemainingPercent, bool invert);

/**
Draw an message to the display. The error message is drawn in the top-left
corner of the display. Error message will overlay previously drawn image.
@param msg the message to display.
@param batteryRemainingPercent the percentage remaining battery capacity for
battery status display. error.
*/
void displayMessage(const char* msg, int batteryRemainingPercent);
#endif
12 changes: 12 additions & 0 deletions include/error_utils.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#ifndef __ERROR_H__
#define __ERROR_H__
#include <esp_err.h>

// Enum of errors that might be encountered.
#define ESP_ERR_ERRNO_BASE (0)
#define ESP_ERR_EDL (1 + ESP_ERR_ERRNO_BASE) // Download error
#define ESP_ERR_EDRAW (2 + ESP_ERR_ERRNO_BASE) // Draw error
#define ESP_ERR_EFILEW (3 + ESP_ERR_ERRNO_BASE) // File write error
#define ESP_ERR_EFILER (4 + ESP_ERR_ERRNO_BASE) // File read error
#define ESP_ERR_ENTP (5 + ESP_ERR_ERRNO_BASE) // NTP error
#endif
20 changes: 20 additions & 0 deletions include/file_utils.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#ifndef __FILE_H__
#define __FILE_H__
#include "error_utils.h"
// The path on SD card where calendar images are downloaded to and read from.
#define CALENDAR_RW_PATH "/calendar.png"
// The file path on SD card to load config.
#define CONFIG_FILE_PATH "/config.yaml"

/**
Write a data buffer a file at a given path. Store the file on disk at a given path.
@param buf the data buffer.
@param size the size of the file to write.
@param filePath the path of the file on disk.
@returns the esp_err_t code:
- ESP_OK if successful.
- ESP_ERR_EFILEW if number of retries is exceeded without success.
*/
esp_err_t writeFile(uint8_t* buf, size_t size, const char* filePath);
#endif
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#include <Inkplate.h>

const uint8_t Merienda_Regular12pt7bBitmaps[] PROGMEM = {
0x00, 0x31, 0x8E, 0x63, 0x19, 0xCC, 0x63, 0x18, 0xC6, 0x10, 0x00, 0xC7,
0x38, 0x46, 0xCD, 0x9E, 0x3C, 0xD9, 0x91, 0x00, 0x01, 0x83, 0x00, 0x60,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#include <Inkplate.h>

const uint8_t Merienda_Regular16pt7bBitmaps[] PROGMEM = {
0x00, 0x10, 0x38, 0x70, 0xF1, 0xC3, 0x87, 0x0E, 0x38, 0x70, 0xE1, 0xC3,
0x86, 0x0C, 0x18, 0x30, 0x30, 0x00, 0x00, 0x04, 0x1C, 0x78, 0xF0, 0x42,
Expand Down
53 changes: 3 additions & 50 deletions src/battery.h → include/icon/icons_32x32.h
Original file line number Diff line number Diff line change
@@ -1,53 +1,6 @@
#ifndef BATTERY_H
#define BATTERY_H

// Define a battery capacity lookup table as an array of structs
struct BatteryCapacity {
double voltage;
int percentage;
};

#ifdef BATT_2000MAH
// A capacity table based on a 3.7v 2000mAh LiPo discharge profile over ~50
// days.
BatteryCapacity capacityTable[] = {
{4.25, 100}, {4.22, 99}, {4.19, 98}, {4.17, 97}, {4.15, 96}, {4.14, 95},
{4.12, 94}, {4.11, 93}, {4.10, 91}, {4.09, 90}, {4.08, 89}, {4.08, 88},
{4.08, 87}, {4.08, 86}, {4.07, 85}, {4.07, 84}, {4.07, 83}, {4.07, 82},
{4.06, 81}, {4.06, 80}, {4.05, 79}, {4.04, 78}, {4.03, 77}, {4.02, 76},
{4.00, 74}, {3.99, 73}, {3.98, 72}, {3.97, 71}, {3.96, 70}, {3.96, 69},
{3.95, 68}, {3.95, 67}, {3.94, 66}, {3.94, 65}, {3.93, 64}, {3.93, 63},
{3.92, 62}, {3.91, 61}, {3.90, 60}, {3.89, 59}, {3.87, 57}, {3.86, 56},
{3.85, 55}, {3.84, 54}, {3.83, 53}, {3.82, 52}, {3.80, 51}, {3.79, 50},
{3.78, 49}, {3.77, 48}, {3.76, 47}, {3.75, 46}, {3.74, 45}, {3.73, 44},
{3.72, 43}, {3.71, 41}, {3.70, 40}, {3.70, 39}, {3.69, 38}, {3.69, 37},
{3.68, 36}, {3.68, 35}, {3.67, 34}, {3.66, 33}, {3.65, 32}, {3.65, 31},
{3.64, 30}, {3.63, 29}, {3.62, 28}, {3.62, 27}, {3.62, 26}, {3.61, 24},
{3.60, 23}, {3.59, 22}, {3.57, 21}, {3.56, 20}, {3.54, 19}, {3.53, 18},
{3.51, 17}, {3.51, 16}, {3.50, 15}, {3.49, 14}, {3.48, 13}, {3.47, 12},
{3.45, 11}, {3.40, 10}, {3.34, 9}, {3.33, 7}, {3.31, 6}, {3.29, 5},
{3.26, 4}, {3.24, 3}, {3.21, 2}, {3.16, 1}, {3.10, 0},
};
#elif
extern BatteryCapacity capacityTable[];
#endif

const int numCapacityEntries = sizeof(capacityTable) / sizeof(BatteryCapacity);

/**
Look up battery capacity percentage based on voltage.
@param voltage the current voltage of the battery.
@returns the capacity remaining as a percentage integer.
*/
int getBatteryCapacity(double voltage) {
for (int i = 0; i < numCapacityEntries; i++) {
if (voltage >= capacityTable[i].voltage) {
return capacityTable[i].percentage;
}
}
return 0;
}
#ifndef ICONS_32X32_H
#define ICONS_32X32_H
#include <Arduino.h>

// 'battery-empty', 32x32px
uint8_t epdBitmapBatteryEmpty[] PROGMEM = {
Expand Down
Loading

0 comments on commit e1d6083

Please sign in to comment.