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 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..da46c3c 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; diff --git a/src/Face.cpp b/src/Face.cpp index 28ba24b..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 @@ -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) { 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