From bc23304a7d9a15c46a6037487db943549c9eeca4 Mon Sep 17 00:00:00 2001 From: Tester23 Date: Tue, 19 Sep 2023 13:58:29 +0200 Subject: [PATCH] add i2c scan command --- docs/README.md | 8 ++++---- src/i2c/drv_i2c_main.c | 28 ++++++++++++++++++++++++++-- 2 files changed, 30 insertions(+), 6 deletions(-) diff --git a/docs/README.md b/docs/README.md index f601a697f..b5cd4c9e6 100644 --- a/docs/README.md +++ b/docs/README.md @@ -15,13 +15,13 @@ Do not add anything here, as it will overwritten with next rebuild. |:------------- |------:| | [IO/Pin Roles](https://github.com/openshwprojects/OpenBK7231T_App/blob/main/docs/ioRoles.md) (79 total) | You can set pin roles in 'Configure Module' section or use one of predefined templates in Web App. For each pin, you also set coresponding channel value. This is needed for modules with multiple relays. If you have 3 relays and 3 buttons, you need to use channel values like 1, 2, and 3. Just enter '1' in the text field, etc. | | [Flags](https://github.com/openshwprojects/OpenBK7231T_App/blob/main/docs/flags.md) (43 total) | Flags are global and allows you to alter behaviour of the device. | -| [Drivers](https://github.com/openshwprojects/OpenBK7231T_App/blob/main/docs/drivers.md) (40 total) | Drivers allows you to control certain peripherals or enable certain features that are off by default. | +| [Drivers](https://github.com/openshwprojects/OpenBK7231T_App/blob/main/docs/drivers.md) (41 total) | Drivers allows you to control certain peripherals or enable certain features that are off by default. | | [Script constants](https://github.com/openshwprojects/OpenBK7231T_App/blob/main/docs/constants.md) (29 total) | Every console command that takes an integer argument supports certain constant expansion. | | [Channel Types](https://github.com/openshwprojects/OpenBK7231T_App/blob/main/docs/channelTypes.md) (41 total) | Channel types are often not required and don't have to be configured, but in some cases they are required for better device control from OpenBeken web panel. Channel types describes the kind of value stored in channel, for example, if you have a Tuya Fan Controller with 3 speeds control, you can set the channel type to LowMidHigh and it will display the correct UI radiobutton on OpenBeken panel.
Some channels have '_div10' or '_div100' sufixes. This is for TuyaMCU. This is needed because TuyaMCU sends values as integers, so it sends, for example, 215 for 21.5C temperature, and we store it internally as 215 and only convert to float for display. | | [FAQ](https://github.com/openshwprojects/OpenBK7231T_App/blob/main/docs/faq.md) (29 total) | Here is a detailed list of questions you may ask. Some information from docs is repeated here. | -| [Console/Script commands](https://github.com/openshwprojects/OpenBK7231T_App/blob/main/docs/commands.md) (279 total) | There are multiple console commands that allow you to automate your devices. Commands can be entered manually in command line, can be send by HTTP (just like in Tasmota), can be send by MQTT and also can be scripted. | +| [Console/Script commands](https://github.com/openshwprojects/OpenBK7231T_App/blob/main/docs/commands.md) (280 total) | There are multiple console commands that allow you to automate your devices. Commands can be entered manually in command line, can be send by HTTP (just like in Tasmota), can be send by MQTT and also can be scripted. | | [Command Examples](https://github.com/openshwprojects/OpenBK7231T_App/blob/main/docs/commandExamples.md) (10 total) | Here you can find some examples of console commands usage | -| [Autoexec.bat examples (configs)](https://github.com/openshwprojects/OpenBK7231T_App/blob/main/docs/autoexecExamples.md) (17 total) | Here you can find examples of autoexec.bat configs. The autoexec.bat file can be created in Web Application, under LittleFS tab, and is run every time device reboots (unless device enters safe mode/AP mode). The autoexec.bat file allows you to create more advanced configs, setup TuyaMCU mappings, etc | +| [Autoexec.bat examples (configs)](https://github.com/openshwprojects/OpenBK7231T_App/blob/main/docs/autoexecExamples.md) (18 total) | Here you can find examples of autoexec.bat configs. The autoexec.bat file can be created in Web Application, under LittleFS tab, and is run every time device reboots (unless device enters safe mode/AP mode). The autoexec.bat file allows you to create more advanced configs, setup TuyaMCU mappings, etc | | [MQTT Topics](https://github.com/openshwprojects/OpenBK7231T_App/blob/main/docs/mqttTopics.md) (25 total) | MQTT topic names and content for incoming and ougoing OBK MQTT publishes | | [Script examples](https://github.com/openshwprojects/OpenBK7231T_App/blob/main/docs/scriptExamples.md) (6 total) | Scripts can be put in autoexec.bat and then they will start automatically on reboot, you can also put script in other LittleFS file and use startScript [fileName] [Label] command to run them. From the firmware point of view, scripts and autoexecs are basically the same thing. There is, however, a little bit more advanced system of execution for scripts which can be written in a form of scripts threads that run over time, can have delays within then, conditional checks and jumps. | -| [Console/Script commands [Extended Edition]](https://github.com/openshwprojects/OpenBK7231T_App/blob/main/docs/commands-extended.md) (279 total) | More details on commands. | +| [Console/Script commands [Extended Edition]](https://github.com/openshwprojects/OpenBK7231T_App/blob/main/docs/commands-extended.md) (280 total) | More details on commands. | diff --git a/src/i2c/drv_i2c_main.c b/src/i2c/drv_i2c_main.c index 02258bb40..4b6276ad5 100644 --- a/src/i2c/drv_i2c_main.c +++ b/src/i2c/drv_i2c_main.c @@ -299,8 +299,28 @@ commandResult_t DRV_I2C_AddDevice_LCM1602(const void *context, const char *cmd, return CMD_RES_OK; } - +// set SoftSDA and SoftSCL pins +// startDriver I2C +// scanI2C Soft commandResult_t DRV_I2C_Scan(const void *context, const char *cmd, const char *args, int cmdFlags) { + const char *i2cModuleStr; + i2cBusType_t busType; + + Tokenizer_TokenizeString(args, 0); + i2cModuleStr = Tokenizer_GetArg(0); + + busType = DRV_I2C_ParseBusType(i2cModuleStr); + + for (int a = 1; a < 128; a ++) { + DRV_I2C_Begin(a, busType); + bool bOk = Soft_I2C_Start(&g_softI2C, (a << 1) + 0); + Soft_I2C_Stop(&g_softI2C); + if (bOk) { + addLogAdv(LOG_INFO, LOG_FEATURE_I2C, "Address 0x%x (dec %i)\n", a, a); + } + rtos_delay_milliseconds(5); + } + return CMD_RES_OK; } @@ -308,13 +328,17 @@ commandResult_t DRV_I2C_Scan(const void *context, const char *cmd, const char *a // // TC74 - I2C temperature sensor - read only single integer value, temperature in C // +/* // TC74 A0 (address type 0) // setChannelType 5 temperature // addI2CDevice_TC74 I2C1 0x48 5 // TC74 A2 (address type 2) // setChannelType 6 temperature // addI2CDevice_TC74 I2C1 0x4A 6 - +// TC74 A5 (address type 5) +setChannelType 6 temperature +addI2CDevice_TC74 Soft 0x4D 6 +*/ // // MCP23017 - I2C 16 bit port expander - both inputs and outputs, right now we use it only as outputs //