Browse Source

WIP: add pagination, scroll w/ home button; scroll brightness w/ RST button

m5stack
Ryan Joseph 1 year ago
parent
commit
1d24db1f24
5 changed files with 44 additions and 44 deletions
  1. +28
    -24
      zero_watch.ino
  2. +1
    -1
      zw_common.h
  3. +2
    -6
      zw_displays.cpp
  4. +11
    -8
      zw_redis.cpp
  5. +2
    -5
      zw_wifi.cpp

+ 28
- 24
zero_watch.ino View File

@@ -19,7 +19,7 @@

#define CONTROL_POINT_SEP_CHAR '#'
#define SER_BAUD 115200
#define DEF_BRIGHT 1
#define DEF_BRIGHT 2
#define CHECKIN_EVERY_X_REFRESH 5
#define CHECKIN_EXPIRY_MULT 2
#define HEARTBEAT_EXPIRY_MULT 5
@@ -290,8 +290,7 @@ void readAndSetTime()
if (!(!ts.Hours && !ts.Minutes && !ts.Seconds))
{
M5.Rtc.SetTime(&ts);
zlog("Set time (from Redis) to %02d:%02d:%02d\n",
ts.Hours, ts.Minutes, ts.Seconds);
zlog("Set time: %02d:%02d\n", ts.Hours, ts.Minutes);
}
else
{
@@ -443,6 +442,13 @@ void zwM5StickC_UpdateBatteryDisplay()
M5.Lcd.setTextColor(CYAN, BLACK);
M5.Lcd.printf("%02d:%02d\n", M5.Rtc.Hour, M5.Rtc.Minute);
M5.Lcd.setTextColor(WHITE, BLACK);

// brightness line
auto brightLvl = 8 - gConfig.brightness;
M5.Lcd.drawLine(140, 10, 140, 30, DARKCYAN);
M5.Lcd.drawLine(142, 10, 142, 30, CYAN);
M5.Lcd.drawLine(143, 10, 143, 30, CYAN);
M5.Lcd.drawLine(145, 10, 145, 30, DARKCYAN);
}
#else
#define zwM5StickC_UpdateBatteryDisplay()
@@ -516,9 +522,9 @@ void loop()
{
__dispPage = (__dispPage + 1) % (__dispPages + 1);
}
}

forceTick = true;
forceTick = true;
}
}

if (curRst != __lastRst)
@@ -564,22 +570,22 @@ void setup()

verifyProvisioning();

zlog("\n%s v" ZEROWATCH_VER " starting...\n", gHostname.c_str());
#if DEEP_SLEEP_MODE_ENABLE
zlog("Deep sleep mode enabled by default\n");
#endif

if (!(gDisplays = zwdisplayInit(gHostname)))
{
dprint("Display init failed, halting forever\n");
__haltOrCatchFire();
}

#if M5STACKC
M5.Lcd.setCursor(0, 0, 1);
#endif

zlog("%s v" ZEROWATCH_VER "\n", gHostname.c_str());

auto dWalk = gDisplays;
for (; dWalk->clockPin != -1 && dWalk->dioPin != -1; dWalk++)
;
__dispPages = (int)((dWalk - gDisplays) / PAGE_SIZE) - (!((dWalk - gDisplays) % PAGE_SIZE) ? 1 : 0);
zlog("Have %d display pages\n", __dispPages + 1);

if (!gConfig.deepSleepMode)
{
@@ -636,31 +642,29 @@ void setup()
NUM_RETRIES - redisConnectRetries, seenErrnos.c_str());
}

#if M5STACKC
delay(5000);
gConfig.publishLogs = false;
gPublishLogsEmit = NULL;
#endif
gBootCount = gRedis->incrementBootcount();

zlog("Redis connection established, reading config...\n");
zlog("Initialized! (debug %s)\n", gConfig.debug ? "on" : "off");
zlog("Boot count: %lu\n", gBootCount);

readConfigAndUserKeys();

zlog("Fully initialized! (debug %sabled)\n", gConfig.debug ? "en" : "dis");

if (gConfig.debug && !gConfig.deepSleepMode)
delay(5000);

gPublishLogsEmit = redis_publish_logs_emit;

