Skip to content
Closed
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
1 change: 0 additions & 1 deletion tasmota/my_user_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -1113,7 +1113,6 @@
// #define HX711_CAL_PRECISION 1 // When HX711 calibration is to course, raise this value

//#define USE_DINGTIAN_RELAY // Add support for the Dingian board using 74'595 et 74'165 shift registers
// #define DINGTIAN_INPUTS_INVERTED // Invert input states (Hi => OFF, Low => ON)
Copy link
Owner

@arendst arendst Jan 24, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The removal of this defines breaks legacy support (and current installation).

The "usual way" to handle this is adding a one time test in your new code for setting the correct SetOption based on this define.
This one time test should also set the other SetOption to it's default value before you made this change (as otherwise the legacy functionality would also be broken).

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@arendst How should I implement the one-time migration check? What's the recommended way to detect "first boot after flashing" so the SetOption migration from the legacy DINGTIAN_INPUTS_INVERTED define only runs once?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's tricky and related to version number. It needs to be in the settings.ino file at the end.

I'll do it now based on your PR. Pls do not change anything anymore. Working on it.

// #define DINGTIAN_USE_AS_BUTTON // Inputs as Tasmota's virtual Buttons
// #define DINGTIAN_USE_AS_SWITCH // Inputs as Tasmota's virtual Switches

Expand Down
39 changes: 26 additions & 13 deletions tasmota/tasmota_xdrv_driver/xdrv_90_esp32_dingtian_relay.ino
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
// SetOption133: Inverts 74HC595 shift register outputs at runtime
// SetOption81: Inverts 74HC165 shift register inputs at runtime

#ifdef ESP32
#ifdef USE_DINGTIAN_RELAY
Expand Down Expand Up @@ -55,6 +57,11 @@ struct DINGTIAN_DATA {

uint32_t DingtianReadWrite(uint32_t outputs)
{
// SetOption133: invert outputs (74HC595)
if (Settings->flag5.shift595_invert_outputs) {
outputs = ~outputs;
}

uint32_t inputs = 0;
uint32_t in_bit = 1;

Expand Down Expand Up @@ -82,11 +89,12 @@ uint32_t DingtianReadWrite(uint32_t outputs)
Dingtian->outputs_initialized = true;
}

#ifdef DINGTIAN_INPUTS_INVERTED
return ~inputs;
#else
return inputs;
#endif
// SetOption81: invert inputs (74HC165)
if (Settings->flag3.pcf8574_ports_inverted) {
return ~inputs;
} else {
return inputs;
}
}

/********************************************************************************************************
Expand All @@ -95,22 +103,27 @@ uint32_t DingtianReadWrite(uint32_t outputs)

void DingtianInit(void) {
if (PinUsed(GPIO_DINGTIAN_CLK, GPIO_ANY) && PinUsed(GPIO_DINGTIAN_SDI) && PinUsed(GPIO_DINGTIAN_Q7)
&& (PinUsed(GPIO_DINGTIAN_PL) || PinUsed(GPIO_DINGTIAN_OE)) && PinUsed(GPIO_DINGTIAN_RCK)) {
&& (PinUsed(GPIO_DINGTIAN_PL) || PinUsed(GPIO_DINGTIAN_OE))
&& (PinUsed(GPIO_DINGTIAN_PL) || PinUsed(GPIO_DINGTIAN_RCK))) {
// allocate Dingtian data structure
Dingtian = (struct DINGTIAN_DATA*)calloc(1, sizeof(struct DINGTIAN_DATA));
if (Dingtian) {
// get pins
Dingtian->pin_clk = Pin(GPIO_DINGTIAN_CLK, GPIO_ANY); // shift clock : 595's SCLK & 165's CLK
Dingtian->pin_sdi = Pin(GPIO_DINGTIAN_SDI); // Serial out : 595's SER
Dingtian->pin_q7 = Pin(GPIO_DINGTIAN_Q7); // Serial in : 165's Q7
if (PinUsed(GPIO_DINGTIAN_PL)) Dingtian->pin_pl = Pin(GPIO_DINGTIAN_PL); // Input load : 595's nOE & 165's PL (or SH/LD on some datasheet)
if (PinUsed(GPIO_DINGTIAN_OE)) Dingtian->pin_oe = Pin(GPIO_DINGTIAN_OE); // Output enable : 595's nOE (v3.6.10)
Dingtian->pin_rck = Pin(GPIO_DINGTIAN_RCK); // Output load : 595's RCLK & 165's CLKINH
Dingtian->pin_clk = Pin(GPIO_DINGTIAN_CLK, GPIO_ANY); // shift clock : 595's SCLK & 165's CLK
Dingtian->pin_sdi = Pin(GPIO_DINGTIAN_SDI); // Serial out : 595's SER
Dingtian->pin_q7 = Pin(GPIO_DINGTIAN_Q7); // Serial in : 165's Q7
if (PinUsed(GPIO_DINGTIAN_PL)) Dingtian->pin_pl = Pin(GPIO_DINGTIAN_PL); // Input load : 595's nOE & 165's PL (or SH/LD on some datasheet)
if (PinUsed(GPIO_DINGTIAN_OE)) Dingtian->pin_oe = Pin(GPIO_DINGTIAN_OE); // Output enable : 595's nOE & 165's nCE (v3.6.10)
if (PinUsed(GPIO_DINGTIAN_RCK)) Dingtian->pin_rck = Pin(GPIO_DINGTIAN_RCK); // Output load : 595's RCLK & 165's CLKINH
else Dingtian->pin_rck = Dingtian->pin_pl; // Use PL as RCK if not defined (shared pin boards)
// number of shift registers is the CLK index
Dingtian->count = ((GetPin(Dingtian->pin_clk) - AGPIO(GPIO_DINGTIAN_CLK)) + 1) * 8;

AddLog(LOG_LEVEL_DEBUG, PSTR("DNGT: clk:%d, sdi:%d, q7:%d, pl:%d, oe:%d, rck:%d, count:%d"),
Dingtian->pin_clk, Dingtian->pin_sdi, Dingtian->pin_q7, Dingtian->pin_pl, Dingtian->pin_oe, Dingtian->pin_rck, Dingtian->count);

AddLog(LOG_LEVEL_DEBUG, PSTR("DNGT: SetOption133 (Output invert): %d, SetOption81 (Input invert): %d"),
Settings->flag5.shift595_invert_outputs, Settings->flag3.pcf8574_ports_inverted);

DINGTIAN_SET_OUTPUT(Dingtian->pin_clk, 0);
DINGTIAN_SET_OUTPUT(Dingtian->pin_sdi, 0);
Expand Down Expand Up @@ -280,4 +293,4 @@ bool Xdrv90(uint32_t function) {
}

#endif // USE_DINGTIAN_RELAY
#endif // ESP32
#endif // ESP32