Skip to content

Commit

Permalink
Make sure to queue m5stack actions to the Matter thread as needed. (#…
Browse files Browse the repository at this point in the history
bzbarsky-apple authored Feb 11, 2022

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
1 parent 512ab16 commit 379d144
Showing 2 changed files with 40 additions and 4 deletions.
7 changes: 7 additions & 0 deletions examples/all-clusters-app/esp32/main/CHIPDeviceManager.cpp
Original file line number Diff line number Diff line change
@@ -99,6 +99,13 @@ CHIP_ERROR CHIPDeviceManager::Init(CHIPDeviceManagerCallbacks * cb)
void MatterPostAttributeChangeCallback(const chip::app::ConcreteAttributePath & path, uint8_t mask, uint8_t type, uint16_t size,
uint8_t * value)
{
TaskHandle_t task = xTaskGetCurrentTaskHandle();
const char * name = pcTaskGetName(task);
if (!strcmp(name, "CHIP"))
{
ESP_LOGE("all-clusters-app", "Attribute changed on non-Matter task '%s'\n", name);
}

chip::DeviceManager::CHIPDeviceManagerCallbacks * cb =
chip::DeviceManager::CHIPDeviceManager::GetInstance().GetCHIPDeviceManagerCallbacks();
if (cb != nullptr)
37 changes: 33 additions & 4 deletions examples/all-clusters-app/esp32/main/main.cpp
Original file line number Diff line number Diff line change
@@ -185,7 +185,35 @@ void AddDevice(std::string name)

#if CONFIG_DEVICE_TYPE_M5STACK

class EditAttributeListModel : public ListScreen::Model
class TouchesMatterStackModel : public ListScreen::Model
{
// We could override Action() and then hope focusIndex has not changed by
// the time our queued task runs, but it's cleaner to just capture its value
// now.
struct QueuedAction
{
QueuedAction(TouchesMatterStackModel * selfArg, int iArg) : self(selfArg), i(iArg) {}
TouchesMatterStackModel * self;
int i;
};

void ItemAction(int i) final
{
auto * action = chip::Platform::New<QueuedAction>(this, i);
chip::DeviceLayer::PlatformMgr().ScheduleWork(QueuedActionHandler, reinterpret_cast<intptr_t>(action));
}

static void QueuedActionHandler(intptr_t closure)
{
auto * queuedAction = reinterpret_cast<QueuedAction *>(closure);
queuedAction->self->DoAction(queuedAction->i);
chip::Platform::Delete(queuedAction);
}

virtual void DoAction(int i) = 0;
};

class EditAttributeListModel : public TouchesMatterStackModel
{
int deviceIndex;
int endpointIndex;
@@ -224,7 +252,8 @@ class EditAttributeListModel : public ListScreen::Model
}
return i == 0 ? "+" : "-";
}
virtual void ItemAction(int i)

void DoAction(int i) override
{
auto & attribute = this->attribute();
auto & value = std::get<1>(attribute);
@@ -398,7 +427,7 @@ class MdnsDebugListModel : public ActionListModel
}
};

class SetupListModel : public ListScreen::Model
class SetupListModel : public TouchesMatterStackModel
{
public:
SetupListModel()
@@ -413,7 +442,7 @@ class SetupListModel : public ListScreen::Model
virtual std::string GetTitle() { return "Setup"; }
virtual int GetItemCount() { return options.size(); }
virtual std::string GetItemText(int i) { return options.at(i); }
virtual void ItemAction(int i)
void DoAction(int i) override
{
ESP_LOGI(TAG, "Opening options %d: %s", i, GetItemText(i).c_str());
if (i == 0)

0 comments on commit 379d144

Please sign in to comment.