2
2
#include "ZWSupport.h"
3
3
#include "Debug.h"
4
4
5
+ static uint8_t _batteryLevel = 0x0 ;
6
+
7
+ static bool _zunoSendBatteryReportHandler (bool report_test );
5
8
void zuno_CCBattery_OnSetup (){
6
- if (zunoIsSleepingMode () == false)
7
- return ;
8
- zunoSendBatteryReport ();
9
+ _zunoSendBatteryReportHandler (true);
9
10
}
10
11
11
12
@@ -53,13 +54,32 @@ static uint8_t _ZunoBattery(bool async, ZunoBattery_t *out) {
53
54
return (batteryLevel );
54
55
}
55
56
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 ) {
57
74
ZwBatteryReportFrame_t * report ;
58
75
ZunoBattery_t out ;
59
76
uint8_t batteryLevel ;
60
77
uint8_t properties1 ;
61
78
62
79
batteryLevel = _ZunoBattery (async , & out );
80
+ if (_battery_report_common_test_send (report_test , batteryLevel ) == false)
81
+ return (false);
82
+ _batteryLevel = batteryLevel ;
63
83
#ifdef LOGGING_DBG
64
84
LOGGING_UART .print ("*** Battery report: " );
65
85
LOGGING_UART .println (batteryLevel );
@@ -78,22 +98,28 @@ static void _battery_report_common(bool async, ZUNOCommandPacketReport_t *frame)
78
98
report -> properties1 = properties1 ;
79
99
report -> properties2 = 0x0 ;
80
100
frame -> info .packet .len = sizeof (report [0x0 ]);
101
+ return (true);
81
102
}
82
103
83
- bool zunoSendBatteryReportHandler ( ) {
104
+ static bool _zunoSendBatteryReportHandler ( bool report_test ) {
84
105
ZUNOCommandPacketReport_t frame ;
85
106
86
107
if (zunoIsSleepingMode () == false)
87
108
return (false);
88
109
fillOutgoingReportPacketAsync (& frame , 0x0 );
89
- _battery_report_common (true, & frame );
110
+ if (_battery_report_common (true, report_test , & frame ) == false)
111
+ return (false);
90
112
zunoSendZWPackageAdd (& frame );
91
- return true;
113
+ return (true);
114
+ }
115
+
116
+ bool zunoSendBatteryReportHandler () {
117
+ return _zunoSendBatteryReportHandler (false);
92
118
}
93
119
94
120
static int _battery_report (ZUNOCommandPacketReport_t * frame_report ) {
95
121
_zunoMarkSystemClassRequested (SYSREQUEST_MAP_BATTERY_BIT );
96
- _battery_report_common (false, frame_report );
122
+ _battery_report_common (false, false, frame_report );
97
123
return (ZUNO_COMMAND_ANSWERED );
98
124
}
99
125
0 commit comments