Add a process which reads frames from the camera
Tested on a pi, and it captures something. Don't have a good way to look
if the data makes any sense or not.
Change-Id: I40c8c4e395fcf468f4381250c7b75a5e4bee0cc4
diff --git a/y2020/vision/camera_reader.cc b/y2020/vision/camera_reader.cc
new file mode 100644
index 0000000..e5bcb64
--- /dev/null
+++ b/y2020/vision/camera_reader.cc
@@ -0,0 +1,42 @@
+#include "aos/events/shm_event_loop.h"
+#include "aos/init.h"
+
+#include "y2020/vision/v4l2_reader.h"
+
+namespace frc971 {
+namespace vision {
+namespace {
+
+void CameraReaderMain() {
+ aos::FlatbufferDetachedBuffer<aos::Configuration> config =
+ aos::configuration::ReadConfig("config.json");
+
+ aos::ShmEventLoop event_loop(&config.message());
+ V4L2Reader v4l2_reader(&event_loop, "/dev/video0");
+
+ while (true) {
+ const auto image = v4l2_reader.ReadLatestImage();
+ if (image.empty()) {
+ LOG(INFO) << "No image, sleeping";
+ std::this_thread::sleep_for(std::chrono::milliseconds(10));
+ continue;
+ }
+
+ // Now, process image.
+ // TODO(Brian): Actually process it, rather than just logging its size...
+ LOG(INFO) << image.size();
+ std::this_thread::sleep_for(std::chrono::milliseconds(70));
+
+ v4l2_reader.SendLatestImage();
+ }
+}
+
+} // namespace
+} // namespace vision
+} // namespace frc971
+
+
+int main(int argc, char **argv) {
+ aos::InitGoogle(&argc, &argv);
+ frc971::vision::CameraReaderMain();
+}