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
dbf4ccbc
Commit
dbf4ccbc
authored
Aug 18, 2021
by
Robey Pointer
Browse files
move the remaining remote_* functions into the controller module
parent
bd75e743
Changes
3
Hide whitespace changes
Inline
Side-by-side
reform2-keyboard-fw/Keyboard.c
View file @
dbf4ccbc
...
...
@@ -102,35 +102,11 @@ uint8_t matrix[MATRIX_ROWS * MATRIX_COLUMNS] = {
// 49 = mute
// 84 = scroll lock
char
r_inbuf
[
10
];
void
empty_serial
(
void
)
{
int
clock
=
0
;
while
(
Serial_ReceiveByte
()
>=
0
&&
clock
<
100
)
{
// flush serial
clock
++
;
}
}
int
term_x
=
0
;
int
term_y
=
0
;
int
low_battery_alert
=
0
;
static
void
remote_check_for_low_battery
(
void
)
{
battery_info_t
info
;
controller_probe_batteries
(
&
info
);
int
was_low
=
low_battery_alert
;
for
(
int
i
=
0
;
i
<
8
;
i
++
)
{
if
(
info
.
decivolts
[
i
]
<
30
)
{
low_battery_alert
=
1
;
}
}
if
(
info
.
total_percent
>
0
&&
info
.
total_percent
<
10
)
{
low_battery_alert
=
1
;
}
low_battery_alert
=
controller_battery_is_low
();
if
(
was_low
&&
!
low_battery_alert
)
{
display_clear
();
display_flush
();
...
...
@@ -138,118 +114,40 @@ static void remote_check_for_low_battery(void) {
}
int
16
_t
pwmval
=
8
;
u
int
8
_t
pwmval
=
8
;
void
kbd_brightness_init
(
void
)
{
// initial brightness
OCR0A
=
pwmval
;
// clear/set, WGM1:0 set (Phase correct PWM)
TCCR0A
=
(
1
<<
7
)
|
(
0
<<
6
)
|
(
0
<<
1
)
|
1
;
TCCR0A
=
(
1
<<
7
)
|
(
0
<<
6
)
|
(
0
<<
1
)
|
1
;
// 3=WGM02, (cs02 2:0 -> clock/
256
=
1
00)
TCCR0B
=
/*(1 << 3) |*/
(
1
<<
0
)
|
(
0
<<
1
)
|
1
;
// 3=WGM02, (cs02 2:0 -> clock/
1
= 00
1
)
TCCR0B
=
/*(1 << 3) |*/
(
0
<<
2
)
|
(
0
<<
1
)
|
1
;
}
void
kbd_brightness_inc
(
void
)
{
pwmval
+=
2
;
if
(
pwmval
>=
10
)
pwmval
=
10
;
if
(
pwmval
<
9
)
pwmval
+=
2
;
OCR0A
=
pwmval
;
}
void
kbd_brightness_dec
(
void
)
{
pwmval
-=
2
;
if
(
pwmval
<
0
)
pwmval
=
0
;
if
(
pwmval
>
1
)
pwmval
-=
2
;
OCR0A
=
pwmval
;
}
void
kbd_brightness_set
(
int
brite
)
{
pwmval
=
brite
;
if
(
pwmval
<
0
)
pwmval
=
0
;
if
(
pwmval
>=
10
)
pwmval
=
10
;
void
kbd_brightness_set
(
uint8_t
brite
)
{
pwmval
=
brite
;
if
(
pwmval
>=
10
)
pwmval
=
10
;
OCR0A
=
pwmval
;
}
void
remote_reset_som
(
void
)
{
empty_serial
();
term_x
=
0
;
term_y
=
0
;
Serial_SendByte
(
'2'
);
Serial_SendByte
(
'p'
);
Serial_SendByte
(
'\r'
);
Delay_MS
(
1
);
empty_serial
();
}
void
remote_wake_som
(
void
)
{
empty_serial
();
term_x
=
0
;
term_y
=
0
;
Serial_SendByte
(
'1'
);
Serial_SendByte
(
'w'
);
Serial_SendByte
(
'\r'
);
Delay_MS
(
1
);
empty_serial
();
Serial_SendByte
(
'0'
);
Serial_SendByte
(
'w'
);
Serial_SendByte
(
'\r'
);
Delay_MS
(
1
);
empty_serial
();
}
void
remote_turn_off_aux
(
void
)
{
empty_serial
();
Serial_SendByte
(
'3'
);
Serial_SendByte
(
'p'
);
Serial_SendByte
(
'\r'
);
Delay_MS
(
1
);
empty_serial
();
}
void
remote_turn_on_aux
(
void
)
{
empty_serial
();
Serial_SendByte
(
'4'
);
Serial_SendByte
(
'p'
);
Serial_SendByte
(
'\r'
);
Delay_MS
(
1
);
empty_serial
();
}
void
remote_enable_som_uart
(
void
)
{
empty_serial
();
Serial_SendByte
(
'1'
);
Serial_SendByte
(
'u'
);
Serial_SendByte
(
'\r'
);
Delay_MS
(
1
);
empty_serial
();
}
void
remote_disable_som_uart
(
void
)
{
empty_serial
();
Serial_SendByte
(
'0'
);
Serial_SendByte
(
'u'
);
Serial_SendByte
(
'\r'
);
Delay_MS
(
1
);
empty_serial
();
static
void
local_test
(
void
)
{
// low_battery_alert = !low_battery_alert;
// display_refresh();
}
typedef
struct
MenuItem
{
char
*
title
;
int
keycode
;
}
MenuItem
;
#ifdef KBD_VARIANT_STANDALONE
#define MENU_NUM_ITEMS 4
const
MenuItem
menu_items
[]
=
{
...
...
@@ -291,52 +189,6 @@ const menu_item_t circle_menu[] = {
};
#endif
int
current_menu_y
=
0
;
int
current_scroll_y
=
0
;
int
active_meta_mode
=
0
;
int
execute_meta_function
(
int
keycode
);
int
execute_menu_function
(
int
y
)
{
if
(
y
>=
0
&&
y
<
MENU_NUM_ITEMS
)
{
return
execute_meta_function
(
menu_items
[
y
].
keycode
);
}
return
execute_meta_function
(
KEY_ESCAPE
);
}
// returns 1 for navigation function (stay in meta mode), 0 for terminal function
int
execute_meta_function
(
int
keycode
)
{
if
(
keycode
==
KEY_R
)
{
// TODO: are you sure?
remote_reset_som
();
}
else
if
(
keycode
==
KEY_SPACE
)
{
remote_wake_som
();
}
/*else if (keycode == KEY_X) {
remote_turn_on_aux();
}
else if (keycode == KEY_V) {
remote_turn_off_aux();
}*/
else
if
(
keycode
==
KEY_Z
)
{
low_battery_alert
=
!
low_battery_alert
;
if
(
!
low_battery_alert
)
{
display_clear
();
display_flush
();
}
return
0
;
}
return
0
;
}
// scan the keyboard matrix and fill in a list of (up to MAX_CONCURRENT_KEYS)
// keys that are currently pressed. returns the count of pressed keys.
static
uint8_t
scan_keyboard_raw
(
uint8_t
keys
[])
{
...
...
@@ -457,32 +309,10 @@ static uint8_t scan_keyboard_enhanced(uint8_t keys[]) {
return
count
;
}
void
robey_test
(
void
)
{
display_clear
();
display_flush
();
for
(
int
j
=
0
;
j
<
20
;
j
++
)
{
Delay_MS
(
500
);
uint8_t
keys
[
MAX_CONCURRENT_KEYS
];
uint8_t
count
=
scan_keyboard
(
keys
);
if
(
count
>
0
)
{
for
(
int
i
=
0
;
i
<
count
;
i
++
)
{
char
x
[
10
];
sprintf
(
x
,
"%02x;"
,
keys
[
i
]);
display_write
(
x
);
}
display_write
(
".
\n
"
);
display_flush
();
}
}
display_write
(
"*"
);
display_flush
();
}
int
blink
=
0
;
void
process_alerts
(
void
)
{
static
int
blink
=
0
;
if
(
low_battery_alert
)
{
ux_blink_low_battery
(
blink
);
}
...
...
@@ -524,17 +354,23 @@ int main(void) {
int
counter
=
0
;
while
(
true
)
{
// do our own (non-usb) scan, too, so we can handle the circle menu
// when the laptop is off :)
scan_keyboard_enhanced
(
keys
);
HID_Device_USBTask
(
&
Keyboard_HID_Interface
);
USB_USBTask
();
counter
++
;
#ifndef KBD_VARIANT_STANDALONE
#if 0
if (counter >= 30000) {
remote_check_for_low_battery();
counter = 0;
}
if
(
counter
%
75
0
==
0
)
{
if (counter %
300
0 == 0) {
process_alerts();
}
#endif
#endif
}
}
...
...
reform2-keyboard-fw/controller.c
View file @
dbf4ccbc
...
...
@@ -98,6 +98,18 @@ void controller_probe_batteries(battery_info_t *info) {
info
->
total_percent
=
atoi
(
bat_gauge
);
}
// is the battery "alarmingly low"?
bool
controller_battery_is_low
(
void
)
{
battery_info_t
info
;
controller_probe_batteries
(
&
info
);
for
(
int
i
=
0
;
i
<
8
;
i
++
)
{
if
(
info
.
decivolts
[
i
]
<
30
)
return
true
;
}
if
(
info
.
total_percent
>
0
&&
info
.
total_percent
<
10
)
return
true
;
}
void
controller_turn_on_som
(
void
)
{
display_clear
();
display_flush
();
...
...
@@ -113,3 +125,37 @@ void controller_turn_off_som(void) {
flush
();
EnterPowerOff
();
}
void
controller_reset_som
(
void
)
{
display_clear
();
display_flush
();
controller_send
(
"2p"
);
flush
();
}
void
controller_wake_som
(
void
)
{
controller_send
(
"1w"
);
flush
();
controller_send
(
"0w"
);
flush
();
}
void
controller_turn_off_aux
(
void
)
{
controller_send
(
"3p"
);
flush
();
}
void
controller_turn_on_aux
(
void
)
{
controller_send
(
"4p"
);
flush
();
}
void
controller_enable_som_uart
(
void
)
{
controller_send
(
"1u"
);
flush
();
}
void
controller_disable_som_uart
(
void
)
{
controller_send
(
"0u"
);
flush
();
}
reform2-keyboard-fw/controller.h
View file @
dbf4ccbc
...
...
@@ -20,5 +20,12 @@ typedef struct {
void
controller_init
(
void
);
const
char
*
controller_request
(
const
char
*
command
);
void
controller_probe_batteries
(
battery_info_t
*
info
);
bool
controller_battery_is_low
(
void
);
void
controller_turn_on_som
(
void
);
void
controller_turn_off_som
(
void
);
void
controller_reset_som
(
void
);
void
controller_wake_som
(
void
);
void
controller_turn_off_aux
(
void
);
void
controller_turn_on_aux
(
void
);
void
controller_enable_som_uart
(
void
);
void
controller_disable_som_uart
(
void
);
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