Skip to content

Commit

Permalink
Add in UTC Offsets and DST Region Menus
Browse files Browse the repository at this point in the history
Expand EEPROM type behaviour

Modifcations to NTP code
  • Loading branch information
johnheenan committed May 12, 2020
1 parent 119ddb8 commit e3e29f6
Show file tree
Hide file tree
Showing 27 changed files with 724 additions and 348 deletions.
90 changes: 90 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,93 @@
# Modifications in this branch by John Heenan

### Uploading Firmware File

If you have got a working version of TioRuben's code on your T-Wristband then you can OTA the firmware file for this source code, firmware.bin from the release section of this github repo, tagged as v0.1-alpha.

It can be OTA uploaded to the T-Wristband with:

```
espota.py --auth=wristbandpass --progress -i <ip address> -f firmware.bin
```
For example if the screen shows IP address 192.168.1.177 then
```
espota.py --auth=wristbandpass --progress -i 192.168.1.177 -f firmware.bin
```

### Screen changes

Screen | Skipping in mod | Long Press Original | Long Press Modifed
---------------|-----------------|------------------|--------------------
Orange Local Time | No | Update Time with NTP | Update Time with NTP
Green UTC Time | No | Update Time with NTP | Set DST Region or UTC Offset
Battery Level|No|None|Toggle IMU on or off for power saving|
Orange Compass Degrees|Yes in mod if IMU off|Calibrate Compass|Calibrate Compass
Red Temperature|Yes in mod if IMU off|None| None
OTA (upgrade firmware)|No|Update firmware|Update firmware
Deep Sleep | Yes in mod if plugged in | Wake up| Wake up

In the original there are two types of key presses

Brief press changes screen and a key press of one second chooses an action

So IMU can be toggled on or off by holding down the the button on the battery screen

## Key Press Behaviour Changes For UTC and DST Menus

The behaviour of key presses change changes in the UTC action to change DST region or UTC offset

1. A key press advances either the DST Regions or the UTC Offset screen.
2. A key press of one second choose an option and backs out
3. No key press for five seconds backs out and chooses nothing

### UTC Offset Menu

There are 49 choices: 48 for each half hour increment in day and a choice to move to DST Regions menu instead. If you choose DST regions then go back in view.

### UTC Region Menu

The sample firmware had four choices and one other to move to UTC Offset menu

If you choose UTC Offset then go back to view.

The four choices are
* Europe, Central
* China
* Brisbane
* Sydney

A region does not have to be a DST region to put an entry in (such as China and Brisbane)

You can code up to 100 in the timezones.cpp file. Each entry only requires one line.

## NVS (as EEPROM) Settings preserved

If the settings structure has the same size as before then settings are preserved across firmware updates, unless the EEPROM_VER value in platformio.ini is changed

## Additional Documentation and TODOs

There are strings in the code that partially serve as documentation. Just search or grep through code for "doco" and "todo jh", such as:

* grep -r doco *
* grep -r "todo jh" *


## Miscellaneous Notes

platformio.ini documents various build time choices.

The WiFi Manager screen that appears if a WiFi connection fails shows name of AP to connect to (T-Wristband) and when connected what IP to use in a web browser. The screen now times out after two minutes

Internally, since the NTP library code tries many times to get an answer, the code only makes one attempt to get time the time through the library. If there is a failure, just try again later.

The NTP library code was modified minimally.

A firmware ID screen such as "200512,jh,branch,tr" appears in the IMU on/off screen. 200512 means 12 May 2020. "jh,branch,tr" means branch of John Heenan from TioRuben.

There are strings in the code that partially serve as documentation. Just grep through code

# From the version cloned from:

# WIP: TTGO T-Wristband Example

