plotter
plotter.cpp@1:761371998f16, 2016-10-30 (annotated)
- Committer:
- dicarloj
- Date:
- Sun Oct 30 22:30:34 2016 +0000
- Revision:
- 1:761371998f16
- Parent:
- 0:ed208b547ef9
aqaaaaaa
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
dicarloj | 0:ed208b547ef9 | 1 | #include "mbed.h" |
dicarloj | 0:ed208b547ef9 | 2 | #include "plotter.h" |
dicarloj | 0:ed208b547ef9 | 3 | |
dicarloj | 0:ed208b547ef9 | 4 | volatile float* data_1; |
dicarloj | 0:ed208b547ef9 | 5 | volatile float* data_2; |
dicarloj | 0:ed208b547ef9 | 6 | size_t buffer_size; |
dicarloj | 0:ed208b547ef9 | 7 | volatile bool send_now; |
dicarloj | 0:ed208b547ef9 | 8 | volatile float* plot_ptr; |
dicarloj | 0:ed208b547ef9 | 9 | |
dicarloj | 0:ed208b547ef9 | 10 | Serial pc(USBTX, USBRX); |
dicarloj | 0:ed208b547ef9 | 11 | // |
dicarloj | 0:ed208b547ef9 | 12 | int samples_per_plot = -1; |
dicarloj | 0:ed208b547ef9 | 13 | int count = 0; |
dicarloj | 0:ed208b547ef9 | 14 | int plot_count = 0; |
dicarloj | 0:ed208b547ef9 | 15 | bool initialized = false; |
dicarloj | 0:ed208b547ef9 | 16 | void send_message() |
dicarloj | 0:ed208b547ef9 | 17 | { |
dicarloj | 1:761371998f16 | 18 | //printf("in serial send\n\r"); |
dicarloj | 0:ed208b547ef9 | 19 | char start = 236; |
dicarloj | 0:ed208b547ef9 | 20 | ser_send(&pc, &start, 1); |
dicarloj | 0:ed208b547ef9 | 21 | ser_send(&pc, &start, 1); |
dicarloj | 1:761371998f16 | 22 | ser_send(&pc, (void*)data_1, buffer_size); |
dicarloj | 0:ed208b547ef9 | 23 | } |
dicarloj | 0:ed208b547ef9 | 24 | |
dicarloj | 1:761371998f16 | 25 | void init_plotter(int num_vars) |
dicarloj | 0:ed208b547ef9 | 26 | { |
dicarloj | 0:ed208b547ef9 | 27 | pc.baud(115200); |
dicarloj | 1:761371998f16 | 28 | buffer_size = num_vars * sizeof(float); |
dicarloj | 0:ed208b547ef9 | 29 | data_1 = (volatile float*)malloc(buffer_size); |
dicarloj | 1:761371998f16 | 30 | memset((void*)data_1, 0, buffer_size); |
dicarloj | 0:ed208b547ef9 | 31 | } |
dicarloj | 0:ed208b547ef9 | 32 | |
dicarloj | 0:ed208b547ef9 | 33 | void plot(int index_v, float value) |
dicarloj | 0:ed208b547ef9 | 34 | { |
dicarloj | 1:761371998f16 | 35 | volatile float* data_ptr = data_1; |
dicarloj | 1:761371998f16 | 36 | data_ptr[index_v] = value; |
dicarloj | 0:ed208b547ef9 | 37 | } |