Skip to content

Commit

Permalink
event queue fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
mvladic committed Aug 21, 2019
1 parent 4d1755d commit a704ff6
Show file tree
Hide file tree
Showing 8 changed files with 117 additions and 99 deletions.
8 changes: 4 additions & 4 deletions src/eez/apps/psu/channel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@ void Channel::protectionEnter(ProtectionValue &cpv) {
int bit_mask = reg_get_ques_isum_bit_mask_for_channel_protection_value(cpv);
setQuesBits(bit_mask, true);

int16_t eventId = event_queue::EVENT_ERROR_CH1_OVP_TRIPPED + 3 * (index - 1);
int16_t eventId = event_queue::EVENT_ERROR_CH1_OVP_TRIPPED + (index - 1);

if (IS_OVP_VALUE(this, cpv)) {
if (flags.rprogEnabled && channel_dispatcher::getUProtectionLevel(*this) == channel_dispatcher::getUMax(*this)) {
Expand Down Expand Up @@ -1448,21 +1448,21 @@ void Channel::clearProtection(bool clearOTP) {
ovp.flags.tripped = 0;
ovp.flags.alarmed = 0;
setQuesBits(QUES_ISUM_OVP, false);
if (lastEvent.eventId == event_queue::EVENT_ERROR_CH1_OVP_TRIPPED + 3 * (index - 1)) {
if (lastEvent.eventId == event_queue::EVENT_ERROR_CH1_OVP_TRIPPED + (index - 1)) {
event_queue::markAsRead();
}

ocp.flags.tripped = 0;
ocp.flags.alarmed = 0;
setQuesBits(QUES_ISUM_OCP, false);
if (lastEvent.eventId == event_queue::EVENT_ERROR_CH1_OCP_TRIPPED + 3 * (index - 1)) {
if (lastEvent.eventId == event_queue::EVENT_ERROR_CH1_OCP_TRIPPED + (index - 1)) {
event_queue::markAsRead();
}

opp.flags.tripped = 0;
opp.flags.alarmed = 0;
setQuesBits(QUES_ISUM_OPP, false);
if (lastEvent.eventId == event_queue::EVENT_ERROR_CH1_OPP_TRIPPED + 3 * (index - 1)) {
if (lastEvent.eventId == event_queue::EVENT_ERROR_CH1_OPP_TRIPPED + (index - 1)) {
event_queue::markAsRead();
}

Expand Down
2 changes: 1 addition & 1 deletion src/eez/apps/psu/conf_advanced.h
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@
#define MAX_KEYPAD_TEXT_LENGTH 128

/// Enable transition to the Main page after period of inactivity.
#define GUI_BACK_TO_MAIN_ENABLED 1
#define GUI_BACK_TO_MAIN_ENABLED 0

/// Inactivity period duration in seconds before transition to the Main page.
#define GUI_BACK_TO_MAIN_DELAY 10
Expand Down
2 changes: 1 addition & 1 deletion src/eez/apps/psu/eeprom.h
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@
|6 |2 |int |Queue head |
|8 |2 |int |Queue size |
|10 |2 |int |Last error event index |
|16 |1600 |[struct](#event) |Max. 100 events |
|16 |3200 |[struct](#event) |Max. 200 events |
## <a name="event">Event</a>
Expand Down
4 changes: 2 additions & 2 deletions src/eez/apps/psu/event_queue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ namespace psu {
namespace event_queue {

static const uint32_t MAGIC = 0xD8152FC3L;
static const uint16_t VERSION = 4;
static const uint16_t VERSION = 5;

static const uint16_t MAX_EVENTS = 100;
static const uint16_t MAX_EVENTS = 200;
static const uint16_t NULL_INDEX = MAX_EVENTS;

static const uint16_t EVENT_HEADER_SIZE = 16;
Expand Down
171 changes: 89 additions & 82 deletions src/eez/apps/psu/event_queue.h

Large diffs are not rendered by default.

12 changes: 6 additions & 6 deletions src/eez/apps/psu/gui/data.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1909,19 +1909,21 @@ void data_channel_protection_otp_delay(data::DataOperationEnum operation, data::
}
}

event_queue::Event g_stateEvents[2][event_queue::EVENTS_PER_PAGE];
static event_queue::Event g_lastEvent[2];
event_queue::Event g_event;

void data_event_queue_last_event_type(data::DataOperationEnum operation, data::Cursor &cursor, data::Value &value) {
if (operation == data::DATA_OPERATION_GET) {
event_queue::Event *lastEvent = &g_lastEvent[getCurrentStateBufferIndex()];
event_queue::Event *lastEvent = isUpdatingScreen() ? &g_lastEvent[getCurrentStateBufferIndex()] : &g_event;
event_queue::getLastErrorEvent(lastEvent);
value = data::Value(event_queue::getEventType(lastEvent));
}
}

void data_event_queue_last_event_message(data::DataOperationEnum operation, data::Cursor &cursor, data::Value &value) {
if (operation == data::DATA_OPERATION_GET) {
event_queue::Event *lastEvent = &g_lastEvent[getCurrentStateBufferIndex()];
event_queue::Event *lastEvent = isUpdatingScreen() ? &g_lastEvent[getCurrentStateBufferIndex()] : &g_event;
event_queue::getLastErrorEvent(lastEvent);
if (event_queue::getEventType(lastEvent) != event_queue::EVENT_TYPE_NONE) {
value = MakeEventValue(lastEvent);
Expand All @@ -1935,12 +1937,10 @@ void data_event_queue_events(data::DataOperationEnum operation, data::Cursor &cu
}
}

event_queue::Event g_stateEvents[2][event_queue::EVENTS_PER_PAGE];

void data_event_queue_events_type(data::DataOperationEnum operation, data::Cursor &cursor, data::Value &value) {
if (operation == data::DATA_OPERATION_GET) {
if (cursor.i >= 0) {
event_queue::Event *event = &g_stateEvents[getCurrentStateBufferIndex()][cursor.i];
event_queue::Event *event = isUpdatingScreen() ? &g_stateEvents[getCurrentStateBufferIndex()][cursor.i] : &g_event;

int n = event_queue::getActivePageNumEvents();
if (cursor.i < n) {
Expand All @@ -1957,7 +1957,7 @@ void data_event_queue_events_type(data::DataOperationEnum operation, data::Curso
void data_event_queue_events_message(data::DataOperationEnum operation, data::Cursor &cursor, data::Value &value) {
if (operation == data::DATA_OPERATION_GET) {
if (cursor.i >= 0) {
event_queue::Event *event = &g_stateEvents[getCurrentStateBufferIndex()][cursor.i];
event_queue::Event *event = isUpdatingScreen() ? &g_stateEvents[getCurrentStateBufferIndex()][cursor.i] : &g_event;

int n = event_queue::getActivePageNumEvents();
if (cursor.i < n) {
Expand Down
8 changes: 5 additions & 3 deletions src/eez/gui/event.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
//

#define CONF_GUI_LONG_TOUCH_TIMEOUT 1000000L // 1s
#define CONF_GUI_KEYPAD_AUTO_REPEAT_DELAY 250000L // 250ms
#define CONF_GUI_KEYPAD_AUTO_REPEAT_DELAY 100000L // 100ms
#define CONF_GUI_EXTRA_LONG_TOUCH_TIMEOUT 30000000L // 30s

namespace eez {
Expand Down Expand Up @@ -85,9 +85,11 @@ void onWidgetDefaultTouch(const WidgetCursor &widgetCursor, Event &touchEvent) {
}
} else if (touchEvent.type == EVENT_TYPE_AUTO_REPEAT) {
int action = getAction(widgetCursor);
if (action == ACTION_ID_KEYPAD_BACK || action == ACTION_ID_EVENT_QUEUE_PREVIOUS_PAGE ||
if (widgetCursor.appContext->isWidgetActionEnabled(widgetCursor) && (
action == ACTION_ID_KEYPAD_BACK ||
action == ACTION_ID_EVENT_QUEUE_PREVIOUS_PAGE ||
action == ACTION_ID_EVENT_QUEUE_NEXT_PAGE ||
widgetCursor.appContext->isAutoRepeatAction(action)) {
widgetCursor.appContext->isAutoRepeatAction(action))) {
m_touchActionExecuted = true;
executeAction(action);
}
Expand Down
9 changes: 9 additions & 0 deletions src/eez/gui/update.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,15 @@
namespace eez {
namespace gui {

static bool g_updatingScreen;
static uint8_t g_stateBuffer[2][CONF_MAX_STATE_SIZE];
static WidgetState *g_previousState;
static WidgetState *g_currentState;

bool isUpdatingScreen() {
return g_updatingScreen;
}

int getCurrentStateBufferIndex() {
return (uint8_t *)g_currentState == &g_stateBuffer[0][0] ? 0 : 1;
}
Expand All @@ -48,7 +53,11 @@ void updateScreen() {
widgetCursor.previousState = g_previousState;
widgetCursor.currentState = g_currentState;

g_updatingScreen = true;

g_appContext->updateAppView(widgetCursor);

g_updatingScreen = false;
}

} // namespace gui
Expand Down

0 comments on commit a704ff6

Please sign in to comment.