First steps with TTGO T-Wristband. [Product page](https://es.aliexpress.com/item/4000527495064.html).
Expand Down
2 changes: 2 additions & 0 deletions include/battery.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
void setupADC();
void setupBattery();
float getVoltage();
float getVoltageVBUS();
uint8_t calcPercentage(float volts);
void updateBatteryChargeStatus();
bool isCharging();
bool isPluggedIn();
29 changes: 21 additions & 8 deletions include/clock.hpp
Original file line number Diff line number Diff line change
@@ -1,21 +1,34 @@
// Additions by John Heenan 2020
// Additions by John Heenan 2020 are as is and with no warranty.

#pragma once

#include <Arduino.h>
#include <Wire.h>
#include <pcf8563.h>
#include <NTP.h> // for enums
#include <NTP.h>
#include "hal.hpp"
#include "translations.hpp"

extern time_t utcDST;
#include "eeprom.hpp" // for settings_t
#include <WiFiUdp.h>

void initClock();
void rtcSleep();
RTC_Date getClockTime();
RTC_Date getUTCTime();
RTC_Date getUTCTime(time_t *utc=nullptr);
void setTime(RTC_Date datetime);
bool isUsingDST();
bool isDST(time_t utcNow);
void
setNtpUtcDst(time_t utcNow);
bool isNothernHemispere();
void beginDST(int year);

void initNTP();
RTC_Date syncTime();

class NTP2
{ // Any class named NTP2 has been declared a friend of the NTP class to get access to private declarations of NTP.
public: // this minimises changes to the NTP class and also avoids unnecessary duplication here from the NTP class
NTP2(NTP &ntp) : ntp(ntp) {}
NTP &ntp;
bool isDST(time_t utc);
bool isDSTSouth();
void setUtcDst(time_t utcNow);
};
29 changes: 10 additions & 19 deletions include/eeprom.hpp
Original file line number Diff line number Diff line change
@@ -1,38 +1,29 @@
// Edits and additions by John Heenan
// Edits and additions by John Heenan are as is and with no warranty
#pragma once
#include <Arduino.h>
#include <Preferences.h> // now recommended to use NVS with Preferences library rather than EEPROM library
#include <NTP.h> // for enums
#include "timezones.hpp"

#define MAGBIAS_FLOATS_MAX 3
void storeMagBiasEEPROM(float *magbias);
void getMagBiasEEPROM(float *magbias);

// Following added by John Heenan, 2020

#define SETTINGS_STRLEN_MAX 10
// Additions by John Heenan, 2020 are as is ans with no warranty

typedef struct
{
int eeprom_ver;
float magbias[3];
bool imu_skip;
bool dst_none;

bool tz_uses_dst;
int tz_offset;
week_t tz_week;
dow_t tz_wday;
char tz_dst_name[SETTINGS_STRLEN_MAX + 1];
month_t tz_dst_month;
int8_t tz_dst_hour;
int tz_dst_offset;
char tz_std_name[SETTINGS_STRLEN_MAX + 1];
month_t tz_std_month;
int8_t tz_std_hour;
int tz_std_offset;
bool imu_skip; // if true them IMU is set to deep sleep and not to cause esp32 to wake up
bool tz_uses_dst; // if user last choose a dst name then this is true, if user last choose a UTC offset then this is false
int tz_offset; // only used when tz_uses_dst is false, however it is remembered
char dst_region[DST_REGION_STRLEN_MAX + 1]; //only used when tz_uses_dst is true, however it is remembered

} settings_t;

extern settings_t settings;
size_t storeSettings();
size_t loadSettings();
char *strcpy_settings(char *to, const char *from, size_t strlen_max);

26 changes: 17 additions & 9 deletions include/hal.hpp
Original file line number Diff line number Diff line change
@@ -1,13 +1,21 @@
#define TP_PIN_PIN 33
#define I2C_SDA_PIN 21
#define I2C_SCL_PIN 22
#define IMU_INT_PIN GPIO_NUM_38
#define RTC_INT_PIN 34
#define BATT_ADC_PIN 35
#define VBUS_PIN 36
#define TP_PWR_PIN 25
#define LED_PIN 4
#define BATT_ADC_PIN GPIO_NUM_35
#define VBUS_ADC_PIN GPIO_NUM_36
#define I2C_SDA_PIN GPIO_NUM_21
#define I2C_SCL_PIN GPIO_NUM_22
#define RTC_INT_PIN GPIO_NUM_34
#define CHARGE_PIN GPIO_NUM_32
#define TP_PIN_PIN GPIO_NUM_33
#define IMU_INT_PIN GPIO_NUM_39
#define TP_PWR_PIN GPIO_NUM_25
#define LED_PIN GPIO_NUM_4

// EXT0 RTC_IO pins: 0,2,4,12-15,25-27,32-39.
// EXT1 RTC_CNTL pins: 32-39
#define RTC_INT_SEL GPIO_SEL_34
#define CHARGE_SEL GPIO_SEL_32
#define TP_PIN_SEL GPIO_SEL_33
#define IMU_INT_SEL GPIO_SEL_39

#define MPU_ADDR 0x69

#ifdef DEBUG_PORT
Expand Down
5 changes: 0 additions & 5 deletions include/ntp.hpp

This file was deleted.

8 changes: 7 additions & 1 deletion include/pages.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,17 @@
#include "pages/page-bearing.hpp"
#include "pages/page-temperature.hpp"
#include "pages/page-imu.hpp"
#include "pages/page-tz.hpp"
#include "eeprom.h"

#define MAX_PAGES 6

extern EasyButton tp_button;
void handleUi();
void increasePage();
void showPage();
void handleSleep(bool showMsg = true);
void initButton();
void handleAction();
void handleAction();
void initButtonHandlers();
void deinitButtonHandlers();
1 change: 0 additions & 1 deletion include/pages/page-clock.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#include <Arduino.h>
#include "clock.hpp"
#include "ntp.hpp"
#include "wristband-tft.hpp"
#include "wristband-wifi.hpp"

Expand Down
5 changes: 5 additions & 0 deletions include/pages/page-tz.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#include <Arduino.h>
#include "wristband-tft.hpp"
#include "eeprom.h"

void actionTZ();
68 changes: 0 additions & 68 deletions include/timezone.hpp

This file was deleted.

31 changes: 31 additions & 0 deletions include/timezones.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// Created by John Heenan 2020
#pragma once
#include <NTP.h> // for enums


#define DST_CODE_STRLEN_MAX 4
#define DST_REGION_STRLEN_MAX 20
#define DST_MAX 100


typedef struct
{
char region[DST_REGION_STRLEN_MAX + 1];
week_t week;
dow_t wday;
char dst_code[DST_CODE_STRLEN_MAX + 1];
month_t dst_month;
int8_t dst_hour;
int dst_offset;
char std_code[DST_CODE_STRLEN_MAX + 1];
month_t std_month;
int8_t std_hour;
int std_offset;

} dst_t;

extern int dst_index;
extern int dst_length;
extern dst_t dst_array[];


5 changes: 5 additions & 0 deletions include/wristband-tft.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,21 @@ void drawProgressBar(uint16_t x0, uint16_t y0, uint16_t w, uint16_t h, uint8_t p
void updatingText();
void msgError(const char *message);
void msgError(const char *message1, const char *message2);
void msgError(const char *message1, const char *message2, const char *message3);
void msgWarning(const char *message);
void msgWarning(const char *message1, const char *message2);
void msgWarning(const char *message1, const char *message2, const char *message3);
void msgSuccess(const char *message);
void msgSuccess(const char *message1, const char *message2);
void msgSuccess(const char *message1, const char *message2, const char *message3);
void msgInfo(const char *message);
void msgInfo(const char *message1, const char *message2);
void msgInfo(const char *message1, const char *message2, const char *message3);
void tftSleep(bool showMsg);
void msgBig(const char *message);
void msg(const char *message, uint16_t color);
void msg(const char *message1, const char *message2, uint16_t color);
void msg(const char *message1, const char *message2, const char *message3, uint16_t color);
void displayDate(const uint8_t day, const uint8_t month, const uint16_t year, bool utc);
uint16_t displayHour(const uint8_t hour, const uint8_t minute, bool utc);
uint16_t displayColon(uint16_t x, bool color, bool utc);
Expand Down
Loading

0 comments on commit e3e29f6

Please sign in to comment.