Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Robey Pointer
reform
Commits
9b85bfc2
Commit
9b85bfc2
authored
Aug 23, 2021
by
Robey Pointer
Browse files
add back the low battery check
parent
af976ea2
Changes
1
Hide whitespace changes
Inline
Side-by-side
reform2-keyboard-fw/keyboard.c
View file @
9b85bfc2
...
...
@@ -55,6 +55,12 @@
#define KBD_VARIANT_QWERTY_US
//#define KBD_VARIANT_NEO2
// check for a low battery every 30 seconds
#define BATTERY_CHECK_MSEC 30000
// how long should the on/off cycle of the low battery alert be
#define BATTERY_ALERT_ON_MSEC 500
#define BATTERY_ALERT_OFF_MSEC 4500
/** Buffer to hold the previously generated Keyboard HID report, for comparison purposes inside the HID class driver. */
static
uint8_t
PrevKeyboardHIDReportBuffer
[
sizeof
(
USB_KeyboardReport_Data_t
)];
...
...
@@ -105,22 +111,9 @@ uint8_t matrix[MATRIX_ROWS * MATRIX_COLUMNS] = {
static
uint8_t
state
[
MATRIX_BYTES
]
=
{
0
,
};
// f8 = sleep
// 49 = mute
// 84 = scroll lock
int
low_battery_alert
=
0
;
static
void
remote_check_for_low_battery
(
void
)
{
int
was_low
=
low_battery_alert
;
low_battery_alert
=
controller_battery_is_low
();
if
(
was_low
&&
!
low_battery_alert
)
{
display_clear
();
display_flush
();
}
}
#ifndef KBD_VARIANT_STANDALONE
static
bool
low_battery
=
false
;
#endif
volatile
static
uint32_t
timer_tick
=
0
;
...
...
@@ -178,8 +171,7 @@ void kbd_brightness_set(uint8_t brite) {
}
static
void
local_test
(
void
)
{
// low_battery_alert = !low_battery_alert;
// display_refresh();
low_battery
=
!
low_battery
;
}
#ifdef KBD_VARIANT_STANDALONE
...
...
@@ -324,15 +316,6 @@ static uint8_t scan_keyboard(uint8_t keys[]) {
}
void
process_alerts
(
void
)
{
static
int
blink
=
0
;
if
(
low_battery_alert
)
{
ux_blink_low_battery
(
blink
);
}
blink
=
1
-
blink
;
}
int
main
(
void
)
{
#ifdef KBD_VARIANT_QWERTY_US
matrix
[
4
*
MATRIX_COLUMNS
+
1
]
=
KEY_DELETE
;
...
...
@@ -369,6 +352,10 @@ int main(void) {
scan_keyboard_matrix
();
}
#ifndef KBD_VARIANT_STANDALONE
uint32_t
last_battery_check
=
0
,
last_low_battery_blink
=
0
;
bool
low_battery_alert_active
=
false
;
#endif
while
(
true
)
{
// do our own (non-usb) scan, too, so we can handle the circle menu
// when the laptop is off :)
...
...
@@ -384,15 +371,30 @@ int main(void) {
while
((
timer_tick
&
31
)
!=
0
)
sleep_mode
();
#ifndef KBD_VARIANT_STANDALONE
#if 0
if (counter >= 30000) {
remote_check_for_low_battery();
counter = 0;
uint32_t
now
=
timer_get_ticks
();
if
(
timer_diff_msec
(
last_battery_check
,
now
)
>=
BATTERY_CHECK_MSEC
)
{
last_battery_check
=
now
;
int
was_low
=
low_battery
;
low_battery
=
controller_battery_is_low
();
if
(
was_low
&&
!
low_battery
)
{
low_battery_alert_active
=
false
;
ux_blink_low_battery
(
false
);
}
}
if (counter % 3000 == 0) {
process_alerts();
if
(
low_battery
)
{
if
(
low_battery_alert_active
&&
timer_diff_msec
(
last_low_battery_blink
,
now
)
>=
BATTERY_ALERT_ON_MSEC
)
{
low_battery_alert_active
=
false
;
last_low_battery_blink
=
now
;
ux_blink_low_battery
(
false
);
}
if
(
!
low_battery_alert_active
&&
timer_diff_msec
(
last_low_battery_blink
,
now
)
>=
BATTERY_ALERT_OFF_MSEC
)
{
low_battery_alert_active
=
true
;
last_low_battery_blink
=
now
;
ux_blink_low_battery
(
true
);
}
}
#endif
#endif
}
}
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment