fra222
Dependencies: mbed SDFileSystem VS1053
main.cpp@2:138538acac01, 2018-12-16 (annotated)
- Committer:
- maner1256
- Date:
- Sun Dec 16 13:06:34 2018 +0000
- Revision:
- 2:138538acac01
- Parent:
- 1:f7477dd40643
hii
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
silis | 0:610f985fb40a | 1 | #include "mbed.h" |
maner1256 | 2:138538acac01 | 2 | #include "string" |
maner1256 | 2:138538acac01 | 3 | #include "player.h" |
maner1256 | 2:138538acac01 | 4 | #include "SDFileSystem.h" |
maner1256 | 2:138538acac01 | 5 | //Player mp3 |
maner1256 | 2:138538acac01 | 6 | SDFileSystem sd(D11, D12, D13, D9, "sd"); // the pinout on the mbed Cool |
maner1256 | 2:138538acac01 | 7 | vs10xx vs1053(D11, D12, D13, D6, D7, D2, D8);//mosi,miso,sclk,xcs,xdcs,dreq,xreset |
maner1256 | 2:138538acac01 | 8 | playerStatetype playerState; |
maner1256 | 2:138538acac01 | 9 | static unsigned char fileBuf[32768]; |
maner1256 | 2:138538acac01 | 10 | unsigned char *bufptr; |
maner1256 | 2:138538acac01 | 11 | char green; |
maner1256 | 2:138538acac01 | 12 | char list[20][50]; //song list |
maner1256 | 2:138538acac01 | 13 | extern playerStatetype playerState; |
maner1256 | 2:138538acac01 | 14 | // |
maner1256 | 2:138538acac01 | 15 | DigitalOut pinout(PC_4); |
maner1256 | 2:138538acac01 | 16 | //Serial |
maner1256 | 2:138538acac01 | 17 | Serial pc(USBTX, USBRX); |
maner1256 | 2:138538acac01 | 18 | Serial sensor_node(PA_15, PB_7); |
maner1256 | 2:138538acac01 | 19 | Serial nextion(PC_6,PA_12); |
maner1256 | 2:138538acac01 | 20 | int input; |
maner1256 | 2:138538acac01 | 21 | int data_buffer[20]; |
jackcom | 1:f7477dd40643 | 22 | |
maner1256 | 2:138538acac01 | 23 | //DATA |
maner1256 | 2:138538acac01 | 24 | struct DATA |
maner1256 | 2:138538acac01 | 25 | { |
maner1256 | 2:138538acac01 | 26 | int height; |
maner1256 | 2:138538acac01 | 27 | int weight; |
maner1256 | 2:138538acac01 | 28 | int sys; |
maner1256 | 2:138538acac01 | 29 | int dia; |
maner1256 | 2:138538acac01 | 30 | int hr; |
maner1256 | 2:138538acac01 | 31 | int bp_status; // BP error |
maner1256 | 2:138538acac01 | 32 | int pattern; // led ring pettern 97, 98, 99, ... |
maner1256 | 2:138538acac01 | 33 | int data_status; //0 = not ready to push to cloud |
maner1256 | 2:138538acac01 | 34 | |
maner1256 | 2:138538acac01 | 35 | }; |
maner1256 | 2:138538acac01 | 36 | struct DATA measured_data; |
jackcom | 1:f7477dd40643 | 37 | |
maner1256 | 2:138538acac01 | 38 | void depacket(struct DATA &input); |
maner1256 | 2:138538acac01 | 39 | void print_data(struct DATA &input); |
jackcom | 1:f7477dd40643 | 40 | |
maner1256 | 2:138538acac01 | 41 | void write_rgb(int pattern){sensor_node.printf("%c",pattern);} |
maner1256 | 2:138538acac01 | 42 | // mp3 function |
maner1256 | 2:138538acac01 | 43 | void begin(void) |
maner1256 | 2:138538acac01 | 44 | { |
maner1256 | 2:138538acac01 | 45 | DirHandle *dir; |
maner1256 | 2:138538acac01 | 46 | struct dirent *ptr; |
maner1256 | 2:138538acac01 | 47 | FileHandle *fp; |
maner1256 | 2:138538acac01 | 48 | |
maner1256 | 2:138538acac01 | 49 | vs1053.reset(); |
maner1256 | 2:138538acac01 | 50 | dir = opendir("/sd"); |
maner1256 | 2:138538acac01 | 51 | printf("\r\n**********playing list**********\r\n"); |
maner1256 | 2:138538acac01 | 52 | unsigned char i = 0,j=0; |
maner1256 | 2:138538acac01 | 53 | while(((ptr = dir->readdir()) != NULL)&&(i <20)) |
maner1256 | 2:138538acac01 | 54 | { |
maner1256 | 2:138538acac01 | 55 | if(strstr(ptr->d_name,".mp3")||strstr(ptr->d_name,".MP3")) |
maner1256 | 2:138538acac01 | 56 | { |
maner1256 | 2:138538acac01 | 57 | fp =sd.open(ptr->d_name, O_RDONLY); |
maner1256 | 2:138538acac01 | 58 | if(fp != NULL) |
maner1256 | 2:138538acac01 | 59 | { |
maner1256 | 2:138538acac01 | 60 | char *byte = ptr->d_name; |
maner1256 | 2:138538acac01 | 61 | j=0; |
maner1256 | 2:138538acac01 | 62 | while(*byte){ |
maner1256 | 2:138538acac01 | 63 | list[i][j++] = *byte++; |
maner1256 | 2:138538acac01 | 64 | green=i; |
maner1256 | 2:138538acac01 | 65 | } |
maner1256 | 2:138538acac01 | 66 | pc.printf("%2d . %s\r\n", i,list[i++]); |
maner1256 | 2:138538acac01 | 67 | //fp->close(); |
maner1256 | 2:138538acac01 | 68 | } |
maner1256 | 2:138538acac01 | 69 | } |
maner1256 | 2:138538acac01 | 70 | } |
maner1256 | 2:138538acac01 | 71 | dir->closedir(); |
maner1256 | 2:138538acac01 | 72 | } |
maner1256 | 2:138538acac01 | 73 | void stop(void){ |
maner1256 | 2:138538acac01 | 74 | playerState =PS_STOP; |
maner1256 | 2:138538acac01 | 75 | } |
maner1256 | 2:138538acac01 | 76 | |
jackcom | 1:f7477dd40643 | 77 | void playFile(char *file) { |
jackcom | 1:f7477dd40643 | 78 | int bytes; // How many bytes in buffer left |
maner1256 | 2:138538acac01 | 79 | char n; |
jackcom | 1:f7477dd40643 | 80 | |
maner1256 | 2:138538acac01 | 81 | playerState = PS_PLAY; |
maner1256 | 2:138538acac01 | 82 | |
maner1256 | 2:138538acac01 | 83 | vs1053.setFreq(24000000); //hight speed |
maner1256 | 2:138538acac01 | 84 | |
jackcom | 1:f7477dd40643 | 85 | FileHandle *fp =sd.open(file, O_RDONLY); |
jackcom | 1:f7477dd40643 | 86 | |
jackcom | 1:f7477dd40643 | 87 | if(fp == NULL) { |
jackcom | 1:f7477dd40643 | 88 | printf("Could not open %s\r\n",file); |
maner1256 | 2:138538acac01 | 89 | |
jackcom | 1:f7477dd40643 | 90 | } |
jackcom | 1:f7477dd40643 | 91 | else |
jackcom | 1:f7477dd40643 | 92 | { |
jackcom | 1:f7477dd40643 | 93 | printf("Playing %s ...\r\n",file); |
jackcom | 1:f7477dd40643 | 94 | |
jackcom | 1:f7477dd40643 | 95 | /* Main playback loop */ |
maner1256 | 2:138538acac01 | 96 | while((bytes = fp->read(fileBuf,32768)) > 0) { |
maner1256 | 2:138538acac01 | 97 | while((bytes = fp->read(fileBuf,32000)) > 0) { |
jackcom | 1:f7477dd40643 | 98 | { |
jackcom | 1:f7477dd40643 | 99 | bufptr = fileBuf; |
maner1256 | 2:138538acac01 | 100 | // actual audio data gets sent to VS10xx. |
maner1256 | 2:138538acac01 | 101 | while(bytes > 0) |
maner1256 | 2:138538acac01 | 102 | { |
maner1256 | 2:138538acac01 | 103 | n = (bytes < 32)?bytes:32; |
maner1256 | 2:138538acac01 | 104 | vs1053.writeData(bufptr,n); |
maner1256 | 2:138538acac01 | 105 | bytes -= n; |
maner1256 | 2:138538acac01 | 106 | bufptr += n; |
maner1256 | 2:138538acac01 | 107 | |
maner1256 | 2:138538acac01 | 108 | } |
maner1256 | 2:138538acac01 | 109 | uint8_t vol = 0x00;//set vlume |
maner1256 | 2:138538acac01 | 110 | vs1053.setVolume(vol); //set vlume |
maner1256 | 2:138538acac01 | 111 | |
maner1256 | 2:138538acac01 | 112 | if(playerState != PS_PLAY) //stop |
maner1256 | 2:138538acac01 | 113 | { |
maner1256 | 2:138538acac01 | 114 | fp->close(); |
maner1256 | 2:138538acac01 | 115 | vs1053.softReset(); |
maner1256 | 2:138538acac01 | 116 | } |
maner1256 | 2:138538acac01 | 117 | |
maner1256 | 2:138538acac01 | 118 | } |
maner1256 | 2:138538acac01 | 119 | } |
jackcom | 1:f7477dd40643 | 120 | } |
jackcom | 1:f7477dd40643 | 121 | } |
maner1256 | 2:138538acac01 | 122 | |
maner1256 | 2:138538acac01 | 123 | } |
maner1256 | 2:138538acac01 | 124 | //// end mp3 |
maner1256 | 2:138538acac01 | 125 | |
maner1256 | 2:138538acac01 | 126 | /// nextion function |
maner1256 | 2:138538acac01 | 127 | void end(void) |
maner1256 | 2:138538acac01 | 128 | { |
maner1256 | 2:138538acac01 | 129 | nextion.putc(0xff); |
maner1256 | 2:138538acac01 | 130 | nextion.putc(0xff); |
maner1256 | 2:138538acac01 | 131 | nextion.putc(0xff); |
maner1256 | 2:138538acac01 | 132 | |
maner1256 | 2:138538acac01 | 133 | } |
maner1256 | 2:138538acac01 | 134 | bool printed_0 = 0; |
maner1256 | 2:138538acac01 | 135 | bool printed_1 = 0; |
maner1256 | 2:138538acac01 | 136 | bool printed_2 = 0; |
maner1256 | 2:138538acac01 | 137 | bool printed_3 = 0; |
maner1256 | 2:138538acac01 | 138 | bool printed_4 = 0; |
maner1256 | 2:138538acac01 | 139 | bool printed_5 = 0; |
maner1256 | 2:138538acac01 | 140 | bool printed_6 = 0; |
maner1256 | 2:138538acac01 | 141 | bool printed_7 = 0; |
maner1256 | 2:138538acac01 | 142 | |
maner1256 | 2:138538acac01 | 143 | |
maner1256 | 2:138538acac01 | 144 | void write_page_0(void){//Sam |
maner1256 | 2:138538acac01 | 145 | printed_1 = 0; |
maner1256 | 2:138538acac01 | 146 | printed_2 = 0; |
maner1256 | 2:138538acac01 | 147 | printed_3 = 0; |
maner1256 | 2:138538acac01 | 148 | printed_4 = 0; |
maner1256 | 2:138538acac01 | 149 | printed_5 = 0; |
maner1256 | 2:138538acac01 | 150 | printed_6 = 0; |
maner1256 | 2:138538acac01 | 151 | printed_7 = 0; |
maner1256 | 2:138538acac01 | 152 | if (!printed_0){ |
maner1256 | 2:138538acac01 | 153 | |
maner1256 | 2:138538acac01 | 154 | nextion.printf("page page0"); |
maner1256 | 2:138538acac01 | 155 | playFile("track0.mp3"); |
maner1256 | 2:138538acac01 | 156 | stop(); |
maner1256 | 2:138538acac01 | 157 | printed_0 = 1; |
maner1256 | 2:138538acac01 | 158 | end(); |
maner1256 | 2:138538acac01 | 159 | } |
maner1256 | 2:138538acac01 | 160 | } |
maner1256 | 2:138538acac01 | 161 | void write_page_1(void){//please stand |
maner1256 | 2:138538acac01 | 162 | printed_0 = 0; |
maner1256 | 2:138538acac01 | 163 | printed_2 = 0; |
maner1256 | 2:138538acac01 | 164 | printed_3 = 0; |
maner1256 | 2:138538acac01 | 165 | printed_4 = 0; |
maner1256 | 2:138538acac01 | 166 | printed_5 = 0; |
maner1256 | 2:138538acac01 | 167 | printed_6 = 0; |
maner1256 | 2:138538acac01 | 168 | printed_7 = 0; |
maner1256 | 2:138538acac01 | 169 | if (!printed_1){ |
maner1256 | 2:138538acac01 | 170 | |
maner1256 | 2:138538acac01 | 171 | nextion.printf("page page1"); |
maner1256 | 2:138538acac01 | 172 | playFile("track1.mp3"); |
maner1256 | 2:138538acac01 | 173 | stop(); |
maner1256 | 2:138538acac01 | 174 | printed_1 = 1; |
maner1256 | 2:138538acac01 | 175 | end(); |
maner1256 | 2:138538acac01 | 176 | } |
maner1256 | 2:138538acac01 | 177 | } |
maner1256 | 2:138538acac01 | 178 | |
maner1256 | 2:138538acac01 | 179 | void write_page_2(int height,int weight){//show height |
maner1256 | 2:138538acac01 | 180 | printed_0 = 0; |
maner1256 | 2:138538acac01 | 181 | printed_1 = 0; |
maner1256 | 2:138538acac01 | 182 | printed_3 = 0; |
maner1256 | 2:138538acac01 | 183 | printed_4 = 0; |
maner1256 | 2:138538acac01 | 184 | printed_6 = 0; |
maner1256 | 2:138538acac01 | 185 | printed_7 = 0; |
maner1256 | 2:138538acac01 | 186 | printed_5 = 0; |
maner1256 | 2:138538acac01 | 187 | if (!printed_2){ |
maner1256 | 2:138538acac01 | 188 | nextion.printf("page page2"); |
maner1256 | 2:138538acac01 | 189 | printed_2 = 1; |
maner1256 | 2:138538acac01 | 190 | end(); |
maner1256 | 2:138538acac01 | 191 | } |
maner1256 | 2:138538acac01 | 192 | nextion.printf("height.val=%d",height); |
maner1256 | 2:138538acac01 | 193 | end(); |
maner1256 | 2:138538acac01 | 194 | nextion.printf("weight.val=%d",weight); |
maner1256 | 2:138538acac01 | 195 | end(); |
maner1256 | 2:138538acac01 | 196 | } |
maner1256 | 2:138538acac01 | 197 | |
maner1256 | 2:138538acac01 | 198 | void write_page_3(void){//put right arm |
maner1256 | 2:138538acac01 | 199 | printed_1 = 0; |
maner1256 | 2:138538acac01 | 200 | printed_2 = 0; |
maner1256 | 2:138538acac01 | 201 | printed_0 = 0; |
maner1256 | 2:138538acac01 | 202 | printed_4 = 0; |
maner1256 | 2:138538acac01 | 203 | printed_5 = 0; |
maner1256 | 2:138538acac01 | 204 | printed_6 = 0; |
maner1256 | 2:138538acac01 | 205 | printed_7 = 0; |
maner1256 | 2:138538acac01 | 206 | if (!printed_3){ |
maner1256 | 2:138538acac01 | 207 | nextion.printf("page page3"); |
maner1256 | 2:138538acac01 | 208 | playFile("track3.mp3"); |
maner1256 | 2:138538acac01 | 209 | stop(); |
maner1256 | 2:138538acac01 | 210 | printed_3 = 1; |
maner1256 | 2:138538acac01 | 211 | end(); |
maner1256 | 2:138538acac01 | 212 | } |
maner1256 | 2:138538acac01 | 213 | } |
maner1256 | 2:138538acac01 | 214 | |
maner1256 | 2:138538acac01 | 215 | void write_page_4(void){//while blood |
maner1256 | 2:138538acac01 | 216 | printed_1 = 0; |
maner1256 | 2:138538acac01 | 217 | printed_2 = 0; |
maner1256 | 2:138538acac01 | 218 | printed_3 = 0; |
maner1256 | 2:138538acac01 | 219 | printed_0 = 0; |
maner1256 | 2:138538acac01 | 220 | printed_5 = 0; |
maner1256 | 2:138538acac01 | 221 | printed_6 = 0; |
maner1256 | 2:138538acac01 | 222 | printed_7 = 0; |
maner1256 | 2:138538acac01 | 223 | if (!printed_4){ |
maner1256 | 2:138538acac01 | 224 | nextion.printf("page page4"); |
maner1256 | 2:138538acac01 | 225 | playFile("track4.mp3"); |
maner1256 | 2:138538acac01 | 226 | stop(); |
maner1256 | 2:138538acac01 | 227 | printed_4 = 1; |
maner1256 | 2:138538acac01 | 228 | end(); |
maner1256 | 2:138538acac01 | 229 | } |
jackcom | 1:f7477dd40643 | 230 | } |
jackcom | 1:f7477dd40643 | 231 | |
maner1256 | 2:138538acac01 | 232 | void write_page_5(int sys,int dia,int pulse){//show blood |
maner1256 | 2:138538acac01 | 233 | printed_1 = 0; |
maner1256 | 2:138538acac01 | 234 | printed_2 = 0; |
maner1256 | 2:138538acac01 | 235 | printed_3 = 0; |
maner1256 | 2:138538acac01 | 236 | printed_4 = 0; |
maner1256 | 2:138538acac01 | 237 | printed_0 = 0; |
maner1256 | 2:138538acac01 | 238 | printed_6 = 0; |
maner1256 | 2:138538acac01 | 239 | printed_7 = 0; |
maner1256 | 2:138538acac01 | 240 | if (!printed_5){ |
maner1256 | 2:138538acac01 | 241 | nextion.printf("page page5"); |
maner1256 | 2:138538acac01 | 242 | printed_5 = 1; |
maner1256 | 2:138538acac01 | 243 | end(); |
maner1256 | 2:138538acac01 | 244 | } |
maner1256 | 2:138538acac01 | 245 | nextion.printf("sys.val=%d",sys); |
maner1256 | 2:138538acac01 | 246 | end(); |
maner1256 | 2:138538acac01 | 247 | nextion.printf("dia.val=%d",dia); |
maner1256 | 2:138538acac01 | 248 | end(); |
maner1256 | 2:138538acac01 | 249 | nextion.printf("pulse.val=%d",pulse); |
maner1256 | 2:138538acac01 | 250 | end(); |
maner1256 | 2:138538acac01 | 251 | } |
maner1256 | 2:138538acac01 | 252 | |
maner1256 | 2:138538acac01 | 253 | void write_page_6(void){//blood failed |
maner1256 | 2:138538acac01 | 254 | printed_1 = 0; |
maner1256 | 2:138538acac01 | 255 | printed_2 = 0; |
maner1256 | 2:138538acac01 | 256 | printed_3 = 0; |
maner1256 | 2:138538acac01 | 257 | printed_4 = 0; |
maner1256 | 2:138538acac01 | 258 | printed_5 = 0; |
maner1256 | 2:138538acac01 | 259 | printed_0 = 0; |
maner1256 | 2:138538acac01 | 260 | printed_7 = 0; |
maner1256 | 2:138538acac01 | 261 | if (!printed_6){ |
maner1256 | 2:138538acac01 | 262 | |
maner1256 | 2:138538acac01 | 263 | nextion.printf("page page6"); |
maner1256 | 2:138538acac01 | 264 | playFile("track6.mp3"); |
maner1256 | 2:138538acac01 | 265 | stop(); |
maner1256 | 2:138538acac01 | 266 | printed_6 = 1; |
maner1256 | 2:138538acac01 | 267 | end(); |
maner1256 | 2:138538acac01 | 268 | } |
maner1256 | 2:138538acac01 | 269 | } |
maner1256 | 2:138538acac01 | 270 | |
maner1256 | 2:138538acac01 | 271 | void write_page_7(void){//see you |
maner1256 | 2:138538acac01 | 272 | printed_1 = 0; |
maner1256 | 2:138538acac01 | 273 | printed_2 = 0; |
maner1256 | 2:138538acac01 | 274 | printed_3 = 0; |
maner1256 | 2:138538acac01 | 275 | printed_4 = 0; |
maner1256 | 2:138538acac01 | 276 | printed_5 = 0; |
maner1256 | 2:138538acac01 | 277 | printed_6 = 0; |
maner1256 | 2:138538acac01 | 278 | printed_0 = 0; |
maner1256 | 2:138538acac01 | 279 | if (!printed_7){ |
maner1256 | 2:138538acac01 | 280 | |
maner1256 | 2:138538acac01 | 281 | nextion.printf("page page7"); |
maner1256 | 2:138538acac01 | 282 | playFile("track7.mp3"); |
maner1256 | 2:138538acac01 | 283 | stop(); |
maner1256 | 2:138538acac01 | 284 | printed_7 = 1; |
maner1256 | 2:138538acac01 | 285 | end(); |
maner1256 | 2:138538acac01 | 286 | } |
maner1256 | 2:138538acac01 | 287 | } |
maner1256 | 2:138538acac01 | 288 | //// end nextion |
maner1256 | 2:138538acac01 | 289 | |
silis | 0:610f985fb40a | 290 | |
silis | 0:610f985fb40a | 291 | int main() { |
maner1256 | 2:138538acac01 | 292 | |
maner1256 | 2:138538acac01 | 293 | bool debug = 1; |
maner1256 | 2:138538acac01 | 294 | begin(); |
maner1256 | 2:138538acac01 | 295 | while(1){ |
maner1256 | 2:138538acac01 | 296 | write_page_3(); |
maner1256 | 2:138538acac01 | 297 | |
maner1256 | 2:138538acac01 | 298 | depacket(measured_data); |
maner1256 | 2:138538acac01 | 299 | if (debug) |
maner1256 | 2:138538acac01 | 300 | print_data(measured_data); |
maner1256 | 2:138538acac01 | 301 | write_rgb(measured_data.pattern); |
maner1256 | 2:138538acac01 | 302 | |
maner1256 | 2:138538acac01 | 303 | if (measured_data.data_status == 0){ |
maner1256 | 2:138538acac01 | 304 | write_page_0(); |
maner1256 | 2:138538acac01 | 305 | } |
maner1256 | 2:138538acac01 | 306 | else if (measured_data.data_status == 1){ |
maner1256 | 2:138538acac01 | 307 | write_page_1(); |
maner1256 | 2:138538acac01 | 308 | } |
maner1256 | 2:138538acac01 | 309 | else if (measured_data.data_status == 2){ |
maner1256 | 2:138538acac01 | 310 | write_page_2(measured_data.height, measured_data.weight); |
maner1256 | 2:138538acac01 | 311 | } |
maner1256 | 2:138538acac01 | 312 | else if (measured_data.data_status == 3){ |
maner1256 | 2:138538acac01 | 313 | write_page_3(); |
maner1256 | 2:138538acac01 | 314 | input=nextion.getc(); |
maner1256 | 2:138538acac01 | 315 | if(input==148){ |
maner1256 | 2:138538acac01 | 316 | pinout=1; |
maner1256 | 2:138538acac01 | 317 | wait(0.5); |
maner1256 | 2:138538acac01 | 318 | pinout=0; |
maner1256 | 2:138538acac01 | 319 | //pc.printf("a\n"); |
maner1256 | 2:138538acac01 | 320 | } |
maner1256 | 2:138538acac01 | 321 | } |
maner1256 | 2:138538acac01 | 322 | else if (measured_data.data_status == 4){ |
maner1256 | 2:138538acac01 | 323 | write_page_4(); |
maner1256 | 2:138538acac01 | 324 | } |
maner1256 | 2:138538acac01 | 325 | else if (measured_data.data_status == 5){ |
maner1256 | 2:138538acac01 | 326 | write_page_5(measured_data.sys, measured_data.dia, measured_data.hr); |
maner1256 | 2:138538acac01 | 327 | } |
maner1256 | 2:138538acac01 | 328 | else if (measured_data.data_status == 6){ |
maner1256 | 2:138538acac01 | 329 | write_page_6(); |
maner1256 | 2:138538acac01 | 330 | } |
maner1256 | 2:138538acac01 | 331 | |
silis | 0:610f985fb40a | 332 | } |
maner1256 | 2:138538acac01 | 333 | } |
maner1256 | 2:138538acac01 | 334 | |
maner1256 | 2:138538acac01 | 335 | void depacket(struct DATA &input){ |
maner1256 | 2:138538acac01 | 336 | if (sensor_node.readable()){ |
maner1256 | 2:138538acac01 | 337 | |
maner1256 | 2:138538acac01 | 338 | int temp =sensor_node.getc(); |
maner1256 | 2:138538acac01 | 339 | //if (temp == 255){ |
maner1256 | 2:138538acac01 | 340 | int cnt = 0; |
maner1256 | 2:138538acac01 | 341 | while(1){ |
maner1256 | 2:138538acac01 | 342 | data_buffer[cnt]=sensor_node.getc(); |
maner1256 | 2:138538acac01 | 343 | if (cnt == 8)break; |
maner1256 | 2:138538acac01 | 344 | if (data_buffer[cnt] == 255)cnt = 0; |
maner1256 | 2:138538acac01 | 345 | else if (data_buffer[cnt] != 255)cnt++; |
maner1256 | 2:138538acac01 | 346 | } |
maner1256 | 2:138538acac01 | 347 | measured_data.height = data_buffer[0]; |
maner1256 | 2:138538acac01 | 348 | measured_data.weight = data_buffer[1]; |
maner1256 | 2:138538acac01 | 349 | input.sys = data_buffer[2]; |
maner1256 | 2:138538acac01 | 350 | input.dia = data_buffer[3]; |
maner1256 | 2:138538acac01 | 351 | input.hr = data_buffer[4]; |
maner1256 | 2:138538acac01 | 352 | input.bp_status = data_buffer[5]; |
maner1256 | 2:138538acac01 | 353 | input.pattern = data_buffer[6]; |
maner1256 | 2:138538acac01 | 354 | input.data_status = data_buffer[7]; |
maner1256 | 2:138538acac01 | 355 | |
maner1256 | 2:138538acac01 | 356 | |
maner1256 | 2:138538acac01 | 357 | } |
maner1256 | 2:138538acac01 | 358 | } |
maner1256 | 2:138538acac01 | 359 | |
maner1256 | 2:138538acac01 | 360 | void print_data(struct DATA &input){ |
maner1256 | 2:138538acac01 | 361 | pc.printf("H : %d ", input.height); |
maner1256 | 2:138538acac01 | 362 | pc.printf("W : %d ", input.weight); |
maner1256 | 2:138538acac01 | 363 | pc.printf("SYS : %d ", input.sys); |
maner1256 | 2:138538acac01 | 364 | pc.printf("DIA : %d ", input.dia); |
maner1256 | 2:138538acac01 | 365 | pc.printf("PUL : %d ", input.hr); |
maner1256 | 2:138538acac01 | 366 | pc.printf("BPs : %d ", input.bp_status); |
maner1256 | 2:138538acac01 | 367 | pc.printf("PAT : %d ", input.pattern); |
maner1256 | 2:138538acac01 | 368 | pc.printf("STATE : %d", input.data_status); |
maner1256 | 2:138538acac01 | 369 | pc.printf("\n"); |
silis | 0:610f985fb40a | 370 | } |