Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(i2c): Add I2cMenu to i2c component #182

Merged
merged 4 commits into from
Mar 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion components/i2c/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
idf_component_register(
INCLUDE_DIRS "include"
REQUIRES "driver" "base_component"
REQUIRES "driver" "base_component" "cli"
)
2 changes: 1 addition & 1 deletion components/i2c/example/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ set(EXTRA_COMPONENT_DIRS

set(
COMPONENTS
"main esptool_py cli i2c logger"
"main esptool_py i2c logger"
CACHE STRING
"List of components to include"
)
Expand Down
23 changes: 18 additions & 5 deletions components/i2c/example/main/i2c_example.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,31 @@ extern "C" void app_main(void) {
logger.info("Starting");

{
#if CONFIG_COMPILER_CXX_EXCEPTIONS || defined(_DOXYGEN_)
//! [i2c menu example]
espp::I2c i2c({
.port = I2C_NUM_0,
.sda_io_num = (gpio_num_t)CONFIG_EXAMPLE_I2C_SDA_GPIO,
.scl_io_num = (gpio_num_t)CONFIG_EXAMPLE_I2C_SCL_GPIO,
.sda_pullup_en = GPIO_PULLUP_ENABLE,
.scl_pullup_en = GPIO_PULLUP_ENABLE,
.log_level = espp::Logger::Verbosity::INFO,
});
// now make a menu for the auth object
I2cMenu i2c_menu(i2c);
// now make a menu for it
espp::I2cMenu i2c_menu(i2c);
cli::Cli cli(i2c_menu.get());
cli::SetColor();
cli.ExitAction([](auto &out) { out << "Goodbye and thanks for all the fish.\n"; });
espp::Cli input(cli);
input.SetInputHistorySize(10);

input.Start(); // As this is in the primary thread, we hold here until cli is complete.
//! [i2c menu example]
input.Start(); // As this is in the primary thread, we hold here until cli
// is complete. This is a blocking call and will not return until
// the user enters the `exit` command.
//! [i2c menu example]
#else
logger.warn("C++ exceptions are not enabled, skipping I2C menu example");
#endif // CONFIG_COMPILER_CXX_EXCEPTIONS || defined(_DOXYGEN_)
}

{
Expand All @@ -39,10 +47,15 @@ extern "C" void app_main(void) {
.port = I2C_NUM_0,
.sda_io_num = (gpio_num_t)CONFIG_EXAMPLE_I2C_SDA_GPIO,
.scl_io_num = (gpio_num_t)CONFIG_EXAMPLE_I2C_SCL_GPIO,
.sda_pullup_en = GPIO_PULLUP_ENABLE,
.scl_pullup_en = GPIO_PULLUP_ENABLE,
});

// probe the bus for all addresses and store the ones that were found /
// responded
// responded. NOTE: this will take a while to run, as it will probe all 128
// possible addresses and the hard-coded timeout on the I2C (inside ESP-IDF)
// is 1 second (I2C_CMD_ALIVE_INTERVAL_TICK within
// esp-idf/components/driver/i2c/i2c.c).
std::vector<uint8_t> found_addresses;
for (uint8_t address = 0; address < 128; address++) {
if (i2c.probe_device(address)) {
Expand Down
169 changes: 0 additions & 169 deletions components/i2c/example/main/i2c_menu.hpp

This file was deleted.

Loading
Loading