Raspberry Pi Camera
Diff: QQQCAM.cpp
- Revision:
- 0:7a6b30b678c7
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/QQQCAM.cpp Sat Sep 19 09:58:31 2020 +0000 @@ -0,0 +1,34 @@ +#include "mbed.h" +#include "QQQCAM.h" + +QQQCAM::QQQCAM(Serial &cam_serial) +{ + _serial = &cam_serial; + _serial->attach(callback(this, &QQQCAM::receive), Serial::RxIrq); +} + +void QQQCAM::receive() +{ + char c = _serial->getc(); + if(c == '$') { + index = 0; + flag = 1; + } + if(flag == 1) { + rx_buf[index] = c; + if(c == '\n') { + rx_buf[index + 1] = '\0'; + flag = 2; + } else { + index++; + } + } + if(flag == 2) { + sscanf(rx_buf, "$CAM,%f", &rate); + flag = 0; + } +} + +float QQQCAM::get_rate(){ + return rate; +} \ No newline at end of file