MPU6050のサンプルプログラム2

Dependencies:   ConfigFile SDFileSystem mbed

Fork of LAURUS_program by LAURUS

Committer:
ojan
Date:
Thu Jun 11 15:43:07 2015 +0000
Revision:
4:45dc5590abc0
Parent:
1:6cd6d2760856
Child:
16:174daf81eea0
add flow control

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ojan 1:6cd6d2760856 1 #include "mbed.h"
ojan 1:6cd6d2760856 2 #include "GMS6_CR6.h"
ojan 1:6cd6d2760856 3
ojan 1:6cd6d2760856 4 GMS6_CR6::GMS6_CR6(Serial* ps, Serial* pc): p_port(ps), p_pc(pc) {
ojan 1:6cd6d2760856 5 p_port->baud(4800);
ojan 1:6cd6d2760856 6 pointer = 0;
ojan 1:6cd6d2760856 7 INT_flag = 0;
ojan 1:6cd6d2760856 8 p_port->attach(this, &GMS6_CR6::INT_Rx, Serial::RxIrq);
ojan 1:6cd6d2760856 9 }
ojan 1:6cd6d2760856 10
ojan 1:6cd6d2760856 11 GMS6_CR6::~GMS6_CR6() {
ojan 1:6cd6d2760856 12 p_port = NULL;
ojan 1:6cd6d2760856 13 }
ojan 1:6cd6d2760856 14
ojan 1:6cd6d2760856 15 void GMS6_CR6::read() {
ojan 1:6cd6d2760856 16 while(INT_flag);
ojan 1:6cd6d2760856 17 int ret = sscanf(buff2, "$GPGGA,%f,%f,%c,%f,%c,%d,%d",
ojan 4:45dc5590abc0 18 &time, &raw_latitude, &lat_hem, &raw_longitude, &lng_hem, &mode, &Ns);
ojan 1:6cd6d2760856 19 if(!ret) {
ojan 1:6cd6d2760856 20 p_pc->printf("sscanf Error\r\n");
ojan 1:6cd6d2760856 21 return;
ojan 1:6cd6d2760856 22 }
ojan 1:6cd6d2760856 23
ojan 1:6cd6d2760856 24 int deg_lat = (int)raw_latitude / 100;
ojan 1:6cd6d2760856 25 float min_lat = (raw_latitude - (float)(deg_lat*100)) / 60.0f;
ojan 1:6cd6d2760856 26 latitude = (float)deg_lat + min_lat;
ojan 1:6cd6d2760856 27
ojan 1:6cd6d2760856 28 int deg_lng = (int)raw_longitude / 100;
ojan 1:6cd6d2760856 29 float min_lng = (raw_longitude - (float)(deg_lng*100)) / 60.0f;
ojan 1:6cd6d2760856 30 longitude = (float)deg_lng + min_lng;
ojan 1:6cd6d2760856 31
ojan 1:6cd6d2760856 32
ojan 1:6cd6d2760856 33 }
ojan 1:6cd6d2760856 34
ojan 1:6cd6d2760856 35 void GMS6_CR6::INT_Rx() {
ojan 1:6cd6d2760856 36 buff1[pointer] = p_port->getc();
ojan 1:6cd6d2760856 37
ojan 1:6cd6d2760856 38 if(buff1[pointer] != '\r') {
ojan 1:6cd6d2760856 39 pointer = (pointer+1)%BuffSize;
ojan 1:6cd6d2760856 40 } else {
ojan 1:6cd6d2760856 41 if(strstr((const char*)buff1, "GPGGA") != NULL) {
ojan 1:6cd6d2760856 42 buff1[pointer] = '\0';
ojan 1:6cd6d2760856 43 INT_flag = 1;
ojan 1:6cd6d2760856 44 strcpy(buff2, (const char*)buff1);
ojan 1:6cd6d2760856 45 INT_flag = 0;
ojan 1:6cd6d2760856 46 pointer = 0;
ojan 1:6cd6d2760856 47 }
ojan 1:6cd6d2760856 48 }
ojan 1:6cd6d2760856 49 }