forked from uxjulia/CrossInk
-
Notifications
You must be signed in to change notification settings - Fork 2
Power button short press when sleeping refreshes TRMNL #4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
mcmphd
wants to merge
8
commits into
yazdipour:development
Choose a base branch
from
mcmphd:feature/trmnl-power-button-refresh
base: development
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 7 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
32fc82a
feat(opds): download opds files in specific dir
yazdipour 154b3bb
feat(TRMNL): implement TRMNL Lockscreen
yazdipour b746f89
feat(power): short-press power button refreshes TRMNL sleep screen in…
mcmphd 6fc528e
feat(TRMNL): add settings toggle to gate power-button refresh
mcmphd a7306c1
feat(TRMNL): show refresh-specific status text during power-button re…
mcmphd f9e9c44
feat(TRMNL): add arrow pointing to the power button on the refresh hint
mcmphd 04e114c
fix(TRMNL): correct power button arrow to right edge, ~20% down
mcmphd ee40894
docs+cleanup: address code review comments
mcmphd File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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,88 @@ | ||
| #include "TrmnlDisplayJsonParser.h" | ||
|
|
||
| #include <cstdlib> | ||
| #include <cstring> | ||
|
|
||
| namespace { | ||
| void safeCopy(char* dst, const size_t dstSize, const char* src, const size_t srcLen) { | ||
| const size_t n = srcLen < dstSize - 1 ? srcLen : dstSize - 1; | ||
| memcpy(dst, src, n); | ||
| dst[n] = '\0'; | ||
| } | ||
| } // namespace | ||
|
|
||
| TrmnlDisplayJsonParser::TrmnlDisplayJsonParser() | ||
| : parser(JsonCallbacks{this, sOnKey, sOnString, sOnNumber, sOnBool, sOnNull, sOnObjectStart, sOnObjectEnd, | ||
| sOnArrayStart, sOnArrayEnd}) { | ||
| reset(); | ||
| } | ||
|
|
||
| void TrmnlDisplayJsonParser::reset() { | ||
| parser.reset(); | ||
| lastKey = LastKey::NONE; | ||
| depth = 0; | ||
| imageUrl[0] = '\0'; | ||
| filename[0] = '\0'; | ||
| refreshRateSeconds = 0; | ||
| imageUrlFound = false; | ||
| } | ||
|
|
||
| void TrmnlDisplayJsonParser::feed(const char* data, const size_t len) { parser.feed(data, len); } | ||
| bool TrmnlDisplayJsonParser::foundImageUrl() const { return imageUrlFound; } | ||
| bool TrmnlDisplayJsonParser::hasError() const { return parser.hasError(); } | ||
| const char* TrmnlDisplayJsonParser::getImageUrl() const { return imageUrl; } | ||
| const char* TrmnlDisplayJsonParser::getFilename() const { return filename; } | ||
| uint32_t TrmnlDisplayJsonParser::getRefreshRateSeconds() const { return refreshRateSeconds; } | ||
|
|
||
| void TrmnlDisplayJsonParser::sOnKey(void* ctx, const char* key, const size_t len) { | ||
| auto* self = static_cast<TrmnlDisplayJsonParser*>(ctx); | ||
| if (self->depth != 1) { | ||
| self->lastKey = LastKey::NONE; | ||
| return; | ||
| } | ||
| if (len == 9 && memcmp(key, "image_url", 9) == 0) { | ||
| self->lastKey = LastKey::IMAGE_URL; | ||
| } else if ((len == 8 && memcmp(key, "filename", 8) == 0) || (len == 10 && memcmp(key, "image_name", 10) == 0)) { | ||
| self->lastKey = LastKey::FILENAME; | ||
| } else if (len == 12 && memcmp(key, "refresh_rate", 12) == 0) { | ||
| self->lastKey = LastKey::REFRESH_RATE; | ||
| } else { | ||
| self->lastKey = LastKey::NONE; | ||
| } | ||
| } | ||
|
|
||
| void TrmnlDisplayJsonParser::sOnString(void* ctx, const char* value, const size_t len) { | ||
| auto* self = static_cast<TrmnlDisplayJsonParser*>(ctx); | ||
| if (self->depth == 1 && self->lastKey == LastKey::IMAGE_URL) { | ||
| safeCopy(self->imageUrl, sizeof(self->imageUrl), value, len); | ||
| self->imageUrlFound = self->imageUrl[0] != '\0'; | ||
| } else if (self->depth == 1 && self->lastKey == LastKey::FILENAME) { | ||
| safeCopy(self->filename, sizeof(self->filename), value, len); | ||
| } | ||
| self->lastKey = LastKey::NONE; | ||
| } | ||
|
|
||
| void TrmnlDisplayJsonParser::sOnNumber(void* ctx, const char* value, const size_t /*len*/) { | ||
| auto* self = static_cast<TrmnlDisplayJsonParser*>(ctx); | ||
| if (self->depth == 1 && self->lastKey == LastKey::REFRESH_RATE) { | ||
| self->refreshRateSeconds = static_cast<uint32_t>(strtoul(value, nullptr, 10)); | ||
| } | ||
| self->lastKey = LastKey::NONE; | ||
| } | ||
|
|
||
| void TrmnlDisplayJsonParser::sOnBool(void* ctx, bool /*value*/) { | ||
| static_cast<TrmnlDisplayJsonParser*>(ctx)->lastKey = LastKey::NONE; | ||
| } | ||
| void TrmnlDisplayJsonParser::sOnNull(void* ctx) { static_cast<TrmnlDisplayJsonParser*>(ctx)->lastKey = LastKey::NONE; } | ||
| void TrmnlDisplayJsonParser::sOnObjectStart(void* ctx) { | ||
| auto* self = static_cast<TrmnlDisplayJsonParser*>(ctx); | ||
| self->depth++; | ||
| self->lastKey = LastKey::NONE; | ||
| } | ||
| void TrmnlDisplayJsonParser::sOnObjectEnd(void* ctx) { | ||
| auto* self = static_cast<TrmnlDisplayJsonParser*>(ctx); | ||
| if (self->depth > 0) self->depth--; | ||
| self->lastKey = LastKey::NONE; | ||
| } | ||
| void TrmnlDisplayJsonParser::sOnArrayStart(void* ctx) { sOnObjectStart(ctx); } | ||
| void TrmnlDisplayJsonParser::sOnArrayEnd(void* ctx) { sOnObjectEnd(ctx); } |
This file contains hidden or 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,40 @@ | ||
| #pragma once | ||
|
|
||
| #include <cstddef> | ||
| #include <cstdint> | ||
|
|
||
| #include "StreamingJsonParser.h" | ||
|
|
||
| class TrmnlDisplayJsonParser { | ||
| public: | ||
| TrmnlDisplayJsonParser(); | ||
| void reset(); | ||
| void feed(const char* data, size_t len); | ||
|
|
||
| bool foundImageUrl() const; | ||
| bool hasError() const; | ||
| const char* getImageUrl() const; | ||
| const char* getFilename() const; | ||
| uint32_t getRefreshRateSeconds() const; | ||
|
|
||
| private: | ||
| enum class LastKey : uint8_t { NONE, IMAGE_URL, FILENAME, REFRESH_RATE }; | ||
|
|
||
| static void sOnKey(void* ctx, const char* key, size_t len); | ||
| static void sOnString(void* ctx, const char* value, size_t len); | ||
| static void sOnNumber(void* ctx, const char* value, size_t len); | ||
| static void sOnBool(void* ctx, bool value); | ||
| static void sOnNull(void* ctx); | ||
| static void sOnObjectStart(void* ctx); | ||
| static void sOnObjectEnd(void* ctx); | ||
| static void sOnArrayStart(void* ctx); | ||
| static void sOnArrayEnd(void* ctx); | ||
|
|
||
| StreamingJsonParser parser; | ||
| LastKey lastKey = LastKey::NONE; | ||
| uint16_t depth = 0; | ||
| char imageUrl[512] = ""; | ||
| char filename[128] = ""; | ||
| uint32_t refreshRateSeconds = 0; | ||
| bool imageUrlFound = false; | ||
| }; |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.