Skip to content

Commit

Permalink
Add VEML6040 RGBW sensor
Browse files Browse the repository at this point in the history
  • Loading branch information
SuperJappie08 committed Oct 9, 2024
1 parent df91b4c commit 6215364
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 2 deletions.
4 changes: 3 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ add_library(tmx_cpp
src/modules/SSD1306_oled.cpp
src/sensors.cpp
src/sensors/INA226.cpp
src/sensors/MPU9250.cpp)
src/sensors/MPU9250.cpp
src/sensors/VEML6040.cpp
)

# Link Boost libraries
target_link_libraries(tmx_cpp Boost::system Boost::thread async_serial)
22 changes: 22 additions & 0 deletions include/tmx_cpp/sensors/VEML6040.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#pragma once
#include <functional>
#include "tmx_cpp/sensors/Sensor_t.hpp"

namespace tmx_cpp {

using VEML6040_cb_t = std::function<void(uint16_t red, uint16_t green, uint16_t blue, uint16_t white)>;
class VEML6040_module : public Sensor_type {
public:
std::function<void(std::vector<uint8_t>)> send_module;
VEML6040_module(uint8_t i2c_port, uint8_t address, VEML6040_cb_t data_cb);

virtual std::vector<uint8_t> init_data() override;
virtual void data_callback(std::vector<uint8_t> data) override;
VEML6040_cb_t data_cb;

private:
uint8_t i2c_port = 0;
uint8_t address = 0x10;
};

} // namespace tmx_cpp
2 changes: 1 addition & 1 deletion src/sensors.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,4 @@ void Sensors::callback(std::vector<uint8_t> data) {
uint8_t module_num = data[2];
std::vector<uint8_t> module_data(data.begin() + 4, data.end());
this->sensors[module_num].second(module_data);
}
}
30 changes: 30 additions & 0 deletions src/sensors/VEML6040.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#include <cstdint>
#include <cassert>

#include <tmx_cpp/sensors/VEML6040.hpp>

using namespace tmx_cpp;

VEML6040_module::VEML6040_module(uint8_t i2c_port, uint8_t address, VEML6040_cb_t data_cb):
data_cb(data_cb), i2c_port(i2c_port), address(address) {
assert(this->address == 0x10);
this->type = SENSOR_TYPE::VEML6040;
}

std::vector<uint8_t> VEML6040_module::init_data() {
this->type = SENSOR_TYPE::VEML6040;

// Address is fixed in PICO Firmware and on the Hardware.
return {i2c_port , /*address*/};
}

void VEML6040_module::data_callback(std::vector<uint8_t> data) {
// Get the data from the VEML6040 sensor
assert(data.size() == 8);
uint16_t red = ((uint16_t)data[1] << 8) | ((uint16_t)data[0]);
uint16_t green = ((uint16_t)data[3] << 8) | ((uint16_t)data[2]);
uint16_t blue = ((uint16_t)data[5] << 8) | ((uint16_t)data[4]);
uint16_t white = ((uint16_t)data[7] << 8) | ((uint16_t)data[6]);

data_cb(red, green, blue, white);
}

0 comments on commit 6215364

Please sign in to comment.