Grove driver, I2C migrations, bugfixes and docs (#532)
This commit is contained in:
committed by
GitHub
parent
8dabda2b5b
commit
a35c88c8fd
@@ -1,7 +1,8 @@
|
||||
#include "Tactility/app/i2cscanner/I2cHelpers.h"
|
||||
|
||||
#include <Tactility/StringUtils.h>
|
||||
#include <Tactility/hal/i2c/I2c.h>
|
||||
|
||||
#include <tactility/drivers/i2c_controller.h>
|
||||
|
||||
#include <iomanip>
|
||||
#include <vector>
|
||||
@@ -19,31 +20,36 @@ std::string getAddressText(uint8_t address) {
|
||||
|
||||
std::string getPortNamesForDropdown() {
|
||||
std::vector<std::string> config_names;
|
||||
for (int port = 0; port < I2C_NUM_MAX; ++port) {
|
||||
auto native_port = static_cast<i2c_port_t>(port);
|
||||
if (hal::i2c::isStarted(native_port)) {
|
||||
auto* name = hal::i2c::getName(native_port);
|
||||
if (name != nullptr) {
|
||||
config_names.push_back(name);
|
||||
}
|
||||
device_for_each_of_type(&I2C_CONTROLLER_TYPE, &config_names, [](auto* device, auto* context) {
|
||||
auto* names = static_cast<std::vector<std::string>*>(context);
|
||||
if (device_is_ready(device)) {
|
||||
names->push_back(device->name);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
});
|
||||
return string::join(config_names, "\n");
|
||||
}
|
||||
|
||||
bool getActivePortAtIndex(int32_t index, int32_t& out) {
|
||||
int current_index = -1;
|
||||
for (int port = 0; port < I2C_NUM_MAX; ++port) {
|
||||
auto native_port = static_cast<i2c_port_t>(port);
|
||||
if (hal::i2c::isStarted(native_port)) {
|
||||
current_index++;
|
||||
if (current_index == index) {
|
||||
out = port;
|
||||
return true;
|
||||
bool getActivePortAtIndex(int32_t index, struct Device** out) {
|
||||
struct Context {
|
||||
int32_t targetIndex;
|
||||
int32_t currentIndex;
|
||||
struct Device* foundDevice;
|
||||
} context = { index, 0, nullptr };
|
||||
|
||||
device_for_each_of_type(&I2C_CONTROLLER_TYPE, &context, [](auto* device, auto* ctx) {
|
||||
auto* c = static_cast<Context*>(ctx);
|
||||
if (device_is_ready(device)) {
|
||||
if (c->currentIndex == c->targetIndex) {
|
||||
c->foundDevice = device;
|
||||
return false;
|
||||
}
|
||||
c->currentIndex++;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
return true;
|
||||
});
|
||||
*out = context.foundDevice;
|
||||
return context.foundDevice != nullptr;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user