__isrTimer = timerBegin(0, 80, true);
timerAttachInterrupt(__isrTimer, &__isr, true);
timerAlarmWrite(__isrTimer, 1000000, true);
timerAlarmEnable(__isrTimer);

gBootCount = gRedis->incrementBootcount();
zlog("%s v" ZEROWATCH_VER " up & running\n", gHostname.c_str());
zlog("Boot count: %lu\n", gBootCount);
#if M5STACKC
delay(gConfig.debug ? 10000 : 1000);
gPublishLogsEmit = NULL;
M5.Lcd.setCursor(0, 0, 2);
M5.Lcd.fillScreen(TFT_BLACK);
#endif

gPublishLogsEmit = redis_publish_logs_emit;

tick(true);
}

+ 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.8"
#define ZEROWATCH_VER "0.2.5.14"
#define DEBUG 1
#define M5STACKC 1



+ 2
- 6
zw_displays.cpp View File

@@ -180,17 +180,13 @@ DisplaySpec *zwdisplayInit(String &hostname)

if (retSpec)
{
zlog("Initializing displays with brightness level %d\n", gConfig.brightness);
#if M5STACKC
zlog("M5StickC display init\n");
M5.Axp.ScreenBreath(2);
dprint("M5StickC display init\n");
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);
M5.Axp.ScreenBreath(gConfig.brightness + 7);
#else
zlog("Initializing displays with brightness level %d\n", gConfig.brightness);
auto spec = retSpec;
for (; spec->clockPin != -1 && spec->dioPin != -1; spec++)
{


+ 11
- 8
zw_redis.cpp View File

@@ -81,7 +81,7 @@ int ZWRedis::incrementBootcount(bool reset)
REDIS_KEY_CREATE_LOCAL(":bootcount");
int bcNext = 0;

if (!reset)
if (!reset)
{
bcNext = connection.redis->get(redisKey_local).toInt() + 1;
}
@@ -204,12 +204,12 @@ bool ZWRedis::clearControlPoint()
return connection.redis->del(REDIS_KEY(":config:controlPoint"));
}

bool ZWRedis::registerDevice(const char* registryName, const char* hostname, const char* ident)
bool ZWRedis::registerDevice(const char *registryName, const char *hostname, const char *ident)
{
return connection.redis->hset(registryName, ident, hostname);
}

void ZWRedis::logCritical(const char* format, ...)
void ZWRedis::logCritical(const char *format, ...)
{
#define BUFLEN 2048
char _buf[BUFLEN];
@@ -218,18 +218,21 @@ void ZWRedis::logCritical(const char* format, ...)
va_start(args, format);
vsnprintf(_buf, BUFLEN, format, args);
va_end(args);
// SHIT! need LPUSH
// SHIT! need LPUSH
//connection.redis->lset
// I guess this'll work ok for now...
static unsigned long __keyCount = 0;
connection.redis->hset(REDIS_KEY(":criticalLog"), String(++__keyCount).c_str(), _buf);
}

void ZWRedis::getTime(uint8_t* hour, uint8_t* minute, uint8_t* second)
void ZWRedis::getTime(uint8_t *hour, uint8_t *minute, uint8_t *second)
{
if (hour) *hour = (uint8_t)connection.redis->hget("rpjios.__meta.time", "hour").toInt();
if (minute) *minute = (uint8_t)connection.redis->hget("rpjios.__meta.time", "minute").toInt();
if (second) *second = (uint8_t)connection.redis->hget("rpjios.__meta.time", "second").toInt();
if (hour)
*hour = (uint8_t)connection.redis->hget("rpjios.__meta.time", "hour").toInt();
if (minute)
*minute = (uint8_t)connection.redis->hget("rpjios.__meta.time", "minute").toInt();
if (second)
*second = (uint8_t)connection.redis->hget("rpjios.__meta.time", "second").toInt();
}

void ZWRedisResponder::setValue(const char *format, ...)


+ 2
- 5
zw_wifi.cpp View File

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

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

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

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

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

zlog("WiFi adapter %s connected to '%s' as %s\n", WiFi.macAddress().c_str(),
EEPROMCFG_WiFiSSID, WiFi.localIP().toString().c_str());
zlog("Connected as %s\n", WiFi.localIP().toString().c_str());

return true;
}

Loading…
Cancel
Save