11 changed files with 433 additions and 269 deletions
-
15README.md
-
174app/app.uvoptx
-
10app/app.uvprojx
-
2app/src/basic/version.h
-
36app/src/board/board.h
-
140app/src/board/board_beep_ctrl.c
-
26app/src/board/board_beep_ctrl.h
-
52app/src/one_conduction_board.c
-
8app/src/one_conduction_board.h
-
227app/src/one_conduction_main.c
-
12scripter/build_app.bat
@ -1,26 +1,24 @@ |
|||
#pragma once |
|||
|
|||
/** |
|||
* @brief |
|||
* |
|||
* 200HZ,16bit |
|||
* -> |
|||
* 1s => 200*2 => 400BYTE |
|||
* 248k |
|||
* -> |
|||
* 1s => 248*1024/400 => 634_S => 10.5min |
|||
*/ |
|||
/******************************************************************************* |
|||
* BEEP * |
|||
*******************************************************************************/ |
|||
#define BEEP_PIN 1 |
|||
#define BEEP_PWM_INSTANCE 0 |
|||
|
|||
#define MAX_STORAGE_TIMEOUT_S (60 * 10) |
|||
#define MAX_STORAGE_SIZE (MAX_STORAGE_TIMEOUT_S * 400) // 存储最大限制为 (256-8)kbyte |
|||
#define MAX_FILE_NUM 10 |
|||
|
|||
#define SAMPLE_RATE 500 |
|||
#define SAMPLE_PRECISION 12 |
|||
|
|||
#define AUTOMATIC_SLEEP_TIME 15000 |
|||
#define SAMPLE_MIN_TIME_S (30.0) |
|||
/** |
|||
* @brief |
|||
*/ |
|||
|
|||
// #define ENABLE_SLEEP |
|||
#define MAX_STORAGE_TIMEOUT_S (60 * 10) // 最长存储时间 |
|||
#define MAX_STORAGE_SIZE (MAX_STORAGE_TIMEOUT_S * 400) // 存储最大限制为 (256-8)kbyte |
|||
#define MAX_FILE_NUM 10 // 最多存储条目数 |
|||
#define SAMPLE_RATE 500 // 采样率 |
|||
#define SAMPLE_PRECISION 12 // 采样精度 |
|||
#define AUTOMATIC_SLEEP_TIME 30000 // 开机后自动休眠时间 |
|||
#define SAMPLE_MIN_TIME_S (30.0) // 采样最小时间 |
|||
#define LITTLE_DATA_BLOCK_FRAME_NUM 5 // 每次多少帧上报一次 |
|||
|
|||
#define LITTLE_DATA_BLOCK_FRAME_NUM 5 // 每次多少帧上报一次 |
|||
#define KEEP_STILL_OVERTIME_MS_1P5 2000 // 保持静止超时时间的1/6 |
@ -0,0 +1,140 @@ |
|||
#include "board_beep_ctrl.h" |
|||
#define BEEP_TIMER_INTERVAL (150) |
|||
#if 1 |
|||
|
|||
APP_TIMER_DEF(m_beep_tmr); // |
|||
static nrf_drv_pwm_t m_beep_pwm0 = NRF_DRV_PWM_INSTANCE(BEEP_PWM_INSTANCE); |
|||
static nrf_pwm_values_individual_t m_beep_pwm0_seq_values = {0}; |
|||
static nrf_pwm_sequence_t const m_beep_pwm0_seq = { |
|||
.values.p_individual = &m_beep_pwm0_seq_values, |
|||
.length = NRF_PWM_VALUES_LENGTH(m_beep_pwm0_seq_values), |
|||
.repeats = 0, |
|||
.end_delay = 0, |
|||
}; |
|||
static nrf_drv_pwm_config_t const m_beep_pwm0_config0 = { |
|||
.output_pins = |
|||
{ |
|||
BEEP_PIN, // |
|||
NRF_DRV_PWM_PIN_NOT_USED, |
|||
NRF_DRV_PWM_PIN_NOT_USED, |
|||
NRF_DRV_PWM_PIN_NOT_USED, |
|||
}, |
|||
.irq_priority = APP_IRQ_PRIORITY_LOWEST, |
|||
.base_clock = NRF_PWM_CLK_125kHz, |
|||
.count_mode = NRF_PWM_MODE_UP, |
|||
.top_value = 80, // 125kHz / 46 = 2.717k |
|||
.load_mode = NRF_PWM_LOAD_INDIVIDUAL, |
|||
.step_mode = NRF_PWM_STEP_AUTO, |
|||
}; |
|||
BoardBeepEffect_t m_beep_effect = kBoardBeepEffect_none; |
|||
static uint32_t m_beep_cnt = 0; |
|||
|
|||
static void beep_tmr_handler(void *context) { |
|||
if (m_beep_effect == kBoardBeepEffect_none) { |
|||
BoardBeepCtrl_set(false); |
|||
} else if (m_beep_effect == kBoardBeepEffect_oneShortBeep) { |
|||
if (m_beep_cnt == 0) { |
|||
BoardBeepCtrl_set(true); |
|||
} else if (m_beep_cnt >= 1) { |
|||
BoardBeepCtrl_set(false); |
|||
app_timer_stop(m_beep_tmr); |
|||
m_beep_effect = kBoardBeepEffect_none; |
|||
} |
|||
} |
|||
|
|||
else if (m_beep_effect == kBoardBeepEffect_oneShortLongBeep) { |
|||
if (m_beep_cnt == 0) { |
|||
BoardBeepCtrl_set(true); |
|||
} else if (m_beep_cnt >= 6) { |
|||
BoardBeepCtrl_set(false); |
|||
app_timer_stop(m_beep_tmr); |
|||
m_beep_effect = kBoardBeepEffect_none; |
|||
} |
|||
} |
|||
|
|||
else if (m_beep_effect == kBoardBeepEffect_threeShortBeep) { |
|||
if (m_beep_cnt < 6) { |
|||
if (m_beep_cnt % 2 == 0) { |
|||
BoardBeepCtrl_set(true); |
|||
} else if (m_beep_cnt % 2 == 1) { |
|||
BoardBeepCtrl_set(false); |
|||
} |
|||
} else { |
|||
BoardBeepCtrl_set(false); |
|||
app_timer_stop(m_beep_tmr); |
|||
m_beep_effect = kBoardBeepEffect_none; |
|||
} |
|||
|
|||
} else if (m_beep_effect == kBoardBeepEffect_continuousShortBeep) { |
|||
// 每隔1秒响三声 |
|||
if (m_beep_cnt < 6) { |
|||
if (m_beep_cnt % 2 == 0) { |
|||
BoardBeepCtrl_set(true); |
|||
} else if (m_beep_cnt % 2 == 1) { |
|||
BoardBeepCtrl_set(false); |
|||
} |
|||
} else { |
|||
if (BEEP_TIMER_INTERVAL * m_beep_cnt >= 10000) { |
|||
m_beep_cnt = 0; |
|||
return; |
|||
} |
|||
} |
|||
} |
|||
m_beep_cnt++; |
|||
} |
|||
|
|||
void BoardBeepCtrl_init(void) { // |
|||
app_timer_create(&m_beep_tmr, APP_TIMER_MODE_REPEATED, beep_tmr_handler); |
|||
} |
|||
static bool m_beep_loaded = false; |
|||
|
|||
void BoardBeepCtrl_load() { // |
|||
if (m_beep_loaded) return; |
|||
|
|||
APP_ERROR_CHECK(nrfx_pwm_init(&m_beep_pwm0, &m_beep_pwm0_config0, NULL)); |
|||
m_beep_loaded = true; |
|||
} |
|||
void BoardBeepCtrl_unload() { |
|||
if (!m_beep_loaded) return; |
|||
|
|||
BoardBeepCtrl_set(0); |
|||
nrfx_pwm_uninit(&m_beep_pwm0); |
|||
m_beep_loaded = false; |
|||
} |
|||
|
|||
void BoardBeepCtrl_set(uint8_t state) { |
|||
if (state) { |
|||
m_beep_pwm0_seq_values.channel_0 = 10; // 设置占空比,数值最大不超过 top_value |
|||
nrfx_pwm_simple_playback(&m_beep_pwm0, &m_beep_pwm0_seq, 1, NRF_DRV_PWM_FLAG_LOOP); |
|||
} else { |
|||
nrfx_pwm_stop(&m_beep_pwm0, true); |
|||
} |
|||
} |
|||
|
|||
void BoardBeepCtrl_setEffect(BoardBeepEffect_t effect) { |
|||
if (m_beep_effect == effect) return; |
|||
|
|||
m_beep_effect = effect; |
|||
|
|||
app_timer_stop(m_beep_tmr); |
|||
m_beep_cnt = 0; |
|||
if (m_beep_effect == kBoardBeepEffect_none) { |
|||
BoardBeepCtrl_set(false); |
|||
} |
|||
|
|||
else { |
|||
app_timer_start(m_beep_tmr, APP_TIMER_TICKS(BEEP_TIMER_INTERVAL), NULL); |
|||
} |
|||
} |
|||
|
|||
#else |
|||
|
|||
void BoardBeepCtrl_init(void) {} |
|||
void BoardBeepCtrl_load() {} |
|||
|
|||
void BoardBeepCtrl_unload() {} |
|||
|
|||
void BoardBeepCtrl_set(uint8_t state) {} |
|||
|
|||
void BoardBeepCtrl_setEffect(BoardBeepEffect_t effect) {} |
|||
#endif |
@ -0,0 +1,26 @@ |
|||
#pragma once |
|||
|
|||
#include <stdbool.h> |
|||
#include <stdint.h> |
|||
|
|||
#include "board/board.h" |
|||
#include "znordic.h" |
|||
|
|||
typedef enum { |
|||
kBoardBeepEffect_none = 0, |
|||
// 响一声 |
|||
kBoardBeepEffect_oneShortBeep, |
|||
// 响一声长鸣 |
|||
kBoardBeepEffect_oneShortLongBeep, |
|||
// 响三声 |
|||
kBoardBeepEffect_threeShortBeep, |
|||
// 持续短鸣报警 |
|||
kBoardBeepEffect_continuousShortBeep, |
|||
} BoardBeepEffect_t; |
|||
|
|||
void BoardBeepCtrl_init(void); |
|||
void BoardBeepCtrl_load(); |
|||
void BoardBeepCtrl_unload(); |
|||
|
|||
void BoardBeepCtrl_set(uint8_t beep); |
|||
void BoardBeepCtrl_setEffect(BoardBeepEffect_t effect); |
Write
Preview
Loading…
Cancel
Save
Reference in new issue