Skip to content

Commit

Permalink
Add USB detection
Browse files Browse the repository at this point in the history
  • Loading branch information
sqfmi committed Jul 6, 2024
1 parent 9c0b7e6 commit 9e6325e
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 16 deletions.
25 changes: 15 additions & 10 deletions examples/WatchFaces/7_SEG/Watchy_7_SEG.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,15 @@ void Watchy7SEG::drawWatchFace(){
drawSteps();
drawWeather();
drawBattery();
display.drawBitmap(120, 77, WIFI_CONFIGURED ? wifi : wifioff, 26, 18, DARKMODE ? GxEPD_WHITE : GxEPD_BLACK);
display.drawBitmap(116, 75, WIFI_CONFIGURED ? wifi : wifioff, 26, 18, DARKMODE ? GxEPD_WHITE : GxEPD_BLACK);
if(BLE_CONFIGURED){
display.drawBitmap(100, 75, bluetooth, 13, 21, DARKMODE ? GxEPD_WHITE : GxEPD_BLACK);
display.drawBitmap(100, 73, bluetooth, 13, 21, DARKMODE ? GxEPD_WHITE : GxEPD_BLACK);
}
#ifdef ARDUINO_ESP32S3_DEV
if(USB_PLUGGED_IN){
display.drawBitmap(140, 75, charge, 16, 18, DARKMODE ? GxEPD_WHITE : GxEPD_BLACK);
}
#endif
}

