diff --git a/.vscode/settings.json b/.vscode/settings.json
index 4439b0a..8d0cb1a 100644
--- a/.vscode/settings.json
+++ b/.vscode/settings.json
@@ -81,7 +81,8 @@
"typeinfo": "c",
"fontlib.h": "c",
"font.h": "c",
- "display_manager.h": "c"
+ "display_manager.h": "c",
+ "wave_drawer.h": "c"
},
"files.encoding": "gbk"
}
\ No newline at end of file
diff --git a/app/app.uvoptx b/app/app.uvoptx
index beef7a2..a5f0a2d 100644
--- a/app/app.uvoptx
+++ b/app/app.uvoptx
@@ -564,6 +564,18 @@
0
0
+
+ 1
+ 16
+ 1
+ 0
+ 0
+ 0
+ .\src\basic\ssd1306\wave_drawer.c
+ wave_drawer.c
+ 0
+ 0
+
@@ -574,7 +586,7 @@
0
2
- 16
+ 17
1
0
0
@@ -594,7 +606,7 @@
0
3
- 17
+ 18
1
0
0
@@ -606,7 +618,7 @@
3
- 18
+ 19
1
0
0
@@ -626,7 +638,7 @@
0
4
- 19
+ 20
1
0
0
@@ -646,7 +658,7 @@
0
5
- 20
+ 21
1
0
0
@@ -658,7 +670,7 @@
5
- 21
+ 22
1
0
0
@@ -670,7 +682,7 @@
5
- 22
+ 23
1
0
0
@@ -682,7 +694,7 @@
5
- 23
+ 24
1
0
0
@@ -694,7 +706,7 @@
5
- 24
+ 25
1
0
0
@@ -706,7 +718,7 @@
5
- 25
+ 26
1
0
0
@@ -718,7 +730,7 @@
5
- 26
+ 27
1
0
0
@@ -730,7 +742,7 @@
5
- 27
+ 28
1
0
0
@@ -750,7 +762,7 @@
0
6
- 28
+ 29
1
0
0
@@ -770,7 +782,7 @@
0
7
- 29
+ 30
1
0
0
@@ -782,7 +794,7 @@
7
- 30
+ 31
1
0
0
@@ -794,7 +806,7 @@
7
- 31
+ 32
1
0
0
@@ -806,7 +818,7 @@
7
- 32
+ 33
1
0
0
@@ -818,7 +830,7 @@
7
- 33
+ 34
1
0
0
@@ -830,7 +842,7 @@
7
- 34
+ 35
1
0
0
@@ -842,7 +854,7 @@
7
- 35
+ 36
1
0
0
@@ -854,7 +866,7 @@
7
- 36
+ 37
1
0
0
@@ -866,7 +878,7 @@
7
- 37
+ 38
1
0
0
@@ -878,7 +890,7 @@
7
- 38
+ 39
1
0
0
@@ -890,7 +902,7 @@
7
- 39
+ 40
1
0
0
@@ -902,7 +914,7 @@
7
- 40
+ 41
1
0
0
@@ -914,7 +926,7 @@
7
- 41
+ 42
1
0
0
@@ -926,7 +938,7 @@
7
- 42
+ 43
1
0
0
@@ -938,7 +950,7 @@
7
- 43
+ 44
1
0
0
@@ -950,7 +962,7 @@
7
- 44
+ 45
1
0
0
@@ -962,7 +974,7 @@
7
- 45
+ 46
1
0
0
@@ -974,7 +986,7 @@
7
- 46
+ 47
1
0
0
@@ -986,7 +998,7 @@
7
- 47
+ 48
1
0
0
@@ -1006,7 +1018,7 @@
0
8
- 48
+ 49
1
0
0
@@ -1018,7 +1030,7 @@
8
- 49
+ 50
1
0
0
@@ -1030,7 +1042,7 @@
8
- 50
+ 51
1
0
0
@@ -1042,7 +1054,7 @@
8
- 51
+ 52
1
0
0
@@ -1054,7 +1066,7 @@
8
- 52
+ 53
1
0
0
@@ -1066,7 +1078,7 @@
8
- 53
+ 54
1
0
0
@@ -1078,7 +1090,7 @@
8
- 54
+ 55
1
0
0
@@ -1090,7 +1102,7 @@
8
- 55
+ 56
1
0
0
@@ -1102,7 +1114,7 @@
8
- 56
+ 57
1
0
0
@@ -1114,7 +1126,7 @@
8
- 57
+ 58
1
0
0
@@ -1126,7 +1138,7 @@
8
- 58
+ 59
1
0
0
@@ -1138,7 +1150,7 @@
8
- 59
+ 60
1
0
0
@@ -1150,7 +1162,7 @@
8
- 60
+ 61
1
0
0
@@ -1162,7 +1174,7 @@
8
- 61
+ 62
1
0
0
@@ -1174,7 +1186,7 @@
8
- 62
+ 63
1
0
0
@@ -1186,7 +1198,7 @@
8
- 63
+ 64
1
0
0
@@ -1198,7 +1210,7 @@
8
- 64
+ 65
1
0
0
@@ -1210,7 +1222,7 @@
8
- 65
+ 66
1
0
0
@@ -1222,7 +1234,7 @@
8
- 66
+ 67
1
0
0
@@ -1234,7 +1246,7 @@
8
- 67
+ 68
1
0
0
@@ -1246,7 +1258,7 @@
8
- 68
+ 69
1
0
0
@@ -1258,7 +1270,7 @@
8
- 69
+ 70
1
0
0
@@ -1270,7 +1282,7 @@
8
- 70
+ 71
1
0
0
@@ -1282,7 +1294,7 @@
8
- 71
+ 72
1
0
0
@@ -1294,7 +1306,7 @@
8
- 72
+ 73
1
0
0
@@ -1306,7 +1318,7 @@
8
- 73
+ 74
1
0
0
@@ -1318,7 +1330,7 @@
8
- 74
+ 75
1
0
0
@@ -1338,7 +1350,7 @@
0
9
- 75
+ 76
1
0
0
@@ -1350,7 +1362,7 @@
9
- 76
+ 77
1
0
0
@@ -1362,7 +1374,7 @@
9
- 77
+ 78
1
0
0
@@ -1374,7 +1386,7 @@
9
- 78
+ 79
1
0
0
@@ -1386,7 +1398,7 @@
9
- 79
+ 80
1
0
0
@@ -1398,7 +1410,7 @@
9
- 80
+ 81
1
0
0
@@ -1418,7 +1430,7 @@
0
10
- 81
+ 82
1
0
0
@@ -1430,7 +1442,7 @@
10
- 82
+ 83
1
0
0
@@ -1442,7 +1454,7 @@
10
- 83
+ 84
1
0
0
@@ -1462,7 +1474,7 @@
0
11
- 84
+ 85
1
0
0
@@ -1474,7 +1486,7 @@
11
- 85
+ 86
1
0
0
@@ -1486,7 +1498,7 @@
11
- 86
+ 87
1
0
0
@@ -1506,7 +1518,7 @@
0
12
- 87
+ 88
1
0
0
@@ -1526,7 +1538,7 @@
0
13
- 88
+ 89
1
0
0
@@ -1538,7 +1550,7 @@
13
- 89
+ 90
1
0
0
diff --git a/app/app.uvprojx b/app/app.uvprojx
index 136dfea..76b25e8 100644
--- a/app/app.uvprojx
+++ b/app/app.uvprojx
@@ -458,6 +458,11 @@
1
.\src\basic\ssd1306\fontlib.c
+
+ wave_drawer.c
+ 1
+ .\src\basic\ssd1306\wave_drawer.c
+
@@ -4257,6 +4262,11 @@
1
.\src\basic\ssd1306\fontlib.c
+
+ wave_drawer.c
+ 1
+ .\src\basic\ssd1306\wave_drawer.c
+
diff --git a/app/src/basic/ssd1306/driver_ssd1306.c b/app/src/basic/ssd1306/driver_ssd1306.c
index 13c21f9..ba880cb 100644
--- a/app/src/basic/ssd1306/driver_ssd1306.c
+++ b/app/src/basic/ssd1306/driver_ssd1306.c
@@ -469,7 +469,6 @@ uint8_t ssd1306_write_point(ssd1306_handle_t *handle, uint8_t x, uint8_t y, uint
}
if ((x > 127) || (y > 63)) /* check x, y */
{
- handle->debug_print("ssd1306: x or y is invalid.\n"); /* x or y is invalid */
return 4; /* return error */
}
@@ -547,7 +546,6 @@ uint8_t ssd1306_read_point(ssd1306_handle_t *handle, uint8_t x, uint8_t y, uint8
}
if ((x > 127) || (y > 63)) /* check x, y */
{
- handle->debug_print("ssd1306: x or y is invalid.\n"); /* x or y is invalid */
return 4; /* return error */
}
@@ -597,8 +595,6 @@ uint8_t ssd1306_gram_write_point(ssd1306_handle_t *handle, uint8_t x, uint8_t y,
}
if ((x > 127) || (y > 63)) /* check x, y */
{
- handle->debug_print("ssd1306: x or y is invalid.\n"); /* x or y is invalid */
-
return 4; /* return error */
}
@@ -647,7 +643,6 @@ uint8_t ssd1306_gram_read_point(ssd1306_handle_t *handle, uint8_t x, uint8_t y,
}
if ((x > 127) || (y > 63)) /* check x, y */
{
- handle->debug_print("ssd1306: x or y is invalid.\n"); /* x or y is invalid */
return 4; /* return error */
}
@@ -696,7 +691,6 @@ uint8_t ssd1306_gram_write_string(ssd1306_handle_t *handle, uint8_t x, uint8_t y
}
if((x > 127) || (y > 63)) /* check x, y */
{
- handle->debug_print("ssd1306: x or y is invalid.\n"); /* x or y is invalid */
return 4; /* return error */
}
diff --git a/app/src/basic/ssd1306/driver_ssd1306_basic.c b/app/src/basic/ssd1306/driver_ssd1306_basic.c
index 07b32ca..36bd9d2 100644
--- a/app/src/basic/ssd1306/driver_ssd1306_basic.c
+++ b/app/src/basic/ssd1306/driver_ssd1306_basic.c
@@ -760,3 +760,29 @@ uint8_t ssd1306_basic_draw_progress(uint8_t xs, uint8_t ys, uint16_t width, uint
}
return 0;
}
+
+uint8_t ssd1306_basic_draw_line(uint8_t x1, uint8_t y1, uint8_t x2, uint8_t y2) {
+ int dx = abs(x2 - x1);
+ int dy = abs(y2 - y1);
+ int sx = (x1 < x2) ? 1 : -1;
+ int sy = (y1 < y2) ? 1 : -1;
+ int err = dx - dy;
+
+ while (1) {
+ ssd1306_gram_write_point(&gs_handle, x1, y1, 1);
+ if (x1 == x2 && y1 == y2) {
+ break;
+ }
+
+ int e2 = 2 * err;
+ if (e2 > -dy) {
+ err -= dy;
+ x1 += sx;
+ }
+
+ if (e2 < dx) {
+ err += dx;
+ y1 += sy;
+ }
+ }
+}
diff --git a/app/src/basic/ssd1306/driver_ssd1306_basic.h b/app/src/basic/ssd1306/driver_ssd1306_basic.h
index dd17d09..93e3397 100644
--- a/app/src/basic/ssd1306/driver_ssd1306_basic.h
+++ b/app/src/basic/ssd1306/driver_ssd1306_basic.h
@@ -210,6 +210,9 @@ uint8_t ssd1306_basic_draw_battery_level(uint8_t xs, uint8_t ys, uint8_t *xchang
uint8_t ssd1306_basic_draw_progress(uint8_t xs, uint8_t ys, uint16_t width, uint16_t high, uint16_t markpos, uint16_t progress);
+uint8_t ssd1306_basic_draw_line(uint8_t x1, uint8_t y1,uint8_t x2, uint8_t y2);
+
+
/**
* @}
*/
diff --git a/app/src/basic/ssd1306/wave_drawer.c b/app/src/basic/ssd1306/wave_drawer.c
new file mode 100644
index 0000000..abd37c6
--- /dev/null
+++ b/app/src/basic/ssd1306/wave_drawer.c
@@ -0,0 +1,86 @@
+#include "wave_drawer.h"
+
+#include "znordic.h"
+
+void wave_drawer_init(wave_drawer_t *dw, uint8_t xs, uint8_t ys, uint16_t width, uint16_t high) {
+ dw->xs = xs;
+ dw->ys = ys;
+ dw->width = width;
+ dw->high = high;
+ dw->pointoffset = 0;
+
+ dw->xright_border = xs + width;
+ dw->xleft_border = xs;
+ dw->ytop_border = ys;
+ dw->ybottom_border = ys + high;
+
+ dw->ytop = ys + 1;
+ dw->ybottom = ys + high - 1;
+ dw->xleft = xs + 1;
+ dw->xright = xs + width - 1;
+
+ dw->high = high - 1;
+ dw->width = width - 1;
+ dw->is_first_point = true;
+}
+
+void wave_drawer_draw_border(wave_drawer_t *dw) {
+ for (uint16_t x = dw->xleft_border; x <= dw->xright_border; x++) {
+ for (uint16_t y = dw->ytop_border; y <= dw->ybottom_border; y++) {
+ if (x == dw->xleft_border || x == dw->xright_border || y == dw->ytop_border || y == dw->ybottom_border) {
+ // ssd1306_gram_write_point(ssd1306_handler(), x, y, 1);
+ } else {
+ ssd1306_gram_write_point(ssd1306_handler(), x, y, 0);
+ }
+ }
+ }
+}
+
+void wave_drawer_draw_next_point(wave_drawer_t *dw, uint8_t y) {
+ /**
+ * @brief
+ *
+ * ----------------
+ * |
+ * | . ..| ....
+ * |.. . |
+ * |
+ * |---------------
+ */
+
+ uint16_t yreal = y / 100.0 * (dw->high - 1);
+ uint16_t ypos = dw->ybottom - yreal;
+ uint16_t xpos = dw->xleft + dw->pointoffset;
+
+ // 清除上一次的点
+ for (size_t yoff = 0; yoff < dw->high; yoff++) {
+ ssd1306_gram_write_point(ssd1306_handler(), xpos + 0, dw->ybottom - yoff, 0);
+ }
+
+ ssd1306_gram_write_point(ssd1306_handler(), xpos, ypos, 1);
+ if (xpos > dw->last_xs && !dw->is_first_point) {
+ // 画当前点和上一次点的连线
+ ssd1306_basic_draw_line(xpos - 1, dw->last_ys, xpos, ypos);
+ }
+ /**
+ * @brief 画当前位置标志
+ */
+ for (size_t yoff = 0; yoff < dw->high; yoff++) {
+ if (xpos + 1 <= dw->xright) {
+ ssd1306_gram_write_point(ssd1306_handler(), xpos + 1, dw->ybottom - yoff, 1);
+ }
+ for (uint8_t i = 2; i < 2 + 20; i++) {
+ if (xpos + i <= dw->xright) {
+ ssd1306_gram_write_point(ssd1306_handler(), xpos + i, dw->ybottom - yoff, 0);
+ }
+ }
+ }
+ dw->last_xs = xpos;
+ dw->last_ys = ypos;
+
+ dw->pointoffset++;
+ if (dw->pointoffset >= dw->width) {
+ dw->pointoffset = 0;
+ }
+ dw->is_first_point = false;
+}
\ No newline at end of file
diff --git a/app/src/basic/ssd1306/wave_drawer.h b/app/src/basic/ssd1306/wave_drawer.h
new file mode 100644
index 0000000..e42d3fb
--- /dev/null
+++ b/app/src/basic/ssd1306/wave_drawer.h
@@ -0,0 +1,33 @@
+#pragma once
+#include "driver_ssd1306.h"
+#include "driver_ssd1306_basic.h"
+
+typedef struct {
+ uint8_t xs;
+ uint8_t ys;
+
+ uint8_t last_xs;
+ uint8_t last_ys;
+
+ uint8_t xright_border;
+ uint8_t xleft_border;
+
+ uint8_t ytop_border;
+ uint8_t ybottom_border;
+
+ uint8_t ytop;
+ uint8_t ybottom;
+
+ uint16_t xleft;
+ uint16_t xright;
+
+ uint16_t width;
+ uint16_t high;
+
+ uint16_t pointoffset;
+ bool is_first_point;
+} wave_drawer_t;
+
+void wave_drawer_init(wave_drawer_t *drawer, uint8_t xs, uint8_t ys, uint16_t width, uint16_t high);
+void wave_drawer_draw_border(wave_drawer_t *drawer);
+void wave_drawer_draw_next_point(wave_drawer_t *drawer, uint8_t y);
diff --git a/app/src/one_conduction/display_manager.c b/app/src/one_conduction/display_manager.c
index 1105246..878d2c9 100644
--- a/app/src/one_conduction/display_manager.c
+++ b/app/src/one_conduction/display_manager.c
@@ -6,6 +6,7 @@
#include "basic/ssd1306/driver_ssd1306.h"
#include "basic/ssd1306/driver_ssd1306_basic.h"
+#include "basic/ssd1306/wave_drawer.h"
#include "font.h"
#include "one_conduction_board.h"
PageState_t g_pageState;
@@ -125,11 +126,20 @@ void dsp_mgr_change_to_preparePage() {
ssd1306_basic_gram_update();
dsp_mgr_change_to_page(kPage_preparePage);
}
+static wave_drawer_t wave_drawer;
+
void dsp_mgr_change_to_sampling() { //
- ssd1306_basic_draw_progress(5, 5, 100, 8, 50, 30);
+ // ssd1306_basic_draw_progress(5, 5, 100, 8, 50, 30);
+ wave_drawer_init(&wave_drawer, 1, 1, 100, 40);
+ wave_drawer_draw_border(&wave_drawer);
ssd1306_basic_gram_update();
+}
+void dsp_mgr_draw_point(int16_t y) {
+ wave_drawer_draw_next_point(&wave_drawer, y);
+ ssd1306_basic_gram_update();
}
+
void dsp_mgr_change_to_samplingError() {
/**
* @brief
diff --git a/app/src/one_conduction/display_manager.h b/app/src/one_conduction/display_manager.h
index 5a9f9eb..cc1f630 100644
--- a/app/src/one_conduction/display_manager.h
+++ b/app/src/one_conduction/display_manager.h
@@ -64,6 +64,8 @@ uint32_t dsp_mgr_get_page_elapsed_time_s(void);
void dsp_mgr_poweron();
void dsp_mgr_poweroff();
+void dsp_mgr_draw_point(int16_t y);
+
void dsp_mgr_change_to_poweroff();
void dsp_mgr_change_to_welcome();
void dsp_mgr_change_to_main();
diff --git a/app/src/one_conduction/one_conduction_board.c b/app/src/one_conduction/one_conduction_board.c
index 7c41ee9..d1fa06f 100644
--- a/app/src/one_conduction/one_conduction_board.c
+++ b/app/src/one_conduction/one_conduction_board.c
@@ -106,7 +106,7 @@ void SingleLeadECG_screen_init() {
spi_config.miso_pin = NRF_DRV_SPI_PIN_NOT_USED;
spi_config.mosi_pin = SCREEN_MOSI_PIN;
spi_config.sck_pin = SCREEN_CLK_PIN;
- spi_config.frequency = NRF_DRV_SPI_FREQ_1M;
+ spi_config.frequency = NRF_DRV_SPI_FREQ_8M;
spi_config.mode = NRF_DRV_SPI_MODE_3;
ZERROR_CHECK(nrf_drv_spi_init(&m_screen_spi, &spi_config, NULL, NULL));
ssd1306_basic_init(SSD1306_INTERFACE_SPI, SSD1306_ADDR_SA0_0);
diff --git a/app/src/one_conduction/one_conduction_main.c b/app/src/one_conduction/one_conduction_main.c
index 22ca17b..8668273 100644
--- a/app/src/one_conduction/one_conduction_main.c
+++ b/app/src/one_conduction/one_conduction_main.c
@@ -1,6 +1,9 @@
+#include
+
#include "basic/zble_module.h"
#include "basic/zdatachannel_service.h"
#include "one_conduction_board.h"
+#include "display_manager.h"
#include "znordic.h"
ZDATACHANNEL_DEF(m_zhrs, 2 /*回调事件优先??*/, 1 /*client num*/);
@@ -25,6 +28,22 @@ void zdatachannel_data_handler(zdatachannel_evt_t* p_evt) {
ZLOGI("rx:%s", hex2str(p_evt->params.rx_data.p_data, p_evt->params.rx_data.length));
}
}
+#define PI 3.14159265
+#define SAMPLES 100
+#define AMPLITUDE 50
+static void test_tx_timer_cb(void* p_context) {
+ static int i;
+ float val = 50 + AMPLITUDE * sin(2 * PI * i / SAMPLES);
+ // NRF_LOG_FLOAT(val);
+
+ ZLOGI("tx:" NRF_LOG_FLOAT_MARKER, NRF_LOG_FLOAT(val));
+ i++;
+ dsp_mgr_draw_point(val);
+}
+
+extern uint32_t g_nrf_log_tx_pin;
+APP_TIMER_DEF(m_drawpoint_timer);
+
/*******************************************************************************
* INIT *
*******************************************************************************/
@@ -59,5 +78,8 @@ void one_conduction_main() {
dsp_mgr_poweron();
dsp_mgr_change_to_sampling();
+ ZERROR_CHECK(app_timer_create(&m_drawpoint_timer, APP_TIMER_MODE_REPEATED, test_tx_timer_cb));
+ ZERROR_CHECK(app_timer_start(m_drawpoint_timer, APP_TIMER_TICKS(30), NULL));
+
znordic_loop();
}