Boboter
Loading...
Searching...
No Matches
colorsensor.h
Go to the documentation of this file.
1
7
8#pragma once
9
10#include <driver/i2c_types.h>
11#include "types/rgb_color.h"
12#include "include/log_sources.h"
13
14class Robot;
15
16namespace Device {
18 private:
19 static constexpr const char* TAG = "Device::Colorsensor";
20 static constexpr log_source LOG_SOURCE = LOG_SOURCE_DEVICE_COLORSENSOR;
21
22 static constexpr uint8_t I2C_ADDRESS = 0x29;
23 static constexpr uint32_t I2C_CLOCK_SPEED = 400'000;
24 static constexpr uint8_t TCS34725_DEVICE_ID = 0x44;
25
26 Robot& robot;
27 i2c_master_dev_handle_t device_handle;
28 rgb_color_t color;
29
30 private:
37 void write_register(uint8_t register_address, uint8_t value) const;
38
46 [[nodiscard]] uint8_t read_register(uint8_t register_address) const;
47
48 private:
50
51
52 public:
53 explicit Colorsensor(Robot& robot);
55
59 void initialize();
60
64 void measure();
65
72 [[nodiscard]] rgb_color_t get_color() const { return color; }
73 };
74}
~Colorsensor()
Definition colorsensor.cpp:26
void initialize()
Sets up the necessary I2C channel.
Definition colorsensor.cpp:31
rgb_color_t get_color() const
Gets the color seen on last measurement.
Definition colorsensor.h:72
void measure()
Measures the current sensor values and computes them into color and brightness.
Definition colorsensor.cpp:62
Colorsensor(Robot &robot)
Definition colorsensor.cpp:18
Class containing all the components of the robot.
Definition robot.h:32
log_source
Definition log_sources.h:12
@ LOG_SOURCE_DEVICE_COLORSENSOR
Definition log_sources.h:29
Definition battery.cpp:14
A type for storing a 16-bit RGB color.
Definition rgb_color.h:14