void Watchy7SEG::drawTime(){
Expand Down Expand Up @@ -81,25 +86,25 @@ void Watchy7SEG::drawSteps(){
display.println(stepCount);
}
void Watchy7SEG::drawBattery(){
display.drawBitmap(154, 73, battery, 37, 21, DARKMODE ? GxEPD_WHITE : GxEPD_BLACK);
display.fillRect(159, 78, 27, BATTERY_SEGMENT_HEIGHT, DARKMODE ? GxEPD_BLACK : GxEPD_WHITE);//clear battery segments
display.drawBitmap(158, 73, battery, 37, 21, DARKMODE ? GxEPD_WHITE : GxEPD_BLACK);
display.fillRect(163, 78, 27, BATTERY_SEGMENT_HEIGHT, DARKMODE ? GxEPD_BLACK : GxEPD_WHITE);//clear battery segments
int8_t batteryLevel = 0;
float VBAT = getBatteryVoltage();
if(VBAT > 4.1){
if(VBAT > 4.0){
batteryLevel = 3;
}
else if(VBAT > 3.95 && VBAT <= 4.1){
else if(VBAT > 3.6 && VBAT <= 4.0){
batteryLevel = 2;
}
else if(VBAT > 3.80 && VBAT <= 3.95){
else if(VBAT > 3.20 && VBAT <= 3.6){
batteryLevel = 1;
}
else if(VBAT <= 3.80){
else if(VBAT <= 3.20){
batteryLevel = 0;
}

for(int8_t batterySegments = 0; batterySegments < batteryLevel; batterySegments++){
display.fillRect(159 + (batterySegments * BATTERY_SEGMENT_SPACING), 78, BATTERY_SEGMENT_WIDTH, BATTERY_SEGMENT_HEIGHT, DARKMODE ? GxEPD_WHITE : GxEPD_BLACK);
display.fillRect(163 + (batterySegments * BATTERY_SEGMENT_SPACING), 78, BATTERY_SEGMENT_WIDTH, BATTERY_SEGMENT_HEIGHT, DARKMODE ? GxEPD_WHITE : GxEPD_BLACK);
}
}

Expand Down Expand Up @@ -150,4 +155,4 @@ void Watchy7SEG::drawWeather(){
}

display.drawBitmap(145, 158, weatherIcon, WEATHER_ICON_WIDTH, WEATHER_ICON_HEIGHT, DARKMODE ? GxEPD_WHITE : GxEPD_BLACK);
}
}
8 changes: 8 additions & 0 deletions examples/WatchFaces/7_SEG/icons.h
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,14 @@ const unsigned char wifioff [] PROGMEM = {
0x01, 0xff, 0xc0, 0x00, 0x07, 0xe1, 0xc0, 0x00, 0x0f, 0xc0, 0x80, 0x00, 0x1f, 0x0c, 0x00, 0x00,
0x3c, 0x1e, 0x00, 0x00, 0xf8, 0x0c, 0x00, 0x00
};

// 'charge', 16x18px
const unsigned char charge [] PROGMEM = {
0x00, 0x10, 0x00, 0x70, 0x00, 0xe0, 0x01, 0xe0, 0x03, 0xe0, 0x07, 0xc0, 0x0f, 0xc0, 0x1f, 0xff,
0x3f, 0xfe, 0x7f, 0xfc, 0x7f, 0xf8, 0x03, 0xf0, 0x03, 0xe0, 0x07, 0xc0, 0x07, 0x80, 0x07, 0x00,
0x0e, 0x00, 0x0c, 0x00
};

// 'chip', 48x32px
const unsigned char chip [] PROGMEM = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
Expand Down
2 changes: 1 addition & 1 deletion library.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "Watchy",
"version": "1.4.13",
"version": "1.4.14",
"description": "Watchy - An Open Source E-Paper Watch by SQFMI",
"authors": [
{
Expand Down
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name=Watchy
version=1.4.13
version=1.4.14
author=SQFMI
maintainer=SQFMI
sentence=Watchy - An Open Source E-Paper Watch by SQFMI
Expand Down
2 changes: 0 additions & 2 deletions src/Display.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,9 @@
RTC_DATA_ATTR bool displayFullInit = true;

void WatchyDisplay::busyCallback(const void *) {
#ifndef ARDUINO_ESP32S3_DEV
gpio_wakeup_enable((gpio_num_t)DISPLAY_BUSY, GPIO_INTR_LOW_LEVEL);
esp_sleep_enable_gpio_wakeup();
esp_light_sleep_start();
#endif
}

WatchyDisplay::WatchyDisplay() :
Expand Down
24 changes: 22 additions & 2 deletions src/Watchy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ RTC_DATA_ATTR weatherData currentWeather;
RTC_DATA_ATTR int weatherIntervalCounter = -1;
RTC_DATA_ATTR long gmtOffset = 0;
RTC_DATA_ATTR bool alreadyInMenu = true;
RTC_DATA_ATTR bool USB_PLUGGED_IN = false;
RTC_DATA_ATTR tmElements_t bootTime;
RTC_DATA_ATTR uint32_t lastIPAddress;
RTC_DATA_ATTR char lastSSID[30];
Expand All @@ -32,7 +33,6 @@ void Watchy::init(String datetime) {
Wire.begin(SDA, SCL); // init i2c
#endif
RTC.init();

// Init the display since is almost sure we will use it
display.epd2.initWatchy();

Expand Down Expand Up @@ -67,9 +67,23 @@ void Watchy::init(String datetime) {
case ESP_SLEEP_WAKEUP_EXT1: // button Press
handleButtonPress();
break;
#ifdef ARDUINO_ESP32S3_DEV
case ESP_SLEEP_WAKEUP_EXT0: // USB plug in
pinMode(USB_DET_PIN, INPUT);
USB_PLUGGED_IN = (digitalRead(USB_DET_PIN) == 1);
if(guiState == WATCHFACE_STATE){
RTC.read(currentTime);
showWatchFace(true);
}
break;
#endif
default: // reset
RTC.config(datetime);
_bmaConfig();
#ifdef ARDUINO_ESP32S3_DEV
pinMode(USB_DET_PIN, INPUT);
USB_PLUGGED_IN = (digitalRead(USB_DET_PIN) == 1);
#endif
gmtOffset = settings.gmtOffset;
RTC.read(currentTime);
RTC.read(bootTime);
Expand All @@ -85,9 +99,16 @@ void Watchy::deepSleep() {
display.hibernate();
RTC.clearAlarm(); // resets the alarm flag in the RTC
#ifdef ARDUINO_ESP32S3_DEV
esp_sleep_enable_ext0_wakeup((gpio_num_t)USB_DET_PIN, USB_PLUGGED_IN ? LOW : HIGH); //// enable deep sleep wake on USB plug in/out
rtc_gpio_set_direction((gpio_num_t)USB_DET_PIN, RTC_GPIO_MODE_INPUT_ONLY);
rtc_gpio_pullup_en((gpio_num_t)USB_DET_PIN);

esp_sleep_enable_ext1_wakeup(
BTN_PIN_MASK,
ESP_EXT1_WAKEUP_ANY_LOW); // enable deep sleep wake on button press
rtc_gpio_set_direction((gpio_num_t)UP_BTN_PIN, RTC_GPIO_MODE_INPUT_ONLY);
rtc_gpio_pullup_en((gpio_num_t)UP_BTN_PIN);

rtc_clk_32k_enable(true);
//rtc_clk_slow_freq_set(RTC_SLOW_FREQ_32K_XTAL);
struct tm timeinfo;
Expand All @@ -108,7 +129,6 @@ void Watchy::deepSleep() {
BTN_PIN_MASK,
ESP_EXT1_WAKEUP_ANY_HIGH); // enable deep sleep wake on button press
#endif
gpio_deep_sleep_hold_dis();
esp_deep_sleep_start();
}

Expand Down
3 changes: 3 additions & 0 deletions src/Watchy.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
#include "soc/rtc_cntl_reg.h"
#include "time.h"
#include "esp_sntp.h"
#include "hal/rtc_io_types.h"
#include "driver/rtc_io.h"
#define uS_TO_S_FACTOR 1000000ULL //Conversion factor for micro seconds to seconds
#define ADC_VOLTAGE_DIVIDER ((360.0f+100.0f)/360.0f) //Voltage divider at battery ADC
#else
Expand Down Expand Up @@ -116,5 +118,6 @@ extern RTC_DATA_ATTR int menuIndex;
extern RTC_DATA_ATTR BMA423 sensor;
extern RTC_DATA_ATTR bool WIFI_CONFIGURED;
extern RTC_DATA_ATTR bool BLE_CONFIGURED;
extern RTC_DATA_ATTR bool USB_PLUGGED_IN;

#endif

0 comments on commit 9e6325e

Please sign in to comment.