|
|
@ -4,6 +4,8 @@ |
|
|
|
using namespace iflytop; |
|
|
|
using namespace std; |
|
|
|
static QueueHandle_t xQueue; |
|
|
|
static AppEvent eventtxcache; |
|
|
|
|
|
|
|
#define TAG "AppEventBus"
|
|
|
|
void AppEventBus::initialize() { |
|
|
|
lock.init(); |
|
|
@ -11,20 +13,20 @@ void AppEventBus::initialize() { |
|
|
|
xQueue = xQueueCreate(20, sizeof(AppEvent)); |
|
|
|
|
|
|
|
thread.start([this]() { |
|
|
|
AppEvent event; |
|
|
|
static AppEvent eventrxcache; |
|
|
|
while (1) { |
|
|
|
if (xQueueReceive(xQueue, &event, portMAX_DELAY) == pdTRUE) { |
|
|
|
// ZLOGI(TAG, "pop event type %d", event.type);
|
|
|
|
if (xQueueReceive(xQueue, &eventrxcache, portMAX_DELAY) == pdTRUE) { |
|
|
|
// ZLOGI(TAG, "pop eventrxcache type %d", eventrxcache.type);
|
|
|
|
|
|
|
|
if (event.type == KAE_callOnAppEventBusLoop) { |
|
|
|
if (event.onfnc) { |
|
|
|
event.onfnc(); |
|
|
|
if (eventrxcache.type == KAE_callOnAppEventBusLoop) { |
|
|
|
if (eventrxcache.onfnc) { |
|
|
|
eventrxcache.onfnc(); |
|
|
|
} |
|
|
|
continue; |
|
|
|
} |
|
|
|
|
|
|
|
for (int i = 0; i < cbNum; i++) { |
|
|
|
m_cbs[i](&event); |
|
|
|
m_cbs[i](&eventrxcache); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -41,24 +43,31 @@ void AppEventBus::pushEvent(const AppEvent& event) { |
|
|
|
ZLOGE(TAG, "xQueueSend failed"); |
|
|
|
} |
|
|
|
} |
|
|
|
static AppEvent event; |
|
|
|
|
|
|
|
void AppEventBus::pushSimpleEvent(AppEventType_t type) { |
|
|
|
zlock_guard lck(lock); |
|
|
|
event.type = type; |
|
|
|
pushEvent(event); |
|
|
|
eventtxcache.type = type; |
|
|
|
pushEvent(eventtxcache); |
|
|
|
} |
|
|
|
|
|
|
|
void AppEventBus::pushPageChangeEvent(uint8_t toPage) { |
|
|
|
zlock_guard lck(lock); |
|
|
|
event.type = KAE_PageChangeEvent; |
|
|
|
event.d.pageChangeTo = toPage; |
|
|
|
pushEvent(event); |
|
|
|
eventtxcache.type = KAE_PageChangeEvent; |
|
|
|
eventtxcache.setPageChangeTo(toPage); |
|
|
|
pushEvent(eventtxcache); |
|
|
|
} |
|
|
|
|
|
|
|
void AppEventBus::callFnInEventBus(function<void()> onfnc) { |
|
|
|
zlock_guard lck(lock); |
|
|
|
event.type = KAE_callOnAppEventBusLoop; |
|
|
|
event.onfnc = onfnc; |
|
|
|
pushEvent(event); |
|
|
|
eventtxcache.type = KAE_callOnAppEventBusLoop; |
|
|
|
eventtxcache.onfnc = onfnc; |
|
|
|
pushEvent(eventtxcache); |
|
|
|
} |
|
|
|
|
|
|
|
void AppEventBus::pushStateDisplayInfoEvent(const char* info) { |
|
|
|
zlock_guard lck(lock); |
|
|
|
eventtxcache.type = kAppEvent_StateDisplayInfo; |
|
|
|
// strncpy(event.getStateDisplayInfo(), info, event.getBufSize());
|
|
|
|
eventtxcache.setStateDisplayInfo(info); |
|
|
|
pushEvent(eventtxcache); |
|
|
|
} |