QQQ / QQQCAM

Dependents:   qqq_izu_main_test

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers QQQCAM.cpp Source File

QQQCAM.cpp

00001 #include "mbed.h"
00002 #include "QQQCAM.h"
00003 
00004 QQQCAM::QQQCAM(Serial &cam_serial)
00005 {
00006     _serial = &cam_serial;
00007     _serial->attach(callback(this, &QQQCAM::receive), Serial::RxIrq);
00008 }
00009 
00010 void QQQCAM::receive()
00011 {
00012     char c = _serial->getc();
00013     if(c == '$') {
00014         index = 0;
00015         flag = 1;
00016     }
00017     if(flag == 1) {
00018         rx_buf[index] = c;
00019         if(c == '\n') {
00020             rx_buf[index + 1] = '\0';
00021             flag = 2;
00022         } else {
00023             index++;
00024         }
00025     }
00026     if(flag == 2) {
00027         sscanf(rx_buf, "$CAM,%f", &rate);
00028         flag = 0;
00029     }
00030 }
00031 
00032 float QQQCAM::get_rate(){
00033     return rate;
00034 }