@@ -79,7 +79,8 @@ Avatar::Avatar(Face *face)
7979 scale{1 },
8080 palette{ColorPalette ()},
8181 speechText{" " },
82- colorDepth{1 }{}
82+ colorDepth{1 },
83+ batteryIconStatus{BatteryIconStatus::invisible}{}
8384
8485void Avatar::setFace (Face *face) { this ->face = face; }
8586
@@ -154,18 +155,6 @@ void Avatar::start(int colorDepth) {
154155
155156void Avatar::draw () {
156157 Gaze g = Gaze (this ->gazeV , this ->gazeH );
157- if (power != nullptr ) {
158- if ((millis () - last_power_display_time) > 3000 ) {
159- // バッテリー残量の更新は3秒に一度
160- if (power->isCharging ()) {
161- this ->batteryIconStatus = BatteryIconStatus::isCharging;
162- } else {
163- this ->batteryIconStatus = BatteryIconStatus::disCharge;
164- }
165- this ->batteryLevel = power->getBatteryLevel ();
166- last_power_display_time = millis ();
167- }
168- }
169158 DrawContext *ctx = new DrawContext (this ->expression , this ->breath ,
170159 &this ->palette , g, this ->eyeOpenRatio ,
171160 this ->mouthOpenRatio , this ->speechText ,
@@ -224,15 +213,24 @@ void Avatar::setSpeechFont(const lgfx::IFont *speechFont) {
224213 this ->speechFont = speechFont;
225214}
226215
227- void Avatar::setM5PowerClass (m5::Power_Class* power) {
228- this ->power = power;
229- if (power->isCharging ()) {
230- this ->batteryIconStatus = BatteryIconStatus::isCharging;
216+ void Avatar::setBatteryIcon (bool batteryIcon) {
217+ if (!batteryIcon) {
218+ batteryIconStatus = BatteryIconStatus::invisible;
231219 } else {
232- this -> batteryIconStatus = BatteryIconStatus::disCharge ;
220+ batteryIconStatus = BatteryIconStatus::unknown ;
233221 }
234- this ->batteryLevel = power->getBatteryLevel ();
235- this ->last_power_display_time = millis ();
222+ }
223+
224+ void Avatar::setBatteryStatus (bool isCharging, int32_t batteryLevel) {
225+ if (this ->batteryIconStatus != BatteryIconStatus::invisible) {
226+ if (isCharging) {
227+ this ->batteryIconStatus = BatteryIconStatus::charging;
228+ } else {
229+ this ->batteryIconStatus = BatteryIconStatus::discharging;
230+ }
231+ this ->batteryLevel = batteryLevel;
232+ }
233+
236234}
237235
238236} // namespace m5avatar
0 commit comments