SensorLib 0.5.0
Multi-platform sensor driver library for Arduino, PlatformIO, and ESP-IDF
Loading...
Searching...
No Matches
I2CDeviceNoHal.hpp
Go to the documentation of this file.
1
30#pragma once
31#include "DeviceBeginCommon.hpp"
32
34{
35public:
36#if defined(ARDUINO)
46 bool begin(TwoWire &wire, uint8_t addr, int sda = -1, int scl = -1)
47 {
48 return beginLifecycle(addr, COMM_I2C, addr, [&]() {
49 comm = std::make_unique<SensorCommI2C>(wire, addr, sda, scl);
50 return comm && comm->init();
51 });
52 }
53#elif defined(ESP_PLATFORM)
54#if defined(SENSORLIB_USE_I2C_LEGACY)
63 bool begin(i2c_port_t port_num, uint8_t addr, int sda = -1, int scl = -1)
64 {
65 return beginLifecycle(addr, COMM_I2C, addr, [&]() {
66 comm = std::make_unique<SensorCommI2C>(port_num, addr, sda, scl);
67 return comm && comm->init();
68 });
69 }
70#else
77 bool begin(i2c_master_bus_handle_t handle, uint8_t addr)
78 {
79 return beginLifecycle(addr, COMM_I2C, addr, [&]() {
80 comm = std::make_unique<SensorCommI2C>(handle, addr);
81 return comm && comm->init();
82 });
83 }
84#endif
85#endif
94 bool begin(SensorCommCustom::CustomCallback callback, uint8_t addr)
95 {
96 return beginLifecycle(addr, COMM_CUSTOM, addr, [&]() {
97 comm = std::make_unique<SensorCommCustom>(callback, addr);
98 return comm && comm->init();
99 });
100 }
101};
@license MIT License
@ COMM_CUSTOM
@ COMM_I2C
std::unique_ptr< SensorCommBase > comm
bool beginLifecycle(uint8_t addr, uint8_t iface, uint8_t initParam, CreateComm createComm)
bool begin(SensorCommCustom::CustomCallback callback, uint8_t addr)
Initialize the sensor using custom callback interface.
bool(*)(uint8_t addr, uint8_t reg, uint8_t *buf, size_t len, bool writeReg, bool isWrite) CustomCallback