-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
df91b4c
commit 6215364
Showing
4 changed files
with
56 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |