From 2c4bf135af1af86cba058130d8c31ce2cfac8f9c Mon Sep 17 00:00:00 2001 From: Takao Akaki Date: Thu, 13 Jul 2023 22:15:00 +0900 Subject: [PATCH 01/25] Bug fix in 0.8.4 when changing priority. --- library.json | 2 +- library.properties | 2 +- src/Avatar.cpp | 8 ++++---- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/library.json b/library.json index 4a16a54..2e1bb15 100644 --- a/library.json +++ b/library.json @@ -17,7 +17,7 @@ "license": "MIT", "dependencies": { }, - "version": "0.8.4", + "version": "0.8.5", "frameworks": "arduino", "platforms": "espressif32" } diff --git a/library.properties b/library.properties index f0400c3..7ad4e6d 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=M5Stack_Avatar -version=0.8.4 +version=0.8.5 author=Shinya Ishikawa maintainer=Shinya Ishikawa sentence=Yet another avatar module for M5Stack diff --git a/src/Avatar.cpp b/src/Avatar.cpp index 88912e0..8dcd15e 100644 --- a/src/Avatar.cpp +++ b/src/Avatar.cpp @@ -4,7 +4,7 @@ #include "Avatar.h" namespace m5avatar { -const uint32_t DEFAULT_STACK_SIZE = 1024; +const uint32_t DEFAULT_STACK_SIZE = 2048; unsigned int seed = 0; @@ -94,7 +94,7 @@ void Avatar::addTask(TaskFunction_t f, const char* name) { name, /* Name of the task */ DEFAULT_STACK_SIZE, /* Stack size in words */ ctx, /* Task input parameter */ - 4, /* P2014riority of the task */ + 3, /* P2014riority of the task */ NULL, /* Task handle. */ APP_CPU_NUM); // xTaskCreatePinnedToCore(f, /* Function to implement the task */ @@ -133,7 +133,7 @@ void Avatar::start(int colorDepth) { "drawLoop", /* Name of the task */ 2048, /* Stack size in words */ ctx, /* Task input parameter */ - 2, /* Priority of the task */ + 1, /* Priority of the task */ &drawTaskHandle, /* Task handle. */ APP_CPU_NUM); @@ -141,7 +141,7 @@ void Avatar::start(int colorDepth) { "facialLoop", /* Name of the task */ 1024, /* Stack size in words */ ctx, /* Task input parameter */ - 3, /* Priority of the task */ + 2, /* Priority of the task */ NULL, /* Task handle. */ APP_CPU_NUM); } From c180e668a4ed1f29e7f2296720688eaf02569852 Mon Sep 17 00:00:00 2001 From: Takao Akaki Date: Tue, 25 Jul 2023 20:54:08 +0900 Subject: [PATCH 02/25] Fix scale bug --- src/Face.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Face.cpp b/src/Face.cpp index 28ba24b..af670a8 100644 --- a/src/Face.cpp +++ b/src/Face.cpp @@ -117,7 +117,7 @@ void Face::draw(DrawContext *ctx) { if (scale != 1.0 || rotation != 0) { tmpSprite->setColorDepth(ctx->getColorDepth()); - tmpSprite->createSprite((int32_t)((float)M5.Display.width() * scale), (int32_t)((float)M5.Display.height() * scale)); + tmpSprite->createSprite((int32_t)((float)320 * scale), (int32_t)((float)240 * scale)); tmpSprite->setBitmapColor(ctx->getColorPalette()->get(COLOR_PRIMARY), ctx->getColorPalette()->get(COLOR_BACKGROUND)); if (ctx->getColorDepth() != 1) { From 45418886941de1237dd755a34047600ff1c45beb Mon Sep 17 00:00:00 2001 From: Takao Akaki Date: Sun, 6 Aug 2023 23:36:07 +0900 Subject: [PATCH 03/25] Deal with freezing issue in models without PSRAM --- src/Avatar.cpp | 17 +++++++++++++---- src/Avatar.h | 3 ++- src/Face.cpp | 12 ++++++------ src/Face.h | 3 +++ 4 files changed, 24 insertions(+), 11 deletions(-) diff --git a/src/Avatar.cpp b/src/Avatar.cpp index 8dcd15e..582e467 100644 --- a/src/Avatar.cpp +++ b/src/Avatar.cpp @@ -36,11 +36,14 @@ void facialLoop(void *args) { unsigned long last_saccade_millis = 0; unsigned long last_blink_millis = 0; bool eye_open = true; + float vertical = 0.0f; + float horizontal = 0.0f; + float breath = 0.0f; while (avatar->isDrawing()) { if ((millis() - last_saccade_millis) > saccade_interval) { - float vertical = rand_r(&seed) / (RAND_MAX / 2.0) - 1; - float horizontal = rand_r(&seed) / (RAND_MAX / 2.0) - 1; + vertical = rand_r(&seed) / (RAND_MAX / 2.0) - 1; + horizontal = rand_r(&seed) / (RAND_MAX / 2.0) - 1; avatar->setGaze(vertical, horizontal); saccade_interval = 500 + 100 * random(20); last_saccade_millis = millis(); @@ -58,8 +61,8 @@ void facialLoop(void *args) { last_blink_millis = millis(); } c = (c + 1) % 100; - float f = sin(c * 2 * PI / 100.0); - avatar->setBreath(f); + breath = sin(c * 2 * PI / 100.0); + avatar->setBreath(breath); vTaskDelay(33); } vTaskDelete(NULL); @@ -83,6 +86,10 @@ Avatar::Avatar(Face *face) colorDepth{1}, batteryIconStatus{BatteryIconStatus::invisible}{} +Avatar::~Avatar() { + delete face; +} + void Avatar::setFace(Face *face) { this->face = face; } Face *Avatar::getFace() const { return face; } @@ -159,7 +166,9 @@ void Avatar::draw() { bool Avatar::isDrawing() { return _isDrawing; } void Avatar::setExpression(Expression expression) { + suspend(); this->expression = expression; + resume(); } Expression Avatar::getExpression() { diff --git a/src/Avatar.h b/src/Avatar.h index f03da30..6531e30 100644 --- a/src/Avatar.h +++ b/src/Avatar.h @@ -31,7 +31,7 @@ class Avatar { public: Avatar(); explicit Avatar(Face *face); - ~Avatar() = default; + ~Avatar(); Avatar(const Avatar &other) = default; Avatar &operator=(const Avatar &other) = default; Face *getFace() const; @@ -61,6 +61,7 @@ class Avatar { void resume(); void setBatteryIcon(bool iconStatus); void setBatteryStatus(bool isCharging, int32_t batteryLevel); + void resetDraw(); }; diff --git a/src/Face.cpp b/src/Face.cpp index af670a8..df7eec6 100644 --- a/src/Face.cpp +++ b/src/Face.cpp @@ -5,9 +5,6 @@ #include "Face.h" namespace m5avatar { -Balloon b; -Effect h; -BatteryIcon battery; BoundingRect br; Face::Face() @@ -54,6 +51,9 @@ Face::~Face() { delete eyeblowLPos; delete sprite; delete boundingRect; + delete b; + delete h; + delete battery; } void Face::setMouth(Drawable *mouth) { this->mouth = mouth; } @@ -106,9 +106,9 @@ void Face::draw(DrawContext *ctx) { eyeblowL->draw(sprite, rect, ctx); // TODO(meganetaaan): make balloons and effects selectable - b.draw(sprite, br, ctx); - h.draw(sprite, br, ctx); - battery.draw(sprite, br, ctx); + b->draw(sprite, br, ctx); + h->draw(sprite, br, ctx); + battery->draw(sprite, br, ctx); // drawAccessory(sprite, position, ctx); // TODO(meganetaaan): rethink responsibility for transform function diff --git a/src/Face.h b/src/Face.h index 1b1b9da..72344b1 100644 --- a/src/Face.h +++ b/src/Face.h @@ -30,6 +30,9 @@ class Face { BoundingRect *boundingRect; M5Canvas *sprite; M5Canvas *tmpSprite; + Balloon *b; + Effect *h; + BatteryIcon *battery; public: // constructor From 7e2455696165067cb5bb807cd39398863512517d Mon Sep 17 00:00:00 2001 From: Takao Akaki Date: Sun, 6 Aug 2023 23:50:50 +0900 Subject: [PATCH 04/25] delete resetDraw --- src/Avatar.h | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Avatar.h b/src/Avatar.h index 6531e30..da46c3c 100644 --- a/src/Avatar.h +++ b/src/Avatar.h @@ -61,7 +61,6 @@ class Avatar { void resume(); void setBatteryIcon(bool iconStatus); void setBatteryStatus(bool isCharging, int32_t batteryLevel); - void resetDraw(); }; From e0c4e09eadae1c5380bf2cfec297010d3fac150e Mon Sep 17 00:00:00 2001 From: Takao Akaki Date: Mon, 7 Aug 2023 13:29:36 +0900 Subject: [PATCH 05/25] raise version v0.8.6 --- library.json | 2 +- library.properties | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/library.json b/library.json index 2e1bb15..4687ac6 100644 --- a/library.json +++ b/library.json @@ -17,7 +17,7 @@ "license": "MIT", "dependencies": { }, - "version": "0.8.5", + "version": "0.8.6", "frameworks": "arduino", "platforms": "espressif32" } diff --git a/library.properties b/library.properties index 7ad4e6d..d958173 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=M5Stack_Avatar -version=0.8.5 +version=0.8.6 author=Shinya Ishikawa maintainer=Shinya Ishikawa sentence=Yet another avatar module for M5Stack From 485a13f799a77a77617edc84acb3194152b9b5d5 Mon Sep 17 00:00:00 2001 From: Takao Akaki Date: Wed, 9 Aug 2023 16:15:26 +0900 Subject: [PATCH 06/25] Review the drawing of Face.cpp(@lovyan03) --- src/Face.cpp | 55 +++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 39 insertions(+), 16 deletions(-) diff --git a/src/Face.cpp b/src/Face.cpp index df7eec6..16966af 100644 --- a/src/Face.cpp +++ b/src/Face.cpp @@ -115,22 +115,45 @@ void Face::draw(DrawContext *ctx) { float scale = ctx->getScale(); float rotation = ctx->getRotation(); - if (scale != 1.0 || rotation != 0) { - tmpSprite->setColorDepth(ctx->getColorDepth()); - tmpSprite->createSprite((int32_t)((float)320 * scale), (int32_t)((float)240 * scale)); - tmpSprite->setBitmapColor(ctx->getColorPalette()->get(COLOR_PRIMARY), - ctx->getColorPalette()->get(COLOR_BACKGROUND)); - if (ctx->getColorDepth() != 1) { - tmpSprite->fillSprite(ctx->getColorPalette()->get(COLOR_BACKGROUND)); - } else { - tmpSprite->fillSprite(0); - } - sprite->pushRotateZoom(tmpSprite, rotation, scale, scale); - tmpSprite->pushSprite(&M5.Display, boundingRect->getLeft(), boundingRect->getTop()); - tmpSprite->deleteSprite(); - } else { - sprite->pushSprite(&M5.Display, boundingRect->getLeft(), boundingRect->getTop()); +// ▼▼▼▼ここから▼▼▼▼ + static constexpr uint8_t y_step = 8; + + if (tmpSprite->getBuffer() == nullptr) { + // 出力先と同じcolorDepthを指定することで、DMA転送が可能になる。 + tmpSprite->setColorDepth(M5.Display.getColorDepth()); + + // 確保するメモリは高さ8ピクセルの横長の細長い短冊状とする。 + tmpSprite->createSprite(boundingRect->getWidth(), y_step); } + + // 背景クリア用の色を設定 + tmpSprite->setBaseColor((ctx->getColorDepth() != 1) ? ctx->getColorPalette()->get(COLOR_BACKGROUND) : (uint16_t)0); + int y = 0; + do { + // 背景色で塗り潰し + tmpSprite->clear(); + + // 傾きとズームを反映してspriteからtmpSpriteに転写 + sprite->pushRotateZoom(tmpSprite, boundingRect->getWidth()>>1, (boundingRect->getHeight()>>1) - y, rotation, scale, scale); + + // tmpSpriteから画面に転写 + M5.Display.startWrite(); + + // 事前にstartWriteしておくことで、pushSprite はDMA転送を開始するとすぐに処理を終えて戻ってくる。 + tmpSprite->pushSprite(&M5.Display, boundingRect->getLeft(), boundingRect->getTop() + y); + + // DMA転送中にdelay処理を設けることにより、DMA転送中に他のタスクへCPU処理時間を譲ることができる。 + delay(1); + + // endWriteによってDMA転送の終了を待つ。 + M5.Display.endWrite(); + + } while ((y += y_step) < M5.Display.height()); + +// 削除するのが良いかどうか要検討 (次回メモリ確保できない場合は描画できなくなるので、維持しておいても良いかも?) +// tmpSprite->deleteSprite(); +// ▲▲▲▲ここまで▲▲▲▲ + sprite->deleteSprite(); } -} // namespace m5avatar +} // namespace m5avatar \ No newline at end of file From 83cf73f2f6d83140df74ca37b0ad6fa182b74785 Mon Sep 17 00:00:00 2001 From: Takao Akaki Date: Wed, 9 Aug 2023 23:21:57 +0900 Subject: [PATCH 07/25] Fix Face.cpp --- src/Face.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/Face.cpp b/src/Face.cpp index 16966af..44535f0 100644 --- a/src/Face.cpp +++ b/src/Face.cpp @@ -120,6 +120,7 @@ void Face::draw(DrawContext *ctx) { if (tmpSprite->getBuffer() == nullptr) { // 出力先と同じcolorDepthを指定することで、DMA転送が可能になる。 + // Display自体は16bit or 24bitしか指定できないが、細長なので1bitではなくても大丈夫。 tmpSprite->setColorDepth(M5.Display.getColorDepth()); // 確保するメモリは高さ8ピクセルの横長の細長い短冊状とする。 @@ -127,7 +128,7 @@ void Face::draw(DrawContext *ctx) { } // 背景クリア用の色を設定 - tmpSprite->setBaseColor((ctx->getColorDepth() != 1) ? ctx->getColorPalette()->get(COLOR_BACKGROUND) : (uint16_t)0); + tmpSprite->setBaseColor(ctx->getColorPalette()->get(COLOR_BACKGROUND)); int y = 0; do { // 背景色で塗り潰し @@ -148,7 +149,7 @@ void Face::draw(DrawContext *ctx) { // endWriteによってDMA転送の終了を待つ。 M5.Display.endWrite(); - } while ((y += y_step) < M5.Display.height()); + } while ((y += y_step) < boundingRect->getHeight()); // 削除するのが良いかどうか要検討 (次回メモリ確保できない場合は描画できなくなるので、維持しておいても良いかも?) // tmpSprite->deleteSprite(); From 70cdca272100980e68022483c31ec14933a1c27c Mon Sep 17 00:00:00 2001 From: Takao Akaki Date: Thu, 10 Aug 2023 16:10:27 +0900 Subject: [PATCH 08/25] raise version v0.9.0 --- library.json | 2 +- library.properties | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/library.json b/library.json index 4687ac6..11c30de 100644 --- a/library.json +++ b/library.json @@ -17,7 +17,7 @@ "license": "MIT", "dependencies": { }, - "version": "0.8.6", + "version": "0.9.0", "frameworks": "arduino", "platforms": "espressif32" } diff --git a/library.properties b/library.properties index d958173..d0eaf5b 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=M5Stack_Avatar -version=0.8.6 +version=0.9.0 author=Shinya Ishikawa maintainer=Shinya Ishikawa sentence=Yet another avatar module for M5Stack From fbfc0387ed616af5ac3982d0f9caab6b09e4d863 Mon Sep 17 00:00:00 2001 From: Takao Akaki Date: Fri, 1 Sep 2023 13:07:28 +0900 Subject: [PATCH 09/25] Update addTask --- src/Avatar.cpp | 29 +++++++++++++---------------- src/Avatar.h | 7 ++++++- 2 files changed, 19 insertions(+), 17 deletions(-) diff --git a/src/Avatar.cpp b/src/Avatar.cpp index 582e467..65527bb 100644 --- a/src/Avatar.cpp +++ b/src/Avatar.cpp @@ -4,7 +4,6 @@ #include "Avatar.h" namespace m5avatar { -const uint32_t DEFAULT_STACK_SIZE = 2048; unsigned int seed = 0; @@ -94,23 +93,21 @@ void Avatar::setFace(Face *face) { this->face = face; } Face *Avatar::getFace() const { return face; } -void Avatar::addTask(TaskFunction_t f, const char* name) { +void Avatar::addTask(TaskFunction_t f + , const char* name + , const uint32_t stack_size + , UBaseType_t priority + , TaskHandle_t* const task_handle + , const BaseType_t core_id) { DriveContext *ctx = new DriveContext(this); // TODO(meganetaaan): set a task handler - xTaskCreateUniversal(f, /* Function to implement the task */ - name, /* Name of the task */ - DEFAULT_STACK_SIZE, /* Stack size in words */ - ctx, /* Task input parameter */ - 3, /* P2014riority of the task */ - NULL, /* Task handle. */ - APP_CPU_NUM); - // xTaskCreatePinnedToCore(f, /* Function to implement the task */ - // name, /* Name of the task */ - // DEFAULT_STACK_SIZE, /* Stack size in words */ - // ctx, /* Task input parameter */ - // 1, /* P2014riority of the task */ - // NULL, /* Task handle. */ - // 1); /* Core where the task should run */ + xTaskCreateUniversal(f, /* Function to implement the task */ + name, /* Name of the task */ + stack_size, /* Stack size in words */ + ctx, /* Task input parameter */ + priority, /* Priority of the task */ + task_handle, /* Task handle. */ + core_id); /* Core No*/ } void Avatar::init(int colorDepth) { diff --git a/src/Avatar.h b/src/Avatar.h index da46c3c..c060899 100644 --- a/src/Avatar.h +++ b/src/Avatar.h @@ -56,7 +56,12 @@ class Avatar { bool isDrawing(); void start(int colorDepth = 1); void stop(); - void addTask(TaskFunction_t f, const char* name); + void addTask(TaskFunction_t f + , const char* name + , const uint32_t stack_size=2048 + , UBaseType_t priority=4 + , TaskHandle_t* const task_handle=NULL + , const BaseType_t core_id=APP_CPU_NUM); void suspend(); void resume(); void setBatteryIcon(bool iconStatus); From ffb01db4e834576d79878b34055f2ae951dc9764 Mon Sep 17 00:00:00 2001 From: Takao Akaki Date: Sun, 10 Sep 2023 16:03:43 +0900 Subject: [PATCH 10/25] DrawLoop drawing interval to 10msec --- src/Avatar.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Avatar.cpp b/src/Avatar.cpp index 65527bb..dfd8242 100644 --- a/src/Avatar.cpp +++ b/src/Avatar.cpp @@ -21,7 +21,7 @@ void drawLoop(void *args) { if (avatar->isDrawing()) { avatar->draw(); } - vTaskDelay(33); + vTaskDelay(10/portTICK_PERIOD_MS); } vTaskDelete(NULL); } @@ -62,7 +62,7 @@ void facialLoop(void *args) { c = (c + 1) % 100; breath = sin(c * 2 * PI / 100.0); avatar->setBreath(breath); - vTaskDelay(33); + vTaskDelay(33/portTICK_PERIOD_MS); } vTaskDelete(NULL); } From cf4d0d2ac2744a2f99ab41fb0149c560c29b5366 Mon Sep 17 00:00:00 2001 From: McbeEringi <46889548+McbeEringi@users.noreply.github.com> Date: Sun, 29 Oct 2023 23:22:25 +0900 Subject: [PATCH 11/25] APP_CPU_NUM fallback --- src/Avatar.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/Avatar.h b/src/Avatar.h index da46c3c..4abd8ed 100644 --- a/src/Avatar.h +++ b/src/Avatar.h @@ -8,6 +8,10 @@ #include "Face.h" #include +#ifndef APP_CPU_NUM +#define APP_CPU_NUM PRO_CPU_NUM +#endif + namespace m5avatar { class Avatar { private: From 4f961806b5fbe536de667347737278cf025f842f Mon Sep 17 00:00:00 2001 From: hollyhockberry <49336378+hollyhockberry@users.noreply.github.com> Date: Sat, 11 Nov 2023 22:00:00 +0900 Subject: [PATCH 12/25] Support native build --- library.json | 12 +++++++---- library.properties | 1 + src/Avatar.cpp | 49 +++++++++++++++++++++++++++++++++++--------- src/Avatar.h | 12 +++++++++++ src/BoundingRect.cpp | 1 - src/BoundingRect.h | 2 +- src/ColorPalette.cpp | 4 ++-- src/Face.cpp | 6 +++++- src/Mouth.cpp | 4 ++++ 9 files changed, 72 insertions(+), 19 deletions(-) diff --git a/library.json b/library.json index 11c30de..526f812 100644 --- a/library.json +++ b/library.json @@ -15,9 +15,13 @@ } ], "license": "MIT", - "dependencies": { - }, + "dependencies": [ + { + "name": "M5Unified", + "version": ">=0.1.10" + } + ], "version": "0.9.0", - "frameworks": "arduino", - "platforms": "espressif32" + "frameworks": ["arduino", "espidf", "*"], + "platforms": ["espressif32", "native"] } diff --git a/library.properties b/library.properties index d0eaf5b..117f309 100644 --- a/library.properties +++ b/library.properties @@ -8,3 +8,4 @@ category=Device Control url=https://platformio.org/lib/show/4529/M5Stack-Avatar architectures=esp32 includes=Avatar.h +depends=M5Unified diff --git a/src/Avatar.cpp b/src/Avatar.cpp index dfd8242..d4f4d0a 100644 --- a/src/Avatar.cpp +++ b/src/Avatar.cpp @@ -3,10 +3,26 @@ // license information. #include "Avatar.h" + +#ifndef PI +#define PI 3.1415926535897932384626433832795 +#endif + namespace m5avatar { unsigned int seed = 0; +#ifdef SDL_h_ +#define TaskResult() return 0 +#define TaskDelay(ms) lgfx::delay(ms) +long random(long howbig) { + return std::rand() % howbig; +} +#else +#define TaskResult() vTaskDelete(NULL) +#define TaskDelay(ms) vTaskDelay(ms/portTICK_PERIOD_MS) +#endif + // TODO(meganetaaan): make read-only DriveContext::DriveContext(Avatar *avatar) : avatar{avatar} {} @@ -14,19 +30,19 @@ Avatar *DriveContext::getAvatar() { return avatar; } TaskHandle_t drawTaskHandle; -void drawLoop(void *args) { +TaskResult_t drawLoop(void *args) { DriveContext *ctx = reinterpret_cast(args); Avatar *avatar = ctx->getAvatar(); while (avatar->isDrawing()) { if (avatar->isDrawing()) { avatar->draw(); } - vTaskDelay(10/portTICK_PERIOD_MS); + TaskDelay(10); } - vTaskDelete(NULL); + TaskResult(); } -void facialLoop(void *args) { +TaskResult_t facialLoop(void *args) { int c = 0; DriveContext *ctx = reinterpret_cast(args); Avatar *avatar = ctx->getAvatar(); @@ -40,15 +56,15 @@ void facialLoop(void *args) { float breath = 0.0f; while (avatar->isDrawing()) { - if ((millis() - last_saccade_millis) > saccade_interval) { + if ((lgfx::millis() - last_saccade_millis) > saccade_interval) { vertical = rand_r(&seed) / (RAND_MAX / 2.0) - 1; horizontal = rand_r(&seed) / (RAND_MAX / 2.0) - 1; avatar->setGaze(vertical, horizontal); saccade_interval = 500 + 100 * random(20); - last_saccade_millis = millis(); + last_saccade_millis = lgfx::millis(); } - if ((millis()- last_blink_millis) > blink_interval) { + if ((lgfx::millis()- last_blink_millis) > blink_interval) { if (eye_open) { avatar->setEyeOpenRatio(1); blink_interval = 2500 + 100 * random(20); @@ -57,14 +73,14 @@ void facialLoop(void *args) { blink_interval = 300 + 10 * random(20); } eye_open = !eye_open; - last_blink_millis = millis(); + last_blink_millis = lgfx::millis(); } c = (c + 1) % 100; breath = sin(c * 2 * PI / 100.0); avatar->setBreath(breath); - vTaskDelay(33/portTICK_PERIOD_MS); + TaskDelay(33); } - vTaskDelete(NULL); + TaskResult(); } Avatar::Avatar() : Avatar(new Face()) {} @@ -100,6 +116,9 @@ void Avatar::addTask(TaskFunction_t f , TaskHandle_t* const task_handle , const BaseType_t core_id) { DriveContext *ctx = new DriveContext(this); +#ifdef SDL_h_ + SDL_CreateThreadWithStackSize(f, name, stack_size, ctx); +#else // TODO(meganetaaan): set a task handler xTaskCreateUniversal(f, /* Function to implement the task */ name, /* Name of the task */ @@ -108,6 +127,7 @@ void Avatar::addTask(TaskFunction_t f priority, /* Priority of the task */ task_handle, /* Task handle. */ core_id); /* Core No*/ +#endif } void Avatar::init(int colorDepth) { @@ -118,11 +138,15 @@ void Avatar::init(int colorDepth) { void Avatar::stop() { _isDrawing = false; } void Avatar::suspend() { +#ifndef SDL_h_ vTaskSuspend(drawTaskHandle); +#endif } void Avatar::resume() { +#ifndef SDL_h_ vTaskResume(drawTaskHandle); +#endif } void Avatar::start(int colorDepth) { @@ -132,6 +156,10 @@ void Avatar::start(int colorDepth) { this->colorDepth = colorDepth; DriveContext *ctx = new DriveContext(this); +#ifdef SDL_h_ + SDL_CreateThreadWithStackSize(drawLoop, "drawLoop", 2048, ctx); + SDL_CreateThreadWithStackSize(facialLoop, "facialLoop", 1024, ctx); +#else // TODO(meganetaaan): keep handle of these tasks xTaskCreateUniversal(drawLoop, /* Function to implement the task */ "drawLoop", /* Name of the task */ @@ -148,6 +176,7 @@ void Avatar::start(int colorDepth) { 2, /* Priority of the task */ NULL, /* Task handle. */ APP_CPU_NUM); +#endif } void Avatar::draw() { diff --git a/src/Avatar.h b/src/Avatar.h index c060899..52320a4 100644 --- a/src/Avatar.h +++ b/src/Avatar.h @@ -8,6 +8,18 @@ #include "Face.h" #include +#ifdef SDL_h_ +typedef SDL_ThreadFunction TaskFunction_t; +typedef int BaseType_t; +typedef unsigned int UBaseType_t; +typedef void* TaskHandle_t; +typedef int TaskResult_t; +#define APP_CPU_NUM (1) +#else +typedef void TaskResult_t; +#endif + + namespace m5avatar { class Avatar { private: diff --git a/src/BoundingRect.cpp b/src/BoundingRect.cpp index b4f42af..bc184fe 100644 --- a/src/BoundingRect.cpp +++ b/src/BoundingRect.cpp @@ -3,7 +3,6 @@ // license information. #include "BoundingRect.h" -#include namespace m5avatar { BoundingRect::BoundingRect(int16_t top, int16_t left) diff --git a/src/BoundingRect.h b/src/BoundingRect.h index 158b795..d0cfc66 100644 --- a/src/BoundingRect.h +++ b/src/BoundingRect.h @@ -4,7 +4,7 @@ #ifndef BOUNDINGRECT_H_ #define BOUNDINGRECT_H_ -#include +#include namespace m5avatar { class BoundingRect { diff --git a/src/ColorPalette.cpp b/src/ColorPalette.cpp index 8256f8e..7d5062e 100644 --- a/src/ColorPalette.cpp +++ b/src/ColorPalette.cpp @@ -19,7 +19,7 @@ uint16_t ColorPalette::get(const char* key) const { } else { // NOTE: if no value it returns BLACK(0x00) as the default value of the // type(int) - Serial.printf("no color with the key %s\n", key); + M5_LOGI("no color with the key %s", key); return TFT_BLACK; } } @@ -27,7 +27,7 @@ uint16_t ColorPalette::get(const char* key) const { void ColorPalette::set(const char* key, uint16_t value) { auto itr = colors.find(key); if (itr != colors.end()) { - Serial.println("Overwriting"); + M5_LOGI("Overwriting"); } itr->second = value; } diff --git a/src/Face.cpp b/src/Face.cpp index 44535f0..ac7f26a 100644 --- a/src/Face.cpp +++ b/src/Face.cpp @@ -4,6 +4,10 @@ #include "Face.h" +#ifndef _min +#define _min(a, b) std::min(a, b) +#endif + namespace m5avatar { BoundingRect br; @@ -144,7 +148,7 @@ void Face::draw(DrawContext *ctx) { tmpSprite->pushSprite(&M5.Display, boundingRect->getLeft(), boundingRect->getTop() + y); // DMA転送中にdelay処理を設けることにより、DMA転送中に他のタスクへCPU処理時間を譲ることができる。 - delay(1); + lgfx::delay(1); // endWriteによってDMA転送の終了を待つ。 M5.Display.endWrite(); diff --git a/src/Mouth.cpp b/src/Mouth.cpp index 9657e0e..bfe4852 100644 --- a/src/Mouth.cpp +++ b/src/Mouth.cpp @@ -4,6 +4,10 @@ #include "Mouth.h" +#ifndef _min +#define _min(a, b) std::min(a, b) +#endif + namespace m5avatar { Mouth::Mouth(uint16_t minWidth, uint16_t maxWidth, uint16_t minHeight, From f929c5c5b52f48f21d068ba20bfcf3f4bc2c1392 Mon Sep 17 00:00:00 2001 From: hollyhockberry <49336378+hollyhockberry@users.noreply.github.com> Date: Sat, 11 Nov 2023 22:48:24 +0900 Subject: [PATCH 13/25] Add native build example --- examples/PlatformIO_SDL/platformio.ini | 51 ++++++++++++++++++++++++ examples/PlatformIO_SDL/src/main.cpp | 28 +++++++++++++ examples/PlatformIO_SDL/src/sdl_main.cpp | 25 ++++++++++++ 3 files changed, 104 insertions(+) create mode 100644 examples/PlatformIO_SDL/platformio.ini create mode 100644 examples/PlatformIO_SDL/src/main.cpp create mode 100644 examples/PlatformIO_SDL/src/sdl_main.cpp diff --git a/examples/PlatformIO_SDL/platformio.ini b/examples/PlatformIO_SDL/platformio.ini new file mode 100644 index 0000000..8987df3 --- /dev/null +++ b/examples/PlatformIO_SDL/platformio.ini @@ -0,0 +1,51 @@ +; PlatformIO Project Configuration File +; +; Build options: build flags, source filter +; Upload options: custom upload port, speed and extra flags +; Library options: dependencies, extra library storages +; Advanced options: extra scripting +; +; Please visit documentation for the other options and examples +; https://docs.platformio.org/page/projectconf.html + +[platformio] +default_envs = native + +[env] +lib_extra_dirs=../../../ +lib_deps = https://github.com/m5stack/M5Unified + +[env:native] +platform = native +build_type = debug +build_flags = -O0 -xc++ -std=c++14 -lSDL2 + -I"/usr/local/include/SDL2" ; for intel mac homebrew SDL2 + -L"/usr/local/lib" ; for intel mac homebrew SDL2 + -I"${sysenv.HOMEBREW_PREFIX}/include/SDL2" ; for arm mac homebrew SDL2 + -L"${sysenv.HOMEBREW_PREFIX}/lib" ; for arm mac homebrew SDL2 + +[env:native_m5stack] +extends = native +platform = native +build_flags = ${env:native.build_flags} + -DM5GFX_BOARD=board_M5Stack + +[env:native_stickCPlus] +extends = native +platform = native +build_flags = ${env:native.build_flags} + -DM5GFX_SCALE=2 + -DM5GFX_ROTATION=0 + -DM5GFX_BOARD=board_M5StickCPlus + +[esp32_base] +build_type = debug +platform = espressif32 +board = esp32dev +upload_speed = 1500000 +monitor_speed = 115200 +monitor_filters = esp32_exception_decoder + +[env:esp32_arduino] +extends = esp32_base +framework = arduino diff --git a/examples/PlatformIO_SDL/src/main.cpp b/examples/PlatformIO_SDL/src/main.cpp new file mode 100644 index 0000000..84af199 --- /dev/null +++ b/examples/PlatformIO_SDL/src/main.cpp @@ -0,0 +1,28 @@ +#include +#include + +using namespace m5avatar; + +Avatar avatar; + +void setup() +{ + M5.begin(); + avatar.init(); // start drawing + + // adjust position + const auto r = avatar.getFace()->getBoundingRect(); + const auto scale_w = M5.Display.width() / (float)r->getWidth(); + const auto scale_h = M5.Display.height() / (float)r->getHeight(); + const auto scale = std::min(scale_w, scale_h); + avatar.setScale(scale); + const auto offs_x = (r->getWidth() - M5.Display.width()) / 2; + const auto offs_y = (r->getHeight() - M5.Display.height()) / 2; + avatar.setPosition(-offs_y, -offs_x); +} + +void loop() +{ + // avatar's face updates in another thread + // so no need to loop-by-loop rendering +} diff --git a/examples/PlatformIO_SDL/src/sdl_main.cpp b/examples/PlatformIO_SDL/src/sdl_main.cpp new file mode 100644 index 0000000..87abf61 --- /dev/null +++ b/examples/PlatformIO_SDL/src/sdl_main.cpp @@ -0,0 +1,25 @@ +#include +#if defined ( SDL_h_ ) + +void setup(void); +void loop(void); + +__attribute__((weak)) +int user_func(bool* running) +{ + setup(); + do + { + loop(); + } while (*running); + return 0; +} + +int main(int, char**) +{ + // The second argument is effective for step execution with breakpoints. + // You can specify the time in milliseconds to perform slow execution that ensures screen updates. + return lgfx::Panel_sdl::main(user_func, 128); +} + +#endif From 1420dc9961997a7df842fe91c6a8ee0bc3ef6772 Mon Sep 17 00:00:00 2001 From: hollyhockberry <49336378+hollyhockberry@users.noreply.github.com> Date: Sun, 12 Nov 2023 17:20:02 +0900 Subject: [PATCH 14/25] Add typedef for TaskHandle_t in native build --- src/Avatar.cpp | 8 ++++++-- src/Avatar.h | 2 +- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/Avatar.cpp b/src/Avatar.cpp index d4f4d0a..1984e3d 100644 --- a/src/Avatar.cpp +++ b/src/Avatar.cpp @@ -117,7 +117,11 @@ void Avatar::addTask(TaskFunction_t f , const BaseType_t core_id) { DriveContext *ctx = new DriveContext(this); #ifdef SDL_h_ - SDL_CreateThreadWithStackSize(f, name, stack_size, ctx); + if (task_handle == NULL) { + SDL_CreateThreadWithStackSize(f, name, stack_size, ctx); + } else { + *task_handle = SDL_CreateThreadWithStackSize(f, name, stack_size, ctx); + } #else // TODO(meganetaaan): set a task handler xTaskCreateUniversal(f, /* Function to implement the task */ @@ -157,7 +161,7 @@ void Avatar::start(int colorDepth) { this->colorDepth = colorDepth; DriveContext *ctx = new DriveContext(this); #ifdef SDL_h_ - SDL_CreateThreadWithStackSize(drawLoop, "drawLoop", 2048, ctx); + drawTaskHandle = SDL_CreateThreadWithStackSize(drawLoop, "drawLoop", 2048, ctx); SDL_CreateThreadWithStackSize(facialLoop, "facialLoop", 1024, ctx); #else // TODO(meganetaaan): keep handle of these tasks diff --git a/src/Avatar.h b/src/Avatar.h index 52320a4..733cc86 100644 --- a/src/Avatar.h +++ b/src/Avatar.h @@ -12,7 +12,7 @@ typedef SDL_ThreadFunction TaskFunction_t; typedef int BaseType_t; typedef unsigned int UBaseType_t; -typedef void* TaskHandle_t; +typedef SDL_Thread* TaskHandle_t; typedef int TaskResult_t; #define APP_CPU_NUM (1) #else From 2326638fde3bd3a129a825527f16cb93dfa87184 Mon Sep 17 00:00:00 2001 From: Takao Akaki Date: Sat, 18 Nov 2023 20:31:21 +0900 Subject: [PATCH 15/25] fix speechtext to string --- src/Avatar.cpp | 2 +- src/Avatar.h | 2 +- src/Balloon.h | 4 ++-- src/DrawContext.cpp | 6 +++--- src/DrawContext.h | 8 ++++---- 5 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/Avatar.cpp b/src/Avatar.cpp index 65527bb..15ea2f7 100644 --- a/src/Avatar.cpp +++ b/src/Avatar.cpp @@ -205,7 +205,7 @@ void Avatar::getGaze(float *vertical, float *horizontal) { } void Avatar::setSpeechText(const char *speechText) { - this->speechText = speechText; + this->speechText = String(speechText); } void Avatar::setSpeechFont(const lgfx::IFont *speechFont) { diff --git a/src/Avatar.h b/src/Avatar.h index c060899..69685e5 100644 --- a/src/Avatar.h +++ b/src/Avatar.h @@ -22,7 +22,7 @@ class Avatar { float rotation; float scale; ColorPalette palette; - const char *speechText; + String speechText; int colorDepth; BatteryIconStatus batteryIconStatus; int32_t batteryLevel; diff --git a/src/Balloon.h b/src/Balloon.h index a043de9..79a8de1 100644 --- a/src/Balloon.h +++ b/src/Balloon.h @@ -25,9 +25,9 @@ class Balloon final : public Drawable { Balloon &operator=(const Balloon &other) = default; void draw(M5Canvas *spi, BoundingRect rect, DrawContext *drawContext) override { - const char *text = drawContext->getspeechText(); + String text = drawContext->getspeechText(); const lgfx::IFont *font = drawContext->getSpeechFont(); - if (strlen(text) == 0) { + if (text.length() == 0) { return; } ColorPalette* cp = drawContext->getColorPalette(); diff --git a/src/DrawContext.cpp b/src/DrawContext.cpp index 72c30fe..528fd44 100644 --- a/src/DrawContext.cpp +++ b/src/DrawContext.cpp @@ -9,13 +9,13 @@ namespace m5avatar { DrawContext::DrawContext(Expression expression, float breath, ColorPalette* const palette, Gaze gaze, float eyeOpenRatio, float mouthOpenRatio, - const char* speechText, BatteryIconStatus batteryIcon, int32_t batteryLevel, const lgfx::IFont* speechFont) + String speechText, BatteryIconStatus batteryIcon, int32_t batteryLevel, const lgfx::IFont* speechFont) : DrawContext(expression, breath, palette, gaze, eyeOpenRatio, mouthOpenRatio, speechText, 0, 1, 1, BatteryIconStatus::invisible, 0, speechFont){}; DrawContext::DrawContext(Expression expression, float breath, ColorPalette* const palette, Gaze gaze, float eyeOpenRatio, float mouthOpenRatio, - const char* speechText, float rotation, float scale, int colorDepth, BatteryIconStatus batteryIconStatus, int32_t batteryLevel, const lgfx::IFont* speechFont) + String speechText, float rotation, float scale, int colorDepth, BatteryIconStatus batteryIconStatus, int32_t batteryLevel, const lgfx::IFont* speechFont) : expression{expression}, breath{breath}, eyeOpenRatio{eyeOpenRatio}, @@ -42,7 +42,7 @@ float DrawContext::getRotation() const { return rotation; } float DrawContext::getScale() const { return scale; } -const char* DrawContext::getspeechText() const { return speechText; } +String DrawContext::getspeechText() const { return speechText; } Gaze DrawContext::getGaze() const { return gaze; } diff --git a/src/DrawContext.h b/src/DrawContext.h index d0e6ee0..6b33628 100644 --- a/src/DrawContext.h +++ b/src/DrawContext.h @@ -23,7 +23,7 @@ class DrawContext { float mouthOpenRatio; Gaze gaze; ColorPalette * const palette; - const char* speechText; + String speechText; float rotation = 0.0; float scale = 1.0; int colorDepth = 1; @@ -35,10 +35,10 @@ class DrawContext { DrawContext() = delete; DrawContext(Expression expression, float breath, ColorPalette* const palette, Gaze gaze, float eyeOpenRatio, float mouthOpenRatio, - const char* speechText, BatteryIconStatus batteryIconStatus, int32_t batteryLevel, const lgfx::IFont* speechFont); + String speechText, BatteryIconStatus batteryIconStatus, int32_t batteryLevel, const lgfx::IFont* speechFont); DrawContext(Expression expression, float breath, ColorPalette* const palette, Gaze gaze, float eyeOpenRatio, float mouthOpenRatio, - const char* speechText, float rotation, float scale, int colorDepth, BatteryIconStatus batteryIconStatus, int32_t batteryLevel, const lgfx::IFont* speechFont); + String speechText, float rotation, float scale, int colorDepth, BatteryIconStatus batteryIconStatus, int32_t batteryLevel, const lgfx::IFont* speechFont); ~DrawContext() = default; DrawContext(const DrawContext& other) = delete; DrawContext& operator=(const DrawContext& other) = delete; @@ -50,7 +50,7 @@ class DrawContext { float getRotation() const; Gaze getGaze() const; ColorPalette* const getColorPalette() const; - const char* getspeechText() const; + String getspeechText() const; int getColorDepth() const; BatteryIconStatus getBatteryIconStatus() const; int32_t getBatteryLevel() const; From bb616cc1feb4267effdc9909513bde3bbae78a2a Mon Sep 17 00:00:00 2001 From: Takao Akaki Date: Sun, 19 Nov 2023 15:03:17 +0900 Subject: [PATCH 16/25] raise version to 0.9.1 --- library.json | 2 +- library.properties | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/library.json b/library.json index 11c30de..dd9b2cb 100644 --- a/library.json +++ b/library.json @@ -17,7 +17,7 @@ "license": "MIT", "dependencies": { }, - "version": "0.9.0", + "version": "0.9.1", "frameworks": "arduino", "platforms": "espressif32" } diff --git a/library.properties b/library.properties index d0eaf5b..38faa46 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=M5Stack_Avatar -version=0.9.0 +version=0.9.1 author=Shinya Ishikawa maintainer=Shinya Ishikawa sentence=Yet another avatar module for M5Stack From 3b7332eace1231ae6474f00de3538856f24ae98c Mon Sep 17 00:00:00 2001 From: Takao Akaki Date: Mon, 20 Nov 2023 16:11:02 +0900 Subject: [PATCH 17/25] fix BMPFace, OledFace --- src/faces/BMPFace.h | 8 ++------ src/faces/OledFace.h | 4 ++-- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/src/faces/BMPFace.h b/src/faces/BMPFace.h index 3773738..e0bc756 100644 --- a/src/faces/BMPFace.h +++ b/src/faces/BMPFace.h @@ -5,11 +5,7 @@ #ifndef FACES_BMPFACE_H_ #define FACES_BMPFACE_H_ -# if defined(ARDUINO_M5STACK_Core2) || defined(M5AVATAR_CORE2) || defined(_M5Core2_H_) - #include -# else - #include // TODO(meganetaaan): include only the Sprite function not a whole library -# endif +#include // TODO(meganetaaan): include only the Sprite function not a whole library #include "../BoundingRect.h" #include "../DrawContext.h" @@ -23,7 +19,7 @@ class BMPEye : public Drawable { void draw(M5Canvas *spi, BoundingRect rect, DrawContext *ctx) { - auto color = COLOR_DEPTH == 1 ? 1 : ctx->getColorPalette()->get(COLOR_PRIMARY); + uint16_t color = ctx->getColorDepth() == 1 ? 1 : ctx->getColorPalette()->get(COLOR_PRIMARY); uint16_t cx = rect.getCenterX(); uint16_t cy = rect.getCenterY(); float openRatio = ctx->getEyeOpenRatio(); diff --git a/src/faces/OledFace.h b/src/faces/OledFace.h index 5a6a7fe..10df93a 100644 --- a/src/faces/OledFace.h +++ b/src/faces/OledFace.h @@ -14,8 +14,8 @@ namespace m5avatar { class OledFace : public Face { public: OledFace() - : Face(new Mouth(), new BoundingRect(168, 163), new Eye(), - new BoundingRect(103, 80), new Eye(), + : Face(new Mouth(50, 90, 4, 60), new BoundingRect(168, 163), new Eye(8, false), + new BoundingRect(103, 80), new Eye(8, true), new BoundingRect(106, 240), new Eyeblow(15, 2, false), new BoundingRect(67, 96), new Eyeblow(15, 2, true), new BoundingRect(72, 230)) {} From 9400827753967eed074c4261459ef8cbcdfa0f20 Mon Sep 17 00:00:00 2001 From: hollyhockberry <49336378+hollyhockberry@users.noreply.github.com> Date: Thu, 14 Dec 2023 07:44:13 +0900 Subject: [PATCH 18/25] define APP_CPU_NUM --- src/Avatar.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Avatar.h b/src/Avatar.h index b918011..1ade521 100644 --- a/src/Avatar.h +++ b/src/Avatar.h @@ -14,6 +14,7 @@ typedef int BaseType_t; typedef unsigned int UBaseType_t; typedef SDL_Thread* TaskHandle_t; typedef int TaskResult_t; +#define APP_CPU_NUM (1) #else typedef void TaskResult_t; #endif From 5811bb69918994cde077256b9d8d9764a5df3a3b Mon Sep 17 00:00:00 2001 From: hollyhockberry <49336378+hollyhockberry@users.noreply.github.com> Date: Thu, 14 Dec 2023 19:57:36 +0900 Subject: [PATCH 19/25] typedef String in case of undefined ARDUINO --- src/Avatar.h | 5 +++++ src/Balloon.h | 9 +++++++-- src/DrawContext.h | 4 ++++ 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/Avatar.h b/src/Avatar.h index 1ade521..2453f8d 100644 --- a/src/Avatar.h +++ b/src/Avatar.h @@ -23,6 +23,11 @@ typedef void TaskResult_t; #define APP_CPU_NUM PRO_CPU_NUM #endif +#ifndef ARDUINO +#include +typedef std::string String; +#endif // ARDUINO + namespace m5avatar { class Avatar { private: diff --git a/src/Balloon.h b/src/Balloon.h index 79a8de1..478d9f4 100644 --- a/src/Balloon.h +++ b/src/Balloon.h @@ -9,6 +9,11 @@ #include "DrawContext.h" #include "Drawable.h" +#ifndef ARDUINO +#include +typedef std::string String; +#endif // ARDUINO + const int16_t TEXT_HEIGHT = 8; const int16_t TEXT_SIZE = 2; const int16_t MIN_WIDTH = 40; @@ -39,7 +44,7 @@ class Balloon final : public Drawable { spi->setTextColor(primaryColor, backgroundColor); spi->setTextDatum(MC_DATUM); M5.Lcd.setFont(font); - int textWidth = M5.Lcd.textWidth(text); + int textWidth = M5.Lcd.textWidth(text.c_str()); int textHeight = TEXT_HEIGHT * TEXT_SIZE; spi->fillEllipse(cx - 20, cy,textWidth + 2, textHeight * 2 + 2, primaryColor); @@ -49,7 +54,7 @@ class Balloon final : public Drawable { backgroundColor); spi->fillTriangle(cx - 60, cy - 40, cx - 10, cy - 10, cx - 40, cy - 10, backgroundColor); - spi->drawString(text, cx - textWidth / 6 - 15, cy, font); // Continue printing from new x position + spi->drawString(text.c_str(), cx - textWidth / 6 - 15, cy, font); // Continue printing from new x position } }; diff --git a/src/DrawContext.h b/src/DrawContext.h index 6b33628..0e831ae 100644 --- a/src/DrawContext.h +++ b/src/DrawContext.h @@ -12,6 +12,10 @@ #include "Expression.h" #include "Gaze.h" +#ifndef ARDUINO +#include +typedef std::string String; +#endif // ARDUINO namespace m5avatar { enum BatteryIconStatus { discharging, charging, invisible, unknown }; From 40409607af127624663447eb0e958714ce94835c Mon Sep 17 00:00:00 2001 From: hollyhockberry <49336378+hollyhockberry@users.noreply.github.com> Date: Thu, 14 Dec 2023 19:58:08 +0900 Subject: [PATCH 20/25] modify dependencies --- library.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library.json b/library.json index 957c7f2..fd12e70 100644 --- a/library.json +++ b/library.json @@ -18,7 +18,7 @@ "dependencies": [ { "name": "M5Unified", - "version": ">=0.1.10" + "version": ">=0.1.11" } ], "version": "0.9.1", From 0199e873e883b08ccd53b6159f6928ad3b295bf0 Mon Sep 17 00:00:00 2001 From: hollyhockberry <49336378+hollyhockberry@users.noreply.github.com> Date: Thu, 14 Dec 2023 19:58:49 +0900 Subject: [PATCH 21/25] updete lib_deps --- examples/PlatformIO_SDL/platformio.ini | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/examples/PlatformIO_SDL/platformio.ini b/examples/PlatformIO_SDL/platformio.ini index 8987df3..e0fedad 100644 --- a/examples/PlatformIO_SDL/platformio.ini +++ b/examples/PlatformIO_SDL/platformio.ini @@ -13,7 +13,9 @@ default_envs = native [env] lib_extra_dirs=../../../ -lib_deps = https://github.com/m5stack/M5Unified +lib_deps = + https://github.com/m5stack/M5GFX#develop ; Until 0.1.12 or later.. + m5stack/M5Unified@^0.1.11 [env:native] platform = native From 010f48d59e3f5694e49c8eec1b1430cf08369bf6 Mon Sep 17 00:00:00 2001 From: hollyhockberry <49336378+hollyhockberry@users.noreply.github.com> Date: Thu, 21 Dec 2023 19:45:42 +0900 Subject: [PATCH 22/25] Implement the constructor of Face --- src/Face.cpp | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/Face.cpp b/src/Face.cpp index ac7f26a..2524bd1 100644 --- a/src/Face.cpp +++ b/src/Face.cpp @@ -28,6 +28,16 @@ Face::Face(Drawable *mouth, BoundingRect *mouthPos, Drawable *eyeR, BoundingRect *eyeRPos, Drawable *eyeL, BoundingRect *eyeLPos, Drawable *eyeblowR, BoundingRect *eyeblowRPos, Drawable *eyeblowL, BoundingRect *eyeblowLPos) + : Face(mouth, mouthPos, eyeR, eyeRPos, eyeL, eyeLPos, eyeblowR, + eyeblowRPos, eyeblowL, eyeblowLPos, + new BoundingRect(0, 0, 320, 240), + new M5Canvas(&M5.Lcd), new M5Canvas(&M5.Lcd)) {} + +Face::Face(Drawable *mouth, BoundingRect *mouthPos, Drawable *eyeR, + BoundingRect *eyeRPos, Drawable *eyeL, BoundingRect *eyeLPos, + Drawable *eyeblowR, BoundingRect *eyeblowRPos, Drawable *eyeblowL, + BoundingRect *eyeblowLPos, + BoundingRect *boundingRect, M5Canvas *spr, M5Canvas *tmpSpr) : mouth{mouth}, eyeR{eyeR}, eyeL{eyeL}, @@ -38,9 +48,9 @@ Face::Face(Drawable *mouth, BoundingRect *mouthPos, Drawable *eyeR, eyeLPos{eyeLPos}, eyeblowRPos{eyeblowRPos}, eyeblowLPos{eyeblowLPos}, - boundingRect{new BoundingRect(0, 0, 320, 240)}, - sprite{new M5Canvas(&M5.Lcd)}, - tmpSprite{new M5Canvas(&M5.Lcd)} {} + boundingRect{boundingRect}, + sprite{spr}, + tmpSprite{tmpSpr} {} Face::~Face() { delete mouth; From 7cca4b0e2effb190a4957a3b2d7c2a6c570fe87b Mon Sep 17 00:00:00 2001 From: hollyhockberry <49336378+hollyhockberry@users.noreply.github.com> Date: Sun, 24 Dec 2023 23:04:00 +0900 Subject: [PATCH 23/25] Call rand() if rand_r() is not available --- src/Avatar.cpp | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/Avatar.cpp b/src/Avatar.cpp index 07e3b26..4e98a45 100644 --- a/src/Avatar.cpp +++ b/src/Avatar.cpp @@ -12,6 +12,14 @@ namespace m5avatar { unsigned int seed = 0; +#ifndef rand_r +#define init_rand() srand(seed) +#define _rand() rand() +#else +#define init_rand() ; +#define _rand() rand_r(&seed) +#endif + #ifdef SDL_h_ #define TaskResult() return 0 #define TaskDelay(ms) lgfx::delay(ms) @@ -54,11 +62,12 @@ TaskResult_t facialLoop(void *args) { float vertical = 0.0f; float horizontal = 0.0f; float breath = 0.0f; + init_rand(); while (avatar->isDrawing()) { if ((lgfx::millis() - last_saccade_millis) > saccade_interval) { - vertical = rand_r(&seed) / (RAND_MAX / 2.0) - 1; - horizontal = rand_r(&seed) / (RAND_MAX / 2.0) - 1; + vertical = _rand() / (RAND_MAX / 2.0) - 1; + horizontal = _rand() / (RAND_MAX / 2.0) - 1; avatar->setGaze(vertical, horizontal); saccade_interval = 500 + 100 * random(20); last_saccade_millis = lgfx::millis(); From cdf6ab89e8afb22520f205c1a2984e2f0d5a4412 Mon Sep 17 00:00:00 2001 From: hollyhockberry <49336378+hollyhockberry@users.noreply.github.com> Date: Fri, 29 Dec 2023 21:19:09 +0900 Subject: [PATCH 24/25] Update platformio.ini --- examples/PlatformIO_SDL/platformio.ini | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/examples/PlatformIO_SDL/platformio.ini b/examples/PlatformIO_SDL/platformio.ini index e0fedad..c939b62 100644 --- a/examples/PlatformIO_SDL/platformio.ini +++ b/examples/PlatformIO_SDL/platformio.ini @@ -13,9 +13,7 @@ default_envs = native [env] lib_extra_dirs=../../../ -lib_deps = - https://github.com/m5stack/M5GFX#develop ; Until 0.1.12 or later.. - m5stack/M5Unified@^0.1.11 +lib_deps = m5stack/M5Unified@^0.1.11 [env:native] platform = native From 96fa7873aa3af312934b1099410d98c57c5ad45e Mon Sep 17 00:00:00 2001 From: Takao Akaki Date: Sat, 6 Jan 2024 16:59:47 +0900 Subject: [PATCH 25/25] Raise Version 0.9.2 --- library.json | 2 +- library.properties | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/library.json b/library.json index fd12e70..fcc9f61 100644 --- a/library.json +++ b/library.json @@ -21,7 +21,7 @@ "version": ">=0.1.11" } ], - "version": "0.9.1", + "version": "0.9.2", "frameworks": ["arduino", "espidf", "*"], "platforms": ["espressif32", "native"] } diff --git a/library.properties b/library.properties index 6617154..a79e8b1 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=M5Stack_Avatar -version=0.9.1 +version=0.9.2 author=Shinya Ishikawa maintainer=Shinya Ishikawa sentence=Yet another avatar module for M5Stack