Skip to content

Commit

Permalink
First commit
Browse files Browse the repository at this point in the history
  • Loading branch information
timendum committed Feb 10, 2023
0 parents commit d700432
Show file tree
Hide file tree
Showing 50 changed files with 4,330 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.pio
include/config.h
.vscode
32 changes: 32 additions & 0 deletions include/config.template.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#ifndef CONFIG_H
#define CONFIG_H

/* CONFIGURATION
* Uncomment only one of the below #define statements
* based on the paperd.ink device you have
*/
#define PAPERDINK_DEVICE Paperdink_Classic
//#define PAPERDINK_DEVICE Paperdink_Merlot

#define DEBUG Serial

#define SSID "xxxxxx" // Wifi Network SSID (name of wifi network)
#define PASSWORD "xxxxxx" // Wifi Network password

/* Time zone from list https://github.com/nayarsystems/posix_tz_db/blob/master/zones.csv */
#define TIME_ZONE "CET-1CEST,M3.5.0,M10.5.0/3"

/* Number of times to update starting 12am
* 1 = Updates every 24 hours
* 2 = Updates every 12 hours
* 3 = Updates every 8 hours. Not a good idea since it won't align with day changes.
* 4 = Updates every 6 hours
* ... and so on
* Higher number means lower battery life
*/
#define UPDATES_PER_DAY 4

/* My information */
#define MY_JSON_URL "https://xxxxx/paperd.json" // City for weather

#endif /* CONFIG_H */
17 changes: 17 additions & 0 deletions lib/Paperdink/src/Paperdink.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#ifndef _PAPERDINK_H_
#define _PAPERDINK_H_

#include <Arduino.h>
#include "pin_assignment.h"

// Paperdink Devices
#include "devices/classic.h"

// Conversion factor for seconds to microseconds
#define S_TO_uS_FACTOR (1000000)
#define M_TO_uS_FACTOR (6e7)
#define H_TO_uS_FACTOR (3.6e9)

extern PAPERDINK_DEVICE Paperdink;

#endif /* _PAPERDINK_H_ */
108 changes: 108 additions & 0 deletions lib/Paperdink/src/devices/base.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@

#include <WiFiClientSecure.h>
#include "base.h"

int8_t PaperdinkDeviceBaseClass::begin()
{
pinMode(EPD_EN, OUTPUT);
pinMode(EPD_RST, OUTPUT);
pinMode(SD_EN, OUTPUT);
pinMode(BATT_EN, OUTPUT);
pinMode(PCF_INT, INPUT); // Required to lower power consumption

return 0;
}

int8_t PaperdinkDeviceBaseClass::enable_display()
{
// Power up EPD
digitalWrite(EPD_EN, LOW);
digitalWrite(EPD_RST, LOW);
delay(50);
digitalWrite(EPD_RST, HIGH);
delay(50);

return 0;
}

int8_t PaperdinkDeviceBaseClass::disable_display()
{
digitalWrite(EPD_EN, HIGH);
digitalWrite(EPD_RST, LOW);
delay(50);
digitalWrite(EPD_RST, HIGH);

return 0;
}

int8_t PaperdinkDeviceBaseClass::disable_everything()
{
disable_display();
// TODO: Add disable functions for SD and Batt
digitalWrite(SD_EN, HIGH);
digitalWrite(BATT_EN, HIGH);

return 0;
}

int8_t PaperdinkDeviceBaseClass::deep_sleep_timer_wakeup(uint64_t sleep_time_us)
{
// Turn off everything
disable_everything();

esp_sleep_enable_timer_wakeup(sleep_time_us);
Serial.printf("Timer wakeup after %lld microseconds...", sleep_time_us);
// Go to sleep
esp_deep_sleep_start();

return 0;
}

int8_t PaperdinkDeviceBaseClass::deep_sleep_button_wakeup(uint8_t gpio_num)
{
// Turn off everything
disable_everything();

esp_sleep_enable_ext0_wakeup((gpio_num_t)gpio_num, 0); //1 = High, 0 = Low
Serial.printf("Button wakeup on pin %d", gpio_num);
// Go to sleep
esp_deep_sleep_start();

return 0;
}

