Skip to content

Commit fdf5162

Browse files
Allow modifying the window covering cluster and power source cluster attrs from the M5Stack (#17792)
1 parent 10bb2fd commit fdf5162

File tree

1 file changed

+73
-2
lines changed

1 file changed

+73
-2
lines changed

examples/all-clusters-app/esp32/main/DeviceWithDisplay.cpp

+73-2
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,30 @@ class EditAttributeListModel : public TouchesMatterStackModel
196196
ESP_LOGI(TAG, "SystemMode changed to : %d", n);
197197
app::Clusters::Thermostat::Attributes::OccupiedHeatingSetpoint::Set(1, n);
198198
}
199+
else if (name == "Current Lift")
200+
{
201+
// update the current lift here for hardcoded endpoint 1
202+
ESP_LOGI(TAG, "Current position lift percent 100ths changed to : %d", n * 100);
203+
app::Clusters::WindowCovering::Attributes::CurrentPositionLiftPercent100ths::Set(1, static_cast<uint16_t>(n * 100));
204+
}
205+
else if (name == "Current Tilt")
206+
{
207+
// update the current tilt here for hardcoded endpoint 1
208+
ESP_LOGI(TAG, "Current position tilt percent 100ths changed to : %d", n * 100);
209+
app::Clusters::WindowCovering::Attributes::CurrentPositionTiltPercent100ths::Set(1, static_cast<uint16_t>(n * 100));
210+
}
211+
else if (name == "Opr Status")
212+
{
213+
// update the operational status here for hardcoded endpoint 1
214+
ESP_LOGI(TAG, "Operational status changed to : %d", n);
215+
app::Clusters::WindowCovering::Attributes::OperationalStatus::Set(1, static_cast<uint8_t>(n));
216+
}
217+
else if (name == "Bat remaining")
218+
{
219+
// update the battery percent remaining here for hardcoded endpoint 1
220+
ESP_LOGI(TAG, "Battery percent remaining changed to : %d", n);
221+
app::Clusters::PowerSource::Attributes::BatteryPercentRemaining::Set(1, static_cast<uint8_t>(n * 2));
222+
}
199223
value = buffer;
200224
}
201225
else if (IsBooleanAttribute())
@@ -223,18 +247,47 @@ class EditAttributeListModel : public TouchesMatterStackModel
223247
else
224248
{
225249
auto & name = std::get<0>(attribute);
226-
auto & cluster = std::get<0>(std::get<1>(std::get<1>(devices[deviceIndex])[endpointIndex])[i]);
250+
auto & cluster = std::get<0>(std::get<1>(std::get<1>(devices[deviceIndex])[endpointIndex])[0]);
227251

228252
ESP_LOGI(TAG, "editing attribute as string: '%s' (%s)", value.c_str(), i == 0 ? "+" : "-");
229-
value = (value == "Closed") ? "Open" : "Closed";
230253
ESP_LOGI(TAG, "name and cluster: '%s' (%s)", name.c_str(), cluster.c_str());
231254
if (name == "State" && cluster == "Lock")
232255
{
256+
value = (value == "Closed") ? "Open" : "Closed";
233257
using namespace chip::app::Clusters;
234258
// update the doorlock attribute here
235259
auto attributeValue = value == "Closed" ? DoorLock::DlLockState::kLocked : DoorLock::DlLockState::kUnlocked;
236260
DoorLock::Attributes::LockState::Set(DOOR_LOCK_SERVER_ENDPOINT, attributeValue);
237261
}
262+
else if (name == "Charge level" && cluster == "Power Source")
263+
{
264+
using namespace chip::app::Clusters::PowerSource;
265+
auto attributeValue = BatChargeLevel::kOk;
266+
267+
if (value == "OK")
268+
{
269+
value = "Warning";
270+
attributeValue = BatChargeLevel::kWarning;
271+
}
272+
else if (value == "Warning")
273+
{
274+
value = "Critical";
275+
attributeValue = BatChargeLevel::kCritical;
276+
}
277+
else
278+
{
279+
value = "OK";
280+
attributeValue = BatChargeLevel::kOk;
281+
}
282+
283+
// update the battery charge level here for hardcoded endpoint 1
284+
ESP_LOGI(TAG, "Battery charge level changed to : %u", static_cast<uint8_t>(attributeValue));
285+
app::Clusters::PowerSource::Attributes::BatteryChargeLevel::Set(1, static_cast<uint8_t>(attributeValue));
286+
}
287+
else
288+
{
289+
value = (value == "Closed") ? "Open" : "Closed";
290+
}
238291
}
239292
}
240293
};
@@ -520,6 +573,24 @@ void SetupPretendDevices()
520573
app::Clusters::ColorControl::Attributes::CurrentHue::Set(1, 200);
521574
AddAttribute("Current Saturation\n", "150");
522575
app::Clusters::ColorControl::Attributes::CurrentSaturation::Set(1, 150);
576+
577+
AddDevice("Window Covering");
578+
AddEndpoint("1");
579+
AddCluster("Window Covering");
580+
AddAttribute("Current Lift", "5");
581+
app::Clusters::WindowCovering::Attributes::CurrentPositionLiftPercent100ths::Set(1, static_cast<uint16_t>(5 * 100));
582+
AddAttribute("Current Tilt", "5");
583+
app::Clusters::WindowCovering::Attributes::CurrentPositionTiltPercent100ths::Set(1, static_cast<uint16_t>(5 * 100));
584+
AddAttribute("Opr Status", "0");
585+
app::Clusters::WindowCovering::Attributes::OperationalStatus::Set(1, static_cast<uint8_t>(0));
586+
587+
AddDevice("Battery");
588+
AddEndpoint("1");
589+
AddCluster("Power Source");
590+
AddAttribute("Bat remaining", "70");
591+
app::Clusters::PowerSource::Attributes::BatteryPercentRemaining::Set(1, static_cast<uint8_t>(70 * 2));
592+
AddAttribute("Charge level", "0");
593+
app::Clusters::PowerSource::Attributes::BatteryChargeLevel::Set(1, static_cast<uint8_t>(0));
523594
}
524595

525596
esp_err_t InitM5Stack(std::string qrCodeText)

0 commit comments

Comments
 (0)