Skip to content

Commit

Permalink
添加keep函数
Browse files Browse the repository at this point in the history
  • Loading branch information
jiaxin96 committed Jul 22, 2021
1 parent e869849 commit 98a0816
Show file tree
Hide file tree
Showing 11 changed files with 320 additions and 200 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,19 @@
__attribute__((weak)) bool bluetooth_init(void) { return true; }
__attribute__((weak)) bool bluetooth_init_pre(void) { return true; }
__attribute__((weak)) bool bluetooth_init_pos(void) { return true; }

__attribute__((weak)) void bluetooth_task(void) {}

__attribute__((weak)) bool bluetooth_is_connected(void) { return true; }

__attribute__((weak)) bool bluetooth_is_configured(void) { return true; }
__attribute__((weak)) void bluetooth_wakeup_once(void) {}
__attribute__((weak)) void bluetooth_unpair_all(void) {}

__attribute__((weak)) void bluetooth_unpair_one(uint8_t device_id) {}
__attribute__((weak)) void bluetooth_unpair_current(void) {}

__attribute__((weak)) void bluetooth_pair(void) {}

__attribute__((weak)) void bluetooth_clear_buf(void) {}
__attribute__((weak)) void bluetooth_switch_one(uint8_t device_id) {}
__attribute__((weak)) uint8_t bluetooth_working_state(void) { return 0; }
__attribute__((weak)) void bluetooth_power_manager(void) {};
__attribute__((weak)) void bluetooth_send_battery_level(void) { }

__attribute__((weak)) void bluetooth_send_keyboard(report_keyboard_t *report) {}

Expand All @@ -37,7 +37,6 @@ __attribute__((weak)) void bluetooth_send_keyboard_nkro(report_keyboard_t *repor
__attribute__((weak)) void bluetooth_send_joystick(joystick_report_t *report) {}
#endif

__attribute__((weak)) void bluetooth_send_battery_level(void) { }



Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,13 @@
#include "report.h"
#include <stdint.h>

enum bluetooth_state {
WORKING,
SLEEPING,
WAITING,
STOPWORK
};

#ifdef __cplusplus
extern "C" {
#endif
Expand All @@ -12,11 +19,17 @@ bool bluetooth_init_pre(void);
bool bluetooth_init_pos(void);
void bluetooth_task(void);
bool bluetooth_is_connected(void);
bool bluetooth_is_configured(void);
void bluetooth_wakeup_once(void);
void bluetooth_unpair_all(void);
void bluetooth_unpair_one(uint8_t device_id);
void bluetooth_unpair_current(void);
void bluetooth_pair(void);
void bluetooth_clear_buf(void);
void bluetooth_switch_one(uint8_t device_id);
uint8_t bluetooth_working_state(void);
void bluetooth_power_manager(void);
void bluetooth_send_battery_level(void);

void bluetooth_send_keyboard(report_keyboard_t *report);

Expand All @@ -36,7 +49,6 @@ void bluetooth_send_keyboard_nkro(report_keyboard_t *report);
void bluetooth_send_joystick(joystick_report_t *report);
#endif

void bluetooth_send_battery_level(void);

#ifdef __cplusplus
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
定时器:
state.last_reset_update // 重启nrf模块计数器,每次重启一次开始计时,重启间隔为BiuNrf52ResetTimeout,默认30秒。模块开始工作后停止计时和重启
state.last_battery_update // 电池电压更新计时器,间隔BatteryUpdateInterval更新一次。
state.last_connection_update // 连接更新计时器,每次发送成功到nrf的包更新一次,(发送电池信息不更新
state.last_system_off_update // nrf休眠计时器,在非连接状态时进行计数,即用户进行配对且配对失败的情况下超时休眠

state.keep_connection_update // 用来保持连接的计时器,定时更新nrf的状态

休眠逻辑:
1:如果是连接状态,判断last_connection_update是否超时(超时间隔BiuNrf52SystemOffTimeout),即一段时间内没有按键
2:非连接状态,判断last_system_off_update是否超时(超时间隔BiuNrf52SystemOffTimeoutFast),即一段时间内没有连接,或者意外断开连接后一段时间

唤醒逻辑:

Loading

0 comments on commit 98a0816

Please sign in to comment.