Browse Source

WIP, not sure when I did all of this but should probably check it in...

m5stack
Ryan Joseph 1 year ago
parent
commit
ce8908142e
5 changed files with 77 additions and 37 deletions
  1. +49
    -20
      zero_watch.ino
  2. +1
    -1
      zw_common.h
  3. +22
    -9
      zw_displays.cpp
  4. +2
    -4
      zw_logging.h
  5. +3
    -3
      zw_wifi.cpp

+ 49
- 20
zero_watch.ino View File

@@ -76,9 +76,9 @@ bool processGetValue(String &imEmit, ZWRedisResponder &responder)
{
responder.setValue(
"{ \"version\": \"%s\", \"sketchMD5\": \"%s\", "
"\"sketchSize\": %d, \"sdk\": \"%s\", \"chipRev\": %d}",
"\"sketchSize\": %d, \"sdk\": \"%s\", \"chipRev\": %d, \"eFuse\": %d}",
ZEROWATCH_VER, ESP.getSketchMD5().c_str(), ESP.getSketchSize(),
ESP.getSdkVersion(), ESP.getChipRevision());
ESP.getSdkVersion(), ESP.getChipRevision(), ESP.getEfuseMac());
}
else if (imEmit.equals("demo"))
{
@@ -262,6 +262,26 @@ void redis_publish_logs_emit(const char *fmt, ...)
free(jbuf);
}

#if M5STACKC
void M5Stack_publish_logs_emit(const char *fmt, ...)
{
char buf[1024];
bzero(buf, 1024);
va_list args;
va_start(args, fmt);
vsprintf(buf, fmt, args);
va_end(args);

auto len = strlen(buf);

if (buf[len - 1] == '\n')
buf[len - 1] = '\0';

M5.Lcd.println(buf);
Serial.println(buf);
}
#endif

#if M5STACKC
void readAndSetTime()
{
@@ -284,6 +304,8 @@ void readAndSetTime()

void readConfigAndUserKeys()
{
readAndSetTime();

auto curCfg = gRedis->readConfig();
bool dirty = false;

@@ -368,8 +390,6 @@ void heartbeat()
}
}

#define R_GREY 0xc618
#define R_DGREY 0x7bef
#if M5STACKC
void zwM5StickC_UpdateBatteryDisplay()
{
@@ -382,40 +402,43 @@ void zwM5StickC_UpdateBatteryDisplay()
discharge = M5.Axp.GetIdischargeData() / 2;
temp = -144.7 + M5.Axp.GetTempData() * 0.1;

const int xOff = 100;
const int xOff = 94;
const int yIncr = 16;
const int battFont = 2;
int yOff = 0;

M5.Lcd.setTextColor(R_GREY, BLACK);
M5.Lcd.drawLine(xOff - 7, yOff, xOff - 7, yOff + 80, R_DGREY);
M5.Lcd.setTextColor(LIGHTGREY, BLACK);
M5.Lcd.drawLine(xOff - 6, yOff, xOff - 6, yOff + 80, DARKCYAN);
M5.Lcd.setCursor(xOff, yOff, battFont);

if (M5.Axp.GetWarningLeve())
M5.Lcd.setTextColor(RED, BLACK);
uint16_t voltageColor = RED;
if (!M5.Axp.GetWarningLeve())
voltageColor = vbat > 3.9 ? GREEN : (vbat > 3.7 ? YELLOW : ORANGE);
M5.Lcd.setTextColor(voltageColor, BLACK);
M5.Lcd.printf("%.3fV\n",vbat); //battery voltage
M5.Lcd.setCursor(xOff, yOff += yIncr, battFont);
M5.Lcd.setTextColor(LIGHTGREY, BLACK);
M5.Lcd.printf("%.1fC\n",temp); //axp192 inside temp
M5.Lcd.setCursor(xOff, yOff += yIncr, battFont);

if (charge) {
M5.Lcd.setTextColor(GREEN, BLACK);
M5.Lcd.printf("%dmA \n",charge); //battery charging current
M5.Lcd.setCursor(xOff, yOff += yIncr, battFont);
M5.Lcd.setTextColor(R_GREY, BLACK);
M5.Lcd.setTextColor(LIGHTGREY, BLACK);
}
if (discharge) {
M5.Lcd.setTextColor(YELLOW, BLACK);
M5.Lcd.setTextColor(ORANGE, BLACK);
M5.Lcd.printf("%dmA \n",discharge); //battery output current
M5.Lcd.setCursor(xOff, yOff += yIncr, battFont);
M5.Lcd.setTextColor(R_GREY, BLACK);
M5.Lcd.setTextColor(LIGHTGREY, BLACK);
}
M5.Lcd.setTextColor(R_GREY, BLACK);
M5.Lcd.printf("%.1fC\n",temp); //axp192 inside temp
M5.Lcd.setCursor(xOff, yOff += yIncr, battFont);
M5.Rtc.GetBm8563Time();
M5.Lcd.setCursor(xOff, 65, 2);
M5.Lcd.setCursor(xOff, 65 - 8, 4);
M5.Lcd.setTextColor(CYAN, BLACK);
M5.Lcd.printf("%02d:%02d:%02d\n", M5.Rtc.Hour, M5.Rtc.Minute, M5.Rtc.Second);
M5.Lcd.printf("%02d:%02d\n", M5.Rtc.Hour, M5.Rtc.Minute);
M5.Lcd.setTextColor(WHITE, BLACK);
}
#else
@@ -484,6 +507,8 @@ void setup()
M5.begin();
pinMode(M5_BUTTON_HOME, INPUT_PULLUP);
zlog("Built for M5StickC\n");
gConfig.publishLogs = true;
gPublishLogsEmit = M5Stack_publish_logs_emit;
#else
pinMode(LED_BLTIN, OUTPUT);
Serial.begin(SER_BAUD);
@@ -556,9 +581,13 @@ void setup()
NUM_RETRIES - redisConnectRetries, seenErrnos.c_str());
}