int8_t PaperdinkDeviceBaseClass::deep_sleep_timer_button_wakeup(uint64_t sleep_time_us, uint8_t gpio_num)
{
// Turn off everything
disable_everything();

esp_sleep_enable_timer_wakeup(sleep_time_us);
esp_sleep_enable_ext0_wakeup((gpio_num_t)gpio_num, 0); //1 = High, 0 = Low
Serial.printf("Timer wakeup after %lld us or button on pin %d", sleep_time_us, gpio_num);
// Go to sleep
esp_deep_sleep_start();

return 0;
}

int8_t PaperdinkDeviceBaseClass::connect_wifi(const char *ssid, const char *password, uint8_t attempts)
{

WiFi.begin(ssid, password);

while(WiFi.status() != WL_CONNECTED ){
delay(500);
Serial.print(".");
if(!attempts--){
return -1;
}
}
Serial.println("Connected");

return 0;
}

int8_t PaperdinkDeviceBaseClass::connect_wifi(const char *ssid, const char *password)
{
return connect_wifi(ssid, password, 40);
}
29 changes: 29 additions & 0 deletions lib/Paperdink/src/devices/base.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@

#ifndef _PDINK_BASE_H_
#define _PDINK_BASE_H_

#define ENABLE_GxEPD2_GFX 1
#include <GxEPD2_BW.h>

#include "pin_assignment.h"

class PaperdinkDeviceBaseClass
{
public:
uint8_t has_color = false;
int color = GxEPD_BLACK;

int8_t begin();
virtual int8_t enable_display();
virtual int8_t disable_display();
int8_t disable_everything();

int8_t deep_sleep_timer_wakeup(uint64_t sleep_time_us);
int8_t deep_sleep_button_wakeup(uint8_t gpio_num);
int8_t deep_sleep_timer_button_wakeup(uint64_t sleep_time_us, uint8_t gpio_num);

int8_t connect_wifi(const char *ssid, const char *password, uint8_t attempts);
int8_t connect_wifi(const char *ssid, const char *password);
};

#endif /* _PDINK_BASE_H_ */
17 changes: 17 additions & 0 deletions lib/Paperdink/src/devices/classic.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#include "classic.h"

int8_t Paperdink_Classic::enable_display()
{
PaperdinkDeviceBaseClass::enable_display();
epd.init();

return 0;
}

int8_t Paperdink_Classic::disable_display()
{
digitalWrite(EPD_EN, HIGH);

return 0;
}

18 changes: 18 additions & 0 deletions lib/Paperdink/src/devices/classic.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@

#ifndef _PDINK_CLASSIC_H_
#define _PDINK_CLASSIC_H_

#include "base.h"

class Paperdink_Classic : public PaperdinkDeviceBaseClass
{
public:
uint8_t has_color = false;
int color = GxEPD_BLACK;

GxEPD2_BW<GxEPD2_420, GxEPD2_420::HEIGHT> epd = GxEPD2_420(EPD_CS, EPD_DC, EPD_RST, EPD_BUSY);
int8_t enable_display() override;
int8_t disable_display() override;
};

#endif /* _PDINK_CLASSIC_H_ */
21 changes: 21 additions & 0 deletions lib/Paperdink/src/fonts.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@

#ifndef _PAPERDINK_FONTS_H_
#define _PAPERDINK_FONTS_H_

//#include "fonts/Roboto_Regular_12pt7b.h"
#include "fonts/Code_New_Roman9pt7b.h"
#include "fonts/Code_New_Roman15pt7b.h"
//#include "fonts/Code_New_Roman_Bold15pt7b.h"
//#include "fonts/Code_New_Roman_Bold10pt7b.h"
#include "fonts/Mont_Heavy25pt7b.h"
//#include "fonts/Mont_ExtraLight8pt7b.h"
#include "fonts/Gobold_Thin9pt7b.h"

#define PAPERDINK_FONT_LRG Mont_Heavy25pt7b
//#define PAPERDINK_FONT_LRG_BOLD Mont_Heavy25pt7b
#define PAPERDINK_FONT_MED Code_New_Roman15pt7b
//#define PAPERDINK_FONT_MED_BOLD Code_New_Roman_Bold15pt7b
#define PAPERDINK_FONT_SML Code_New_Roman9pt7b
//#define PAPERDINK_FONT_SML_BOLD Code_New_Roman_Bold10pt7b

#endif /* _PAPERDINK_FONTS_H_ */
Loading

0 comments on commit d700432

Please sign in to comment.