Skip to content

Commit

Permalink
v-alpha1
Browse files Browse the repository at this point in the history
  • Loading branch information
jiaxin96 committed Jun 28, 2021
1 parent 574b709 commit a4c0819
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,11 @@
#define BiuNrf52MsgShortTimeout 10 /* milliseconds */
#define BiuNrf52MsgRecvTimeout 2000 /* microseconds */

#define BiuNrf52ResetTimeout 10000 /* microseconds */
#define BiuNrf52ResetTimeout 25000 /* microseconds */
#define BiuNrf52InitTimeout 3000 /* microseconds */
// #define BiuNrf52SystemOffTimeout 300000 /* milliseconds */
#define BiuNrf52SystemOffTimeout 30000 /* milliseconds */
#define BatteryUpdateInterval 300000 /* milliseconds */
#define BatteryUpdateInterval 60000 /* milliseconds */



Expand Down Expand Up @@ -202,6 +203,7 @@ static struct {
uint32_t vbat;
#endif
uint16_t last_connection_update;
uint16_t last_success_conn_update;
uint16_t last_reset_update;
bool has_send_ask;
} state;
Expand Down Expand Up @@ -277,6 +279,7 @@ static void process_nrf_ack_msg(struct biunrf52_msg * msg) {
state.initialized = true;
state.configured = true;
state.is_connected = true;
state.last_success_conn_update = timer_read();
break;
case NRF_DISCONNECT:
case NRF_ADVING:
Expand Down Expand Up @@ -684,6 +687,7 @@ bool bluetooth_init_pre(void) {
state.has_send_ask = false;
state.last_connection_update = timer_read();
state.last_battery_update = timer_read();
state.last_success_conn_update = timer_read();

// start the uart data trans
uart_init(BIUNRF52UartBaud);
Expand Down Expand Up @@ -824,6 +828,7 @@ void inline biu_ble_system_off() {
state.has_send_ask = false;
state.last_battery_update = 0;
state.last_connection_update = 0;
state.last_success_conn_update = 0;

struct queue_item item;

Expand All @@ -836,8 +841,16 @@ void inline biu_ble_system_off() {
}

void inline check_ble_system_off_timer(void) {
if (TIMER_DIFF_16(timer_read(), state.last_connection_update) > BiuNrf52SystemOffTimeout) {
biu_ble_system_off();
if (state.is_connected) {
if (TIMER_DIFF_16(timer_read(), state.last_connection_update) > BiuNrf52SystemOffTimeout) {
biu_ble_system_off();
}
} else {
if (0 == state.last_success_conn_update) { // avoid died after last sysoff
state.last_success_conn_update = timer_read();
} else if (TIMER_DIFF_16(timer_read(), state.last_success_conn_update) > BiuNrf52SystemOffTimeout) {
biu_ble_system_off();
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ uint8_t desired_output = OUTPUT_DEFAULT;
* FIXME: Needs doc
*/
void set_output(uint8_t output) {
set_output_user(output);
desired_output = output;
set_output_user(output);
}

/** \brief Set Output User
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ enum outputs {
};

#ifndef OUTPUT_DEFAULT
# define OUTPUT_DEFAULT OUTPUT_BLUETOOTH
# define OUTPUT_DEFAULT OUTPUT_AUTO
#endif


Expand Down
1 change: 1 addition & 0 deletions keyboards/yandrstudio/m60ble/keymaps/ble/keymap.c
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ bool process_record_user(uint16_t keycode, keyrecord_t *record) {
case BL_SW_2:
case BL_SW_3:
if (record->event.pressed) {
set_output(OUTPUT_BLUETOOTH);
bluetooth_switch_one(keycode - BL_SW_0);
}
return false;
Expand Down

0 comments on commit a4c0819

Please sign in to comment.