zlog("Redis connection established, reading config...\n");
#if M5STACKC
delay(5000);
gConfig.publishLogs = false;
gPublishLogsEmit = NULL;
#endif

readAndSetTime();
zlog("Redis connection established, reading config...\n");

readConfigAndUserKeys();



+ 1
- 1
zw_common.h View File

@@ -1,7 +1,7 @@
#ifndef __ZW_COMMON__H__
#define __ZW_COMMON__H__

#define ZEROWATCH_VER "0.2.5.3"
#define ZEROWATCH_VER "0.2.5.6"
#define DEBUG 1
#define M5STACKC 1



+ 22
- 9
zw_displays.cpp View File

@@ -1,6 +1,7 @@
#include "zw_displays.h"
#include "zw_logging.h"
#include "zw_common.h"
#include "zw_provision.h"

// TODO: get rid of these externs! (and associated includes!)
extern unsigned long immediateLatency;
@@ -70,8 +71,10 @@ int noop(int a) { return a; }
void d_def(DisplaySpec *d)
{
#if M5STACKC
M5.Lcd.printf("%s: %d\n", getDispSpecShortName(d).c_str(),
d->spec.lastVal);
M5.Lcd.setTextColor(DARKGREY, BLACK);
M5.Lcd.printf("%s: ", getDispSpecShortName(d).c_str());
M5.Lcd.setTextColor(WHITE, BLACK);
M5.Lcd.printf("%d\n", d->spec.lastVal);
#else
d->disp->showNumberDec(d->spec.lastVal);
#endif
@@ -80,8 +83,15 @@ void d_def(DisplaySpec *d)
void d_tempf(DisplaySpec *d)
{
#if M5STACKC
M5.Lcd.printf("%s: %.1fF\n", getDispSpecSensorName(d).c_str(),
(float)d->spec.lastVal / 100.0);
float curVal = d->spec.lastVal / 100.0;
uint16_t tempColor = curVal > 100 ? RED : (curVal > 95.0 ? ORANGE :
(curVal > 85.0 ? YELLOW : (curVal > 65.0 ? GREEN :
(curVal > 55.0 ? CYAN : (curVal > 40.0 ? BLUE : PURPLE)))));
M5.Lcd.setTextColor(DARKGREY, BLACK);
M5.Lcd.printf("%s: ", getDispSpecSensorName(d).c_str());
M5.Lcd.setTextColor(tempColor, BLACK);
M5.Lcd.printf("%.1fF\n", curVal);
M5.Lcd.setTextColor(WHITE, BLACK);
#else
if (d->spec.lastVal < 10000)
{
@@ -99,8 +109,10 @@ void d_tempf(DisplaySpec *d)
void d_humidPercent(DisplaySpec *d)
{
#if M5STACKC
M5.Lcd.printf("%s: %.1f%%\n", getDispSpecSensorName(d).c_str(),
(float)d->spec.lastVal / 100.0);
M5.Lcd.setTextColor(DARKGREY, BLACK);
M5.Lcd.printf("%s: ", getDispSpecSensorName(d).c_str());
M5.Lcd.setTextColor(WHITE, BLACK);
M5.Lcd.printf("%.1f%%\n", (float)d->spec.lastVal / 100.0);
#else
d->disp->showNumberDecEx(d->spec.lastVal, 0, false);
d->disp->setSegments(prcntSeg, 2, 2);
@@ -164,16 +176,17 @@ DisplaySpec *zwdisplayInit(String &hostname)

if (retSpec)
{
auto spec = retSpec;
zlog("Initializing displays with brightness level %d\n", gConfig.brightness);
#if M5STACKC
zlog("M5StickC display init\n");
M5.Axp.ScreenBreath(gConfig.brightness + 7);
M5.Axp.ScreenBreath(2);
M5.Lcd.setRotation(3);
M5.Lcd.fillScreen(TFT_BLACK);
M5.Lcd.setCursor(0, 0, 2);
M5.Lcd.printf("%s v%s\n", gHostname.c_str(), ZEROWATCH_VER);
#else
auto spec = retSpec;
for (; spec->clockPin != -1 && spec->dioPin != -1; spec++)
{
zlog("Setting up display #%d with clock=%d DIO=%d\n",
@@ -184,7 +197,6 @@ DisplaySpec *zwdisplayInit(String &hostname)
spec->disp->setBrightness(gConfig.brightness);
__runAnimation(spec->disp, full_loop, false, 5);
}
#endif

if (gConfig.debug && !gConfig.deepSleepMode)
{
@@ -192,6 +204,7 @@ DisplaySpec *zwdisplayInit(String &hostname)
false, 4 - (int)(walk - retSpec), (int)(walk - retSpec)));
delay(2000);
}
#endif
}

return retSpec;


+ 2
- 4
zw_logging.h View File

@@ -13,11 +13,9 @@ extern void (*gPublishLogsEmit)(const char* fmt, ...);

#define zlog(fmt, ...) do { \
if (gConfig.publishLogs && gPublishLogsEmit) { \
if (gConfig.debug) gPublishLogsEmit("[%s:%d] " fmt, __FILE__, __LINE__, ##__VA_ARGS__); \
else gPublishLogsEmit(fmt, ##__VA_ARGS__); \
gPublishLogsEmit(fmt, ##__VA_ARGS__); \
} else { \
if (gConfig.debug) Serial.printf("[%s:%d] " fmt, __FILE__, __LINE__, ##__VA_ARGS__); \
else Serial.printf(fmt, ##__VA_ARGS__); \
Serial.printf(fmt, ##__VA_ARGS__); \
} } while (0)

#endif

+ 3
- 3
zw_wifi.cpp View File

@@ -5,7 +5,7 @@

bool zwWiFiInit(const char *hostname, ZWAppConfig config)
{
dprint("Disabling WiFi AP\n");
zlog("Disabling WiFi AP\n");
WiFi.mode(WIFI_MODE_STA);
WiFi.enableAP(false);

@@ -15,8 +15,8 @@ bool zwWiFiInit(const char *hostname, ZWAppConfig config)
}

auto bstat = WiFi.begin(EEPROMCFG_WiFiSSID, EEPROMCFG_WiFiPass);
dprint("Connecting to to '%s'...\n", EEPROMCFG_WiFiSSID);
dprint("WiFi.begin() -> %d\n", bstat);
zlog("Connecting to to '%s'...\n", EEPROMCFG_WiFiSSID);
zlog("WiFi.begin() -> %d\n", bstat);

// TODO: timeout!
while (WiFi.status() != WL_CONNECTED) {}


Loading…
Cancel
Save