Skip to content

Commit 4541888

Browse files
committed
Deal with freezing issue in models without PSRAM
1 parent c180e66 commit 4541888

4 files changed

Lines changed: 24 additions & 11 deletions

File tree

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: 2 additions & 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;
@@ -61,6 +61,7 @@ class Avatar {
6161
void resume();
6262
void setBatteryIcon(bool iconStatus);
6363
void setBatteryStatus(bool isCharging, int32_t batteryLevel);
64+
void resetDraw();
6465
};
6566

6667

src/Face.cpp

Lines changed: 6 additions & 6 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

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)