Created
November 17, 2020 11:11
-
-
Save tanakamasayuki/7cf86f4428e80d65a7e20c1871e30962 to your computer and use it in GitHub Desktop.
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
#include "M5CoreInk.h" | |
#include <Preferences.h> | |
Preferences preferences; | |
Ink_Sprite InkPageSprite(&M5.M5Ink); | |
void setup() { | |
M5.begin(); | |
digitalWrite(LED_EXT_PIN, LOW); | |
M5.M5Ink.isInit(); | |
const char buildDate[] = __DATE__; | |
const char buildTime[] = __TIME__; | |
char bootDate[32]; | |
char bootTime[32]; | |
uint32_t bootCount; | |
char str[64]; | |
// Get Boot Date | |
preferences.begin("Boot", true); | |
preferences.getString("bootDate", bootDate, sizeof(bootDate)); | |
preferences.getString("bootTime", bootTime, sizeof(bootTime)); | |
bootCount = preferences.getUInt("bootCount", 1); | |
preferences.end(); | |
InkPageSprite.creatSprite(0, 0, 200, 200, true); | |
if (strcmp(bootDate, buildDate) == 0 && strcmp(bootTime, buildTime) == 0) { | |
Serial.println("Not first boot"); | |
// 削除用(前回の描画) | |
snprintf(str, sizeof(str), "Boot = %d", bootCount); | |
InkPageSprite.drawString(15, 110, str); | |
InkPageSprite.pushSprite(); | |
// 起動回数カウントアップ | |
bootCount++; | |
preferences.begin("Boot", false); | |
preferences.putUInt("bootCount", bootCount); | |
preferences.end(); | |
// 上書き用 | |
snprintf(str, sizeof(str), "Boot = %d", bootCount); | |
InkPageSprite.drawString(15, 110, str); | |
InkPageSprite.pushSprite(); | |
} else { | |
Serial.println("First boot"); | |
bootCount = 1; | |
// 初回起動は全初期化 | |
M5.M5Ink.clear(); | |
InkPageSprite.drawString(10, 50, "Press PWR Btn for sleep"); | |
InkPageSprite.drawString(15, 80, "after 5 sec wakeup."); | |
snprintf(str, sizeof(str), "Boot = %d", bootCount); | |
InkPageSprite.drawString(15, 110, str); | |
InkPageSprite.pushSprite(); | |
InkPageSprite.pushSprite(); | |
// Set Boot Date | |
preferences.begin("Boot", false); | |
preferences.putString("bootDate", buildDate); | |
preferences.putString("bootTime", buildTime); | |
preferences.putUInt("bootCount", bootCount); | |
preferences.end(); | |
} | |
} | |
void loop() { | |
if (M5.BtnPWR.wasPressed()) { | |
M5.shutdown(5); | |
} | |
M5.update(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment