Skip to content

Commit 211bb58

Browse files
authored
Merge pull request #86 from meganetaaan/develop
Develop
2 parents 2c4bf13 + e0c4e09 commit 211bb58

6 files changed

Lines changed: 26 additions & 14 deletions

File tree

library.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
"license": "MIT",
1818
"dependencies": {
1919
},
20-
"version": "0.8.5",
20+
"version": "0.8.6",
2121
"frameworks": "arduino",
2222
"platforms": "espressif32"
2323
}

library.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name=M5Stack_Avatar
2-
version=0.8.5
2+
version=0.8.6
33
author=Shinya Ishikawa
44
maintainer=Shinya Ishikawa<ishikawa.s.1027@gmail.com>
55
sentence=Yet another avatar module for M5Stack

src/Avatar.cpp

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,14 @@ void facialLoop(void *args) {
3636
unsigned long last_saccade_millis = 0;
3737
unsigned long last_blink_millis = 0;
3838
bool eye_open = true;
39+
float vertical = 0.0f;
40+
float horizontal = 0.0f;
41+
float breath = 0.0f;
3942
while (avatar->isDrawing()) {
4043

4144
if ((millis() - last_saccade_millis) > saccade_interval) {
42-
float vertical = rand_r(&seed) / (RAND_MAX / 2.0) - 1;
43-
float horizontal = rand_r(&seed) / (RAND_MAX / 2.0) - 1;
45+
vertical = rand_r(&seed) / (RAND_MAX / 2.0) - 1;
46+
horizontal = rand_r(&seed) / (RAND_MAX / 2.0) - 1;
4447
avatar->setGaze(vertical, horizontal);
4548
saccade_interval = 500 + 100 * random(20);
4649
last_saccade_millis = millis();
@@ -58,8 +61,8 @@ void facialLoop(void *args) {
5861
last_blink_millis = millis();
5962
}
6063
c = (c + 1) % 100;
61-
float f = sin(c * 2 * PI / 100.0);
62-
avatar->setBreath(f);
64+
breath = sin(c * 2 * PI / 100.0);
65+
avatar->setBreath(breath);
6366
vTaskDelay(33);
6467
}
6568
vTaskDelete(NULL);
@@ -83,6 +86,10 @@ Avatar::Avatar(Face *face)
8386
colorDepth{1},
8487
batteryIconStatus{BatteryIconStatus::invisible}{}
8588

89+
Avatar::~Avatar() {
90+
delete face;
91+
}
92+
8693
void Avatar::setFace(Face *face) { this->face = face; }
8794

8895
Face *Avatar::getFace() const { return face; }
@@ -159,7 +166,9 @@ void Avatar::draw() {
159166
bool Avatar::isDrawing() { return _isDrawing; }
160167

161168
void Avatar::setExpression(Expression expression) {
169+
suspend();
162170
this->expression = expression;
171+
resume();
163172
}
164173

165174
Expression Avatar::getExpression() {

src/Avatar.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class Avatar {
3131
public:
3232
Avatar();
3333
explicit Avatar(Face *face);
34-
~Avatar() = default;
34+
~Avatar();
3535
Avatar(const Avatar &other) = default;
3636
Avatar &operator=(const Avatar &other) = default;
3737
Face *getFace() const;

src/Face.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,6 @@
55
#include "Face.h"
66

77
namespace m5avatar {
8-
Balloon b;
9-
Effect h;
10-
BatteryIcon battery;
118
BoundingRect br;
129

1310
Face::Face()
@@ -54,6 +51,9 @@ Face::~Face() {
5451
delete eyeblowLPos;
5552
delete sprite;
5653
delete boundingRect;
54+
delete b;
55+
delete h;
56+
delete battery;
5757
}
5858

5959
void Face::setMouth(Drawable *mouth) { this->mouth = mouth; }
@@ -106,9 +106,9 @@ void Face::draw(DrawContext *ctx) {
106106
eyeblowL->draw(sprite, rect, ctx);
107107

108108
// TODO(meganetaaan): make balloons and effects selectable
109-
b.draw(sprite, br, ctx);
110-
h.draw(sprite, br, ctx);
111-
battery.draw(sprite, br, ctx);
109+
b->draw(sprite, br, ctx);
110+
h->draw(sprite, br, ctx);
111+
battery->draw(sprite, br, ctx);
112112
// drawAccessory(sprite, position, ctx);
113113

114114
// TODO(meganetaaan): rethink responsibility for transform function
@@ -117,7 +117,7 @@ void Face::draw(DrawContext *ctx) {
117117

118118
if (scale != 1.0 || rotation != 0) {
119119
tmpSprite->setColorDepth(ctx->getColorDepth());
120-
tmpSprite->createSprite((int32_t)((float)M5.Display.width() * scale), (int32_t)((float)M5.Display.height() * scale));
120+
tmpSprite->createSprite((int32_t)((float)320 * scale), (int32_t)((float)240 * scale));
121121
tmpSprite->setBitmapColor(ctx->getColorPalette()->get(COLOR_PRIMARY),
122122
ctx->getColorPalette()->get(COLOR_BACKGROUND));
123123
if (ctx->getColorDepth() != 1) {

src/Face.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ class Face {
3030
BoundingRect *boundingRect;
3131
M5Canvas *sprite;
3232
M5Canvas *tmpSprite;
33+
Balloon *b;
34+
Effect *h;
35+
BatteryIcon *battery;
3336

3437
public:
3538
// constructor

0 commit comments

Comments
 (0)