diff --git a/app/src/board/board.h b/app/src/board/board.h index b0999e7..3780cb8 100644 --- a/app/src/board/board.h +++ b/app/src/board/board.h @@ -58,7 +58,7 @@ #define HEART_WAVE_SAMPLE_SERVICE_CACHE_SIZE (3 * 3 * 256) #define FILE_MAX_COUNT 1 -#define SDCARD_MAX_FILE_SIZE (uint32_t)(3 * 1024 * 1024 * 1024) +#define SDCARD_MAX_FILE_SIZE (uint32_t)(3.5 * 1024 * 1024 * 1024) // #define SAMPLE_RATE 500 #define SAMPLE_PRECISION 24 diff --git a/app/src/board/board_button.c b/app/src/board/board_button.c index 69be33a..44601d5 100644 --- a/app/src/board/board_button.c +++ b/app/src/board/board_button.c @@ -14,16 +14,21 @@ void button_process_handler(uint8_t pin_no, uint8_t button_action) { } static app_button_cfg_t buttons[] = { - {BUTTON_PIN, false, NRF_GPIO_PIN_PULLUP, button_process_handler}, + {BUTTON_PIN, true, NRF_GPIO_PIN_PULLUP, button_process_handler}, }; void BoardButton_Init(board_button_cb_t cb) { // m_cb = cb; - ZERROR_CHECK(app_button_init(buttons, ARRAY_SIZE(buttons), BUTTON_DETECTION_DELAY)); + // ZERROR_CHECK(app_button_init(buttons, ARRAY_SIZE(buttons), BUTTON_DETECTION_DELAY)); +} +void BoardButton_load() { + // ZERROR_CHECK(app_button_enable()); +} +void BoardButton_unload() { + // ZERROR_CHECK(app_button_disable()); } -void BoardButton_load() { ZERROR_CHECK(app_button_enable()); } -void BoardButton_unload() { ZERROR_CHECK(app_button_disable()); } void BoardButton_enable_sense() { - app_button_disable(); - nrf_gpio_cfg_sense_input(BUTTON_PIN, NRF_GPIO_PIN_PULLUP, NRF_GPIO_PIN_SENSE_LOW); + // app_button_disable(); + nrf_gpio_cfg_sense_input(BUTTON_PIN, NRF_GPIO_PIN_NOPULL, NRF_GPIO_PIN_SENSE_LOW); + // nrf_gpio_cfg_sense_input(BUTTON_PIN, NRF_GPIO_PIN_PULLDOWN, NRF_GPIO_PIN_SENSE_HIGH); } diff --git a/app/src/device_ctrl_service.c b/app/src/device_ctrl_service.c index e5c5dd7..1056ef3 100644 --- a/app/src/device_ctrl_service.c +++ b/app/src/device_ctrl_service.c @@ -72,6 +72,7 @@ static void poweroff() { // 进入深度睡眠前,使能唤醒引脚 BoardButton_enable_sense(); + app_timer_stop_all(); // 系统进入深度睡眠 sd_power_system_off(); NVIC_SystemReset(); @@ -137,6 +138,12 @@ static void prvf_change_to_sample_state() { // static void app_event_listener(void* p_event_data, uint16_t event_size) { // app_event_t* event = (app_event_t*)p_event_data; + static bool inited; + if (!inited) { + nrf_gpio_cfg_input(BUTTON_PIN, NRF_GPIO_PIN_NOPULL); + inited = true; + } + ZLOGI("button %d", nrf_gpio_pin_read(BUTTON_PIN)); /******************************************************************************* * 状态无关事件处理 * @@ -156,6 +163,7 @@ static void app_event_listener(void* p_event_data, uint16_t event_size) { // if (m_device_state == kdevice_state_standby) { // 休眠模式现在是深度睡眠,所以永远不会触发这个回调 } + // else if (m_device_state == kdevice_state_ready) { if (!zble_module_is_connected() && DeviceCtrl_cur_state_haspassed_ms() > APP_AUTO_SLEEP_TIMEOUT_MS) { diff --git a/app/src/heart_wave_sample_service.c b/app/src/heart_wave_sample_service.c index 990c764..22ea6e3 100644 --- a/app/src/heart_wave_sample_service.c +++ b/app/src/heart_wave_sample_service.c @@ -49,8 +49,11 @@ static ads1293_t m_ads1293_1; static const nrf_drv_spi_t spi = NRF_DRV_SPI_INSTANCE(ADS1293_SPI_INSTANCE); /**< SPI instance. */ static bool m_ads1293_driver_is_inited = false; static uint32_t m_frame_index; +static uint32_t m_frame_filter_index; static bool m_work_flag; +#define FRAME_FILTER_INDEX_NUM 10 + static uint8_t m_frame_buffer_a[HEART_WAVE_SAMPLE_SERVICE_CACHE_SIZE]; static uint8_t m_frame_buffer_b[HEART_WAVE_SAMPLE_SERVICE_CACHE_SIZE]; static uint8_t* m_frame_buffer; @@ -261,6 +264,10 @@ static void ads1293_sample_one_frame() { if (!m_work_flag) { return; } + if (m_frame_filter_index < FRAME_FILTER_INDEX_NUM) { + m_frame_filter_index++; + return; + } m_frame_index++; // 检查缓冲区是否为空 if (!m_frame_buffer) prvf_buffer_switch(); @@ -353,14 +360,17 @@ void hwss_unload(void) { void hwss_start_capture(void) { m_drop_state_triggered = false; m_work_flag = true; + m_frame_index = 0; + m_frame_filter_index = 0; ads1293_start_conversion(&m_ads1293_0); ads1293_start_conversion(&m_ads1293_1); nrfx_timer_enable(&m_timer); } void hwss_stop_capture(void) { nrfx_timer_disable(&m_timer); - - m_work_flag = false; + m_work_flag = false; + m_frame_index = 0; + m_frame_filter_index = 0; ads1293_stop_conversion(&m_ads1293_0); ads1293_stop_conversion(&m_ads1293_1); } diff --git a/sample_bin_parser/.clang-format b/sample_bin_parser/.clang-format new file mode 100644 index 0000000..26476ea --- /dev/null +++ b/sample_bin_parser/.clang-format @@ -0,0 +1,10 @@ + +# Defines the Chromium style for automatic reformatting. +# http://clang.llvm.org/docs/ClangFormatStyleOptions.html +Language: Cpp +BasedOnStyle: Google +ColumnLimit: 160 +AlignConsecutiveMacros: true +AlignConsecutiveDeclarations: true +AlignConsecutiveAssignments: true +AlignOperands: true \ No newline at end of file diff --git a/sample_bin_parser/.vscode/settings.json b/sample_bin_parser/.vscode/settings.json new file mode 100644 index 0000000..a0f2052 --- /dev/null +++ b/sample_bin_parser/.vscode/settings.json @@ -0,0 +1,62 @@ +{ + "files.associations": { + "*.hpp": "cpp", + "fstream": "cpp", + "iostream": "cpp", + "string": "cpp", + "array": "cpp", + "atomic": "cpp", + "bit": "cpp", + "*.tcc": "cpp", + "cctype": "cpp", + "clocale": "cpp", + "cmath": "cpp", + "compare": "cpp", + "concepts": "cpp", + "cstdarg": "cpp", + "cstddef": "cpp", + "cstdint": "cpp", + "cstdio": "cpp", + "cstdlib": "cpp", + "cwchar": "cpp", + "cwctype": "cpp", + "deque": "cpp", + "list": "cpp", + "map": "cpp", + "set": "cpp", + "unordered_map": "cpp", + "vector": "cpp", + "exception": "cpp", + "algorithm": "cpp", + "functional": "cpp", + "iterator": "cpp", + "memory": "cpp", + "memory_resource": "cpp", + "numeric": "cpp", + "random": "cpp", + "string_view": "cpp", + "system_error": "cpp", + "tuple": "cpp", + "type_traits": "cpp", + "utility": "cpp", + "initializer_list": "cpp", + "iosfwd": "cpp", + "istream": "cpp", + "limits": "cpp", + "new": "cpp", + "numbers": "cpp", + "ostream": "cpp", + "sstream": "cpp", + "stdexcept": "cpp", + "streambuf": "cpp", + "typeinfo": "cpp", + "thread": "cpp", + "ctime": "cpp", + "ratio": "cpp", + "semaphore": "cpp", + "stop_token": "cpp", + "condition_variable": "cpp", + "mutex": "cpp" + }, + "files.encoding": "gbk" +} \ No newline at end of file diff --git a/sample_bin_parser/README.md b/sample_bin_parser/README.md new file mode 100644 index 0000000..94e4901 --- /dev/null +++ b/sample_bin_parser/README.md @@ -0,0 +1 @@ +g++ -static -static-libgcc -static-libstdc++ -lwsock32 -lstdc++ .\sample_bin_parse.cpp -o sample_bin_parse.exe \ No newline at end of file diff --git a/sample_bin_parser/sample_bin_parse.cpp b/sample_bin_parser/sample_bin_parse.cpp new file mode 100644 index 0000000..2e74d50 --- /dev/null +++ b/sample_bin_parser/sample_bin_parse.cpp @@ -0,0 +1,54 @@ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +// +#include +// +#include +// +#include + +#pragma comment(lib, "ws2_32.lib") +#define PORT 8988 + +int main(int argc, char *argv[]) { + // 打开 0.bin + // 读取 0.bin 到数组中 + // 每次读9byte + // 3byte 3byte 3byte + // 存放到0.csv中 + + std::ifstream ifs("0.bin", std::ios::binary); + if (!ifs) { + std::cerr << "open 0.bin failed" << std::endl; + return -1; + } + + std::ofstream ofs("0.csv", std::ios::binary | std::ios::trunc); + if (!ofs) { + std::cerr << "open 0.csv failed" << std::endl; + return -1; + } + + char buf[9]; + while (ifs.read(buf, 9)) { + unsigned int a = 0; + unsigned int b = 0; + unsigned int c = 0; + a = (unsigned char)buf[0] | (unsigned char)buf[1] << 8 | (unsigned char)buf[2] << 16; + b = (unsigned char)buf[3] | (unsigned char)buf[4] << 8 | (unsigned char)buf[5] << 16; + c = (unsigned char)buf[6] | (unsigned char)buf[7] << 8 | (unsigned char)buf[8] << 16; + ofs << a << "," << b << "," << c << std::endl; + } + + return 0; +} \ No newline at end of file diff --git a/sample_bin_parser/sample_bin_parse.exe b/sample_bin_parser/sample_bin_parse.exe new file mode 100644 index 0000000..b856e03 Binary files /dev/null and b/sample_bin_parser/sample_bin_parse.exe differ