Skip to content

Commit

Permalink
Merge pull request #86 from meganetaaan/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
mongonta0716 committed Aug 7, 2023
2 parents 2c4bf13 + e0c4e09 commit 211bb58
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 14 deletions.
2 changes: 1 addition & 1 deletion library.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"license": "MIT",
"dependencies": {
},
"version": "0.8.5",
"version": "0.8.6",
"frameworks": "arduino",
"platforms": "espressif32"
}
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name=M5Stack_Avatar
version=0.8.5
version=0.8.6
author=Shinya Ishikawa
maintainer=Shinya Ishikawa<[email protected]>
sentence=Yet another avatar module for M5Stack
Expand Down
17 changes: 13 additions & 4 deletions src/Avatar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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);
Expand All @@ -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; }
Expand Down Expand Up @@ -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() {
Expand Down
2 changes: 1 addition & 1 deletion src/Avatar.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
14 changes: 7 additions & 7 deletions src/Face.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@
#include "Face.h"

namespace m5avatar {
Balloon b;
Effect h;
BatteryIcon battery;
BoundingRect br;

Face::Face()
Expand Down Expand Up @@ -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; }
Expand Down Expand Up @@ -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
Expand All @@ -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) {
Expand Down
3 changes: 3 additions & 0 deletions src/Face.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ class Face {
BoundingRect *boundingRect;
M5Canvas *sprite;
M5Canvas *tmpSprite;
Balloon *b;
Effect *h;
BatteryIcon *battery;

public:
// constructor
Expand Down

0 comments on commit 211bb58

Please sign in to comment.