blob: e5bcb644cc5396ec4864d5bf503b625b0906cc0c [file] [log] [blame]
Brian Silverman9dd793b2020-01-31 23:52:21 -08001#include "aos/events/shm_event_loop.h"
2#include "aos/init.h"
3
4#include "y2020/vision/v4l2_reader.h"
5
6namespace frc971 {
7namespace vision {
8namespace {
9
10void CameraReaderMain() {
11 aos::FlatbufferDetachedBuffer<aos::Configuration> config =
12 aos::configuration::ReadConfig("config.json");
13
14 aos::ShmEventLoop event_loop(&config.message());
15 V4L2Reader v4l2_reader(&event_loop, "/dev/video0");
16
17 while (true) {
18 const auto image = v4l2_reader.ReadLatestImage();
19 if (image.empty()) {
20 LOG(INFO) << "No image, sleeping";
21 std::this_thread::sleep_for(std::chrono::milliseconds(10));
22 continue;
23 }
24
25 // Now, process image.
26 // TODO(Brian): Actually process it, rather than just logging its size...
27 LOG(INFO) << image.size();
28 std::this_thread::sleep_for(std::chrono::milliseconds(70));
29
30 v4l2_reader.SendLatestImage();
31 }
32}
33
34} // namespace
35} // namespace vision
36} // namespace frc971
37
38
39int main(int argc, char **argv) {
40 aos::InitGoogle(&argc, &argv);
41 frc971::vision::CameraReaderMain();
42}