forked from TioRuben/TTGO-T-Wristband
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow IMU_SKIP to be changed by button.
Progress further to allow timezones to be set by button by allowing IMU_SKIP and timezone settings to be set in and recalled from NVS.
- Loading branch information
1 parent
dedbbdc
commit 119ddb8
Showing
15 changed files
with
203 additions
and
99 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,38 @@ | ||
// Edits and additions by John Heenan | ||
#pragma once | ||
#include <Arduino.h> | ||
#include <EEPROM.h> | ||
|
||
#define MAG_CALIBRATION_ADDRESS 0x00 | ||
#include <Preferences.h> // now recommended to use NVS with Preferences library rather than EEPROM library | ||
#include <NTP.h> // for enums | ||
|
||
#define MAGBIAS_FLOATS_MAX 3 | ||
void storeMagBiasEEPROM(float *magbias); | ||
void getMagBiasEEPROM(float *magbias); | ||
void getMagBiasEEPROM(float *magbias); | ||
|
||
// Following added by John Heenan, 2020 | ||
|
||
#define SETTINGS_STRLEN_MAX 10 | ||
|
||
typedef struct | ||
{ | ||
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; | ||
|
||
} settings_t; | ||
|
||
extern settings_t settings; | ||
size_t storeSettings(); | ||
size_t loadSettings(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
#include <Arduino.h> | ||
#include "wristband-tft.hpp" | ||
#include "mpu.hpp" | ||
#include "eeprom.h" | ||
|
||
void actionIMU(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,79 @@ | ||
|
||
// Edits and additions by John Heenan 2020. Converted to use Preferences | ||
#include "eeprom.hpp" | ||
#include "timezone.hpp" | ||
|
||
Preferences prefs; | ||
settings_t settings; | ||
|
||
void storeMagBiasEEPROM(float *magbias) | ||
{ | ||
EEPROM.begin(3 * sizeof(float)); | ||
for (uint8_t i = 0; i < 3; i++) | ||
{ | ||
EEPROM.put(MAG_CALIBRATION_ADDRESS + (i * sizeof(float)), magbias[i]); | ||
} | ||
EEPROM.commit(); | ||
EEPROM.end(); | ||
settings.magbias[0] = magbias[0]; | ||
settings.magbias[1] = magbias[1]; | ||
settings.magbias[2] = magbias[2]; | ||
storeSettings(); | ||
} | ||
|
||
void getMagBiasEEPROM(float *magbias) | ||
{ | ||
EEPROM.begin(3 * sizeof(float)); | ||
for (uint8_t i = 0; i < 3; i++) | ||
magbias[0] = settings.magbias[0]; | ||
magbias[1] = settings.magbias[1]; | ||
magbias[2] = settings.magbias[2]; | ||
} | ||
|
||
|
||
size_t storeSettings() | ||
{ | ||
return prefs.putBytes("settings", &settings, sizeof(settings)); | ||
} | ||
|
||
char *strcpy_settings(char *to, const char *from) | ||
{ | ||
size_t len = strlen(from); | ||
if (len > SETTINGS_STRLEN_MAX) | ||
len = SETTINGS_STRLEN_MAX; | ||
len++; | ||
memcpy(&settings.tz_dst_name, to, len); | ||
settings.tz_dst_name[len + 1] = 0; | ||
return to + len; | ||
} | ||
|
||
size_t loadSettings() //must be called first before any other functions on this page | ||
{ | ||
prefs.begin("eeprom"); | ||
size_t settingsLen = 0; | ||
#ifndef EEPROM_REINIT | ||
settingsLen = prefs.getBytesLength("settings"); | ||
#endif | ||
if (settingsLen){ | ||
size_t len= prefs.getBytes("settings", &settings, settingsLen); | ||
return len; | ||
} | ||
else | ||
{ | ||
magbias[i] = EEPROM.read(MAG_CALIBRATION_ADDRESS + (i * sizeof(float))); | ||
settings.magbias[0] = 0.0; | ||
settings.magbias[1] = 0.0; | ||
settings.magbias[2] = 0.0; | ||
#ifdef IMU_SKIP | ||
settings.imu_skip = true; | ||
#else | ||
settings.imu_skip = false; | ||
#endif | ||
settings.tz_uses_dst = TZ_USES_DST; | ||
settings.tz_offset = TZ_OFFSET; | ||
settings.tz_week = TZ_WEEK; | ||
settings.tz_wday = TZ_WDAY; | ||
|
||
strcpy_settings(settings.tz_dst_name, TZ_DST_NAME); | ||
settings.tz_dst_month = TZ_DST_MONTH; | ||
settings.tz_dst_hour = TZ_DST_HOUR; | ||
settings.tz_dst_offset = TZ_DST_OFFSET; | ||
|
||
strcpy_settings(settings.tz_std_name, TZ_STD_NAME); | ||
settings.tz_std_month = TZ_STD_MONTH; | ||
settings.tz_std_hour = TZ_STD_HOUR; | ||
settings.tz_std_offset = TZ_STD_OFFSET; | ||
|
||
return storeSettings(); | ||
} | ||
EEPROM.end(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
#include "pages/page-imu.hpp" | ||
|
||
void actionIMU() | ||
{ | ||
settings.imu_skip = settings.imu_skip ? false : true; | ||
storeSettings(); | ||
if (settings.imu_skip) | ||
{ | ||
mpuDeepSleep(); | ||
msgInfo("IMU (Acceler) is OFF", "Watch using less power"); | ||
} | ||
else | ||
{ | ||
initMPU(); | ||
msgInfo("IMU (Acceler) is ON", "Watch using more power"); | ||
} | ||
sleep(3); | ||
} |
Oops, something went wrong.
119ddb8
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is information about this branch here TioRuben#8 (comment)