Skip to content

Commit 2979bcc

Browse files
committed
'Battery Report' when turned on if there is a difference of 3 percent
1 parent 1fc5210 commit 2979bcc

File tree

1 file changed

+34
-8
lines changed

1 file changed

+34
-8
lines changed

hardware/arduino/zunoG2/cores/ZWSupport/ZWCCBattery.c

Lines changed: 34 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@
22
#include "ZWSupport.h"
33
#include "Debug.h"
44

5+
static uint8_t _batteryLevel = 0x0;
6+
7+
static bool _zunoSendBatteryReportHandler(bool report_test);
58
void zuno_CCBattery_OnSetup(){
6-
if (zunoIsSleepingMode() == false)
7-
return ;
8-
zunoSendBatteryReport();
9+
_zunoSendBatteryReportHandler(true);
910
}
1011

1112

@@ -53,13 +54,32 @@ static uint8_t _ZunoBattery(bool async, ZunoBattery_t *out) {
5354
return (batteryLevel);
5455
}
5556

56-
static void _battery_report_common(bool async, ZUNOCommandPacketReport_t *frame) {
57+
static bool _battery_report_common_test_send(bool report_test, uint8_t batteryLevel) {
58+
uint8_t old;
59+
uint8_t hysteresis;
60+
61+
if (report_test == false || batteryLevel == 0x0)
62+
return (true);
63+
old = _batteryLevel;
64+
if (old > batteryLevel)
65+
hysteresis = old - batteryLevel;
66+
else
67+
hysteresis = batteryLevel - old;
68+
if (hysteresis >= 0x3)
69+
return (true);
70+
return (false);
71+
}
72+
73+
static bool _battery_report_common(bool async, bool report_test, ZUNOCommandPacketReport_t *frame) {
5774
ZwBatteryReportFrame_t *report;
5875
ZunoBattery_t out;
5976
uint8_t batteryLevel;
6077
uint8_t properties1;
6178

6279
batteryLevel = _ZunoBattery(async, &out);
80+
if (_battery_report_common_test_send(report_test, batteryLevel) == false)
81+
return (false);
82+
_batteryLevel = batteryLevel;
6383
#ifdef LOGGING_DBG
6484
LOGGING_UART.print("*** Battery report: ");
6585
LOGGING_UART.println(batteryLevel);
@@ -78,22 +98,28 @@ static void _battery_report_common(bool async, ZUNOCommandPacketReport_t *frame)
7898
report->properties1 = properties1;
7999
report->properties2 = 0x0;
80100
frame->info.packet.len = sizeof(report[0x0]);
101+
return (true);
81102
}
82103

83-
bool zunoSendBatteryReportHandler() {
104+
static bool _zunoSendBatteryReportHandler(bool report_test) {
84105
ZUNOCommandPacketReport_t frame;
85106

86107
if (zunoIsSleepingMode() == false)
87108
return (false);
88109
fillOutgoingReportPacketAsync(&frame, 0x0);
89-
_battery_report_common(true, &frame);
110+
if (_battery_report_common(true, report_test, &frame) == false)
111+
return (false);
90112
zunoSendZWPackageAdd(&frame);
91-
return true;
113+
return (true);
114+
}
115+
116+
bool zunoSendBatteryReportHandler() {
117+
return _zunoSendBatteryReportHandler(false);
92118
}
93119

94120
static int _battery_report(ZUNOCommandPacketReport_t *frame_report) {
95121
_zunoMarkSystemClassRequested(SYSREQUEST_MAP_BATTERY_BIT);
96-
_battery_report_common(false, frame_report);
122+
_battery_report_common(false, false, frame_report);
97123
return (ZUNO_COMMAND_ANSWERED);
98124
}
99125

0 commit comments

Comments
 (0)