m5stack-avatar
Loading...
Searching...
No Matches
Avatar.h
1// Copyright (c) Shinya Ishikawa. All rights reserved.
2// Licensed under the MIT license. See LICENSE file in the project root for full
3// license information.
4
5#ifndef AVATAR_H_
6#define AVATAR_H_
7#include <M5GFX.h>
8
9#include "ColorPalette.h"
10#include "Face.h"
11
12#ifdef SDL_h_
13typedef SDL_ThreadFunction TaskFunction_t;
14typedef int BaseType_t;
15typedef unsigned int UBaseType_t;
16typedef SDL_Thread *TaskHandle_t;
17typedef int TaskResult_t;
18#define APP_CPU_NUM (1)
19#else
20typedef void TaskResult_t;
21#endif
22
23#ifndef APP_CPU_NUM
24#define APP_CPU_NUM PRO_CPU_NUM
25#endif
26
27#ifndef ARDUINO
28#include <string>
29typedef std::string String;
30#endif // ARDUINO
31
32namespace m5avatar {
33class Avatar {
34 private:
35 Face *face;
36 bool _isDrawing;
37 Expression expression;
38 float breath;
39
40 // eyes variables
41 float rightEyeOpenRatio_;
42 float rightGazeV_;
43 float rightGazeH_;
44
45 float leftEyeOpenRatio_;
46 float leftGazeV_;
47 float leftGazeH_;
48
49 bool isAutoBlink_;
50
51 float mouthOpenRatio;
52
53 float rotation;
54 float scale;
55 ColorPalette palette;
56 String speechText;
57 int colorDepth;
58 BatteryIconStatus batteryIconStatus;
59 int32_t batteryLevel;
60 const lgfx::IFont *speechFont;
61 bool runing_in_x_task_;
62
63 public:
64 Avatar();
65 explicit Avatar(Face *face);
66 ~Avatar();
67 Avatar(const Avatar &other) = default;
68 Avatar &operator=(const Avatar &other) = default;
69 Face *getFace() const;
70 ColorPalette getColorPalette() const;
71 void setColorPalette(ColorPalette cp);
72 void setFace(Face *face);
73 void init(int colorDepth = 1);
74 // expression i/o
75 Expression getExpression();
76 void setExpression(Expression exp);
77 // breath i/o
78 void setBreath(float f);
79 float getBreath();
80 // gaze i/o
81 void setRightGaze(float vertical, float horizontal);
82 void getRightGaze(float *vertical, float *horizontal);
83 void setLeftGaze(float vertical, float horizontal);
84 void getLeftGaze(float *vertical, float *horizontal);
85
97 void getGaze(float *vertical, float *horizontal);
98
99 // eyes open ratio
100 void setEyeOpenRatio(float ratio);
101 void setRightEyeOpenRatio(float ratio);
102 float getRightEyeOpenRatio();
103 void setLeftEyeOpenRatio(float ratio);
104 float getLeftEyeOpenRatio();
105 void setIsAutoBlink(bool b);
106 bool getIsAutoBlink();
107
108 void setMouthOpenRatio(float ratio);
109 void setSpeechText(const char *speechText);
110 void setSpeechFont(const lgfx::IFont *speechFont);
111 void setRotation(float radian);
112 void setPosition(int top, int left);
113 void setScale(float scale);
114 void setColorDepth(int color_depth = 1);
115 void draw(void);
116 bool isDrawing();
117 void start(int colorDepth = 1);
118 void stop();
119 void addTask(TaskFunction_t f, const char *name,
120 const uint32_t stack_size = 2048, UBaseType_t priority = 4,
121 TaskHandle_t *const task_handle = NULL,
122 const BaseType_t core_id = APP_CPU_NUM);
123 void suspend();
124 void resume();
125 void update();
126 void updateFacialParameters();
127 void setBatteryIcon(bool iconStatus);
128 void setBatteryStatus(bool isCharging, int32_t batteryLevel);
129};
130
132 private:
133 // TODO(meganetaaan): cyclic reference
134 Avatar *avatar;
135
136 public:
137 DriveContext() = delete;
138 explicit DriveContext(Avatar *avatar);
139 ~DriveContext() = default;
140 DriveContext(const DriveContext &other) = delete;
141 DriveContext &operator=(const DriveContext &other) = delete;
142 Avatar *getAvatar();
143};
144
145} // namespace m5avatar
146
147#endif // AVATAR_H_
Definition: Avatar.h:33
void update()
update drawings in the display and facial parameters
Definition: Avatar.cpp:160
void getGaze(float *vertical, float *horizontal)
Get the Gaze of Avatar.
Definition: Avatar.cpp:340
Definition: ColorPalette.h:50
Definition: Avatar.h:131
Definition: Face.h:18