Skip to content

Commit

Permalink
Add PWM Dimmer multi-press and ledmask support
Browse files Browse the repository at this point in the history
  • Loading branch information
pcdiem committed Oct 20, 2020
1 parent 32648da commit f075a89
Show file tree
Hide file tree
Showing 8 changed files with 343 additions and 318 deletions.
4 changes: 2 additions & 2 deletions tasmota/my_user_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -465,8 +465,8 @@
#define DEVICE_GROUPS_ADDRESS 239,255,250,250 // Device groups multicast address
#define DEVICE_GROUPS_PORT 4447 // Device groups multicast port
#define USE_DEVICE_GROUPS_SEND // Add support for the DevGroupSend command (+0k6 code)
#define USE_PWM_DIMMER // Add support for MJ-SD01/acenx/NTONPOWER PWM dimmers (+2k2 code, DGR=0k4)
#define USE_PWM_DIMMER_REMOTE // Add support for remote switches to PWM Dimmer (requires USE_DEVICE_GROUPS) (+0k9 code)
#define USE_PWM_DIMMER // Add support for MJ-SD01/acenx/NTONPOWER PWM dimmers (+2k3 code, DGR=0k7)
#define USE_PWM_DIMMER_REMOTE // Add support for remote switches to PWM Dimmer (requires USE_DEVICE_GROUPS) (+0k6 code)
//#define USE_KEELOQ // Add support for Jarolift rollers by Keeloq algorithm (+4k5 code)
#define USE_SONOFF_D1 // Add support for Sonoff D1 Dimmer (+0k7 code)

Expand Down
6 changes: 6 additions & 0 deletions tasmota/support_command.ino
Original file line number Diff line number Diff line change
Expand Up @@ -1885,7 +1885,13 @@ void CmndLedState(void) {

void CmndLedMask(void) {
if (XdrvMailbox.data_len > 0) {
#ifdef USE_PWM_DIMMER
PWMDimmerSetBrightnessLeds(0);
#endif // USE_PWM_DIMMER
Settings.ledmask = XdrvMailbox.payload;
#ifdef USE_PWM_DIMMER
PWMDimmerSetBrightnessLeds(-1);
#endif // USE_PWM_DIMMER
}
char stemp1[TOPSZ];
snprintf_P(stemp1, sizeof(stemp1), PSTR("%d (0x%04X)"), Settings.ledmask, Settings.ledmask);
Expand Down
21 changes: 10 additions & 11 deletions tasmota/support_device_groups.ino
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ struct device_group {
uint16_t ack_check_interval;
uint8_t message_header_length;
uint8_t initial_status_requests_remaining;
bool local;
char group_name[TOPSZ];
uint8_t message[128];
struct device_group_member * device_group_members;
Expand Down Expand Up @@ -157,8 +156,6 @@ void DeviceGroupsInit(void)
device_group->last_full_status_sequence = -1;
}

device_groups[0].local = true;

// If both in and out shared items masks are 0, assume they're unitialized and initialize them.
if (!Settings.device_group_share_in && !Settings.device_group_share_out) {
Settings.device_group_share_in = Settings.device_group_share_out = 0xffffffff;
Expand Down Expand Up @@ -296,6 +293,7 @@ void SendReceiveDeviceGroupMessage(struct device_group * device_group, struct de
*/
XdrvMailbox.command = nullptr; // Indicates the source is a device group update
XdrvMailbox.index = flags | message_sequence << 16;
if (device_group_index == 0 && first_device_group_is_local) XdrvMailbox.index |= DGR_FLAG_LOCAL;
XdrvMailbox.topic = (char *)&device_group_index;
if (flags & (DGR_FLAG_MORE_TO_COME | DGR_FLAG_DIRECT)) skip_light_fade = true;

Expand Down Expand Up @@ -388,10 +386,12 @@ void SendReceiveDeviceGroupMessage(struct device_group * device_group, struct de
switch (item) {
case DGR_ITEM_POWER:
if (Settings.flag4.multiple_device_groups) { // SetOption88 - Enable relays in separate device groups
bool on = (value & 1);
if (on != (power & (1 << device_group_index))) ExecuteCommandPower(device_group_index + 1, (on ? POWER_ON : POWER_OFF), SRC_REMOTE);
if (device_group_index < devices_present) {
bool on = (value & 1);
if (on != (power & (1 << device_group_index))) ExecuteCommandPower(device_group_index + 1, (on ? POWER_ON : POWER_OFF), SRC_REMOTE);
}
}
else if (device_group->local) {
else if (XdrvMailbox.index & DGR_FLAG_LOCAL) {
uint8_t mask_devices = value >> 24;
if (mask_devices > devices_present) mask_devices = devices_present;
for (uint32_t i = 0; i < mask_devices; i++) {
Expand Down Expand Up @@ -505,10 +505,9 @@ bool _SendDeviceGroupMessage(uint8_t device_group_index, DevGroupMessageType mes
building_status_message = true;

// Call the drivers to build the status update.
if (device_group->local || Settings.flag4.multiple_device_groups) { // SetOption88 - Enable relays in separate device groups
SendDeviceGroupMessage(device_group_index, DGR_MSGTYP_PARTIAL_UPDATE, DGR_ITEM_POWER, power);
}
XdrvMailbox.index = device_group_index << 16;
SendDeviceGroupMessage(device_group_index, DGR_MSGTYP_PARTIAL_UPDATE, DGR_ITEM_POWER, power);
XdrvMailbox.index = 0;
if (device_group_index == 0 && first_device_group_is_local) XdrvMailbox.index = DGR_FLAG_LOCAL;
XdrvMailbox.command_code = DGR_ITEM_STATUS;
XdrvMailbox.topic = (char *)&device_group_index;
XdrvCall(FUNC_DEVICE_GROUP_ITEM);
Expand Down Expand Up @@ -680,7 +679,7 @@ bool _SendDeviceGroupMessage(uint8_t device_group_index, DevGroupMessageType mes
*message_ptr++ = value & 0xff;
value >>= 8;
// For the power item, the device count is overlayed onto the highest 8 bits.
if (item == DGR_ITEM_POWER && !value) value = (device_group_index == 0 ? devices_present : 1);
if (item == DGR_ITEM_POWER && !value) value = (device_group_index == 0 && first_device_group_is_local ? devices_present : 1);
*message_ptr++ = value;
}
}
Expand Down
3 changes: 3 additions & 0 deletions tasmota/support_tasmota.ino
Original file line number Diff line number Diff line change
Expand Up @@ -492,6 +492,9 @@ bool SendKey(uint32_t key, uint32_t device, uint32_t state)
XdrvMailbox.payload = device_save << 24 | key << 16 | state << 8 | device;
XdrvCall(FUNC_ANY_KEY);
XdrvMailbox.payload = payload_save;
#ifdef USE_PWM_DIMMER
if (PWM_DIMMER == my_module_type) result = true;
#endif // USE_PWM_DIMMER
return result;
}

Expand Down
2 changes: 1 addition & 1 deletion tasmota/tasmota.h
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ enum SettingsTextIndex { SET_OTAURL,

enum DevGroupMessageType { DGR_MSGTYP_FULL_STATUS, DGR_MSGTYP_PARTIAL_UPDATE, DGR_MSGTYP_UPDATE, DGR_MSGTYP_UPDATE_MORE_TO_COME, DGR_MSGTYP_UPDATE_DIRECT, DGR_MSGTYPE_UPDATE_COMMAND, DGR_MSGTYPFLAG_WITH_LOCAL = 128 };

enum DevGroupMessageFlag { DGR_FLAG_RESET = 1, DGR_FLAG_STATUS_REQUEST = 2, DGR_FLAG_FULL_STATUS = 4, DGR_FLAG_ACK = 8, DGR_FLAG_MORE_TO_COME = 16, DGR_FLAG_DIRECT = 32, DGR_FLAG_ANNOUNCEMENT = 64 };
enum DevGroupMessageFlag { DGR_FLAG_RESET = 1, DGR_FLAG_STATUS_REQUEST = 2, DGR_FLAG_FULL_STATUS = 4, DGR_FLAG_ACK = 8, DGR_FLAG_MORE_TO_COME = 16, DGR_FLAG_DIRECT = 32, DGR_FLAG_ANNOUNCEMENT = 64, DGR_FLAG_LOCAL = 128 };

enum DevGroupItem { DGR_ITEM_EOL, DGR_ITEM_STATUS, DGR_ITEM_FLAGS,
DGR_ITEM_LIGHT_FADE, DGR_ITEM_LIGHT_SPEED, DGR_ITEM_LIGHT_BRI, DGR_ITEM_LIGHT_SCHEME, DGR_ITEM_LIGHT_FIXED_COLOR,
Expand Down
1 change: 1 addition & 0 deletions tasmota/tasmota_globals.h
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,7 @@ const char kWebColors[] PROGMEM =
#define SendDeviceGroupMessage(DEVICE_INDEX, REQUEST_TYPE, ...) _SendDeviceGroupMessage(DEVICE_INDEX, REQUEST_TYPE, __VA_ARGS__, 0)
#define SendLocalDeviceGroupMessage(REQUEST_TYPE, ...) _SendDeviceGroupMessage(0, REQUEST_TYPE, __VA_ARGS__, 0)
uint8_t device_group_count = 0;
bool first_device_group_is_local = true;
#endif // USE_DEVICE_GROUPS

#ifdef DEBUG_TASMOTA_CORE
Expand Down
7 changes: 4 additions & 3 deletions tasmota/xdrv_04_light.ino
Original file line number Diff line number Diff line change
Expand Up @@ -2336,11 +2336,12 @@ void LightHandleDevGroupItem(void)
{
static bool send_state = false;
static bool restore_power = false;
bool more_to_come;
uint32_t value = XdrvMailbox.payload;

#ifdef USE_PWM_DIMMER_REMOTE
if (*XdrvMailbox.topic) return; // Ignore updates from other device groups
if (!(XdrvMailbox.index & DGR_FLAG_LOCAL)) return;
#endif // USE_PWM_DIMMER_REMOTE
bool more_to_come;
uint32_t value = XdrvMailbox.payload;
switch (XdrvMailbox.command_code) {
case DGR_ITEM_EOL:
more_to_come = (XdrvMailbox.index & DGR_FLAG_MORE_TO_COME);
Expand Down
Loading

0 comments on commit f075a89

Please sign in to comment.