cancel
Showing results for 
Search instead for 
Did you mean: 

[Closed] How to use one Alarm screen with different messages for different events?

KShim.1738
Associate III

I have several pages to be displayed when events occur. Each page shows which event happened.

I think best place to parse the incoming event is FrontApplication. So I check the event queue in FrontendApplication::handleTickEvent() using processIncomingEvents() as in the follwing code.

////////// Model ////////////
    uint32_t IDincomingQEvent;  // in Model class
 
uint32_t Model::getMostRecentEventID()
{
    return IDincomingQEvent;
}
 
////////// FrontApplication ////////////
 
    virtual void handleTickEvent() // FrontendApplication::handleTickEvent()
    {
        uint32_t currentScreenID;
        uint32_t bADPlayState;
 
        model.tick();
        FrontendApplicationBase::handleTickEvent(); /* reset counter */
 
        model.getADPlayState(&bADPlayState);
        currentScreenID = model.getCurrentScreenID();
        if(bADPlayState != 0) {
            if((currentScreenID != ESP_SCREN_SCREEN_SAVER) &&
               (tickCounter4ScreenSaver > 300)) {
                static_cast<FrontendApplication *>(Application::getInstance())->gotoScreenSaverScreenNoTransition();
            }
        }
 
        tickCounter4ScreenSaver++;
 
        processIncomingEvents();
    }
 
void FrontendApplication::processIncomingEvents()
{
#if defined(__TARGET_BOARD__)
    unsigned int currentScreenID;
    uint32_t nTGFXEvent;
    int32_t ret;
 
    ret = TGFXdequeueEvent(&nTGFXEvent);
    if(ret < 0) {
        return;
    }
 
    DBG_PRINT(DBG_DEBUG, "test FrontendApplication::processIncomingEvents()\r\n");
 
    /* common codes will be taken out of the swich statement later. */
    switch(nTGFXEvent) {
        case TGFX_EVENT_ALERT_FILM_SCRAPS_FULL:
            DBG_PRINT(DBG_DEBUG, "ALERT_FILM_SCRAPS_FULL Event\r\n");
            initTickCounter();
            currentScreenID == model.getCurrentScreenID();
            if(currentScreenID == ESP_SCREN_SCREEN_SAVER) {
                model.popScreenID(&ret);
 
                DBG_PRINT(DBG_DEBUG, "screen id to be removed: %d\r\n", ret);
            }
            model.pushScreenID(ESP_SCREN_ALERT_FILM_SCRAPS_FULL, nTGFXEvent);
            gotoScreenWithID(ESP_SCREN_ALERT_FILM_SCRAPS_FULL);
            break;
        case TGFX_EVENT_ALERT_DRUM_NOT_DETECTED:
            DBG_PRINT(DBG_DEBUG, "ALERT_DRUM_NOT_DETECTED Event\r\n");
            initTickCounter();
            currentScreenID == model.getCurrentScreenID();
            if(currentScreenID == ESP_SCREN_SCREEN_SAVER) {
                model.popScreenID(&ret);
 
                DBG_PRINT(DBG_DEBUG, "screen id to be removed: %d\r\n", ret);
            }
            model.pushScreenID(ESP_SCREN_ALERT_FILM_SCRAPS_FULL, nTGFXEvent);
            gotoScreenWithID(ESP_SCREN_ALERT_FILM_SCRAPS_FULL);
            break;
        default:
            break;
    }
#endif /* __TARGET_BOARD__ */
}

Differnt messages must be displayed on the screen for different events.

TGFX_EVENT_ALERT_FILM_SCRAPS_FULL

TGFX_EVENT_ALERT_DRUM_NOT_DETECTED

But I can't pass the event code on creation of the Alarm "SCREEN(the meaning in the context of TouchGFX)". So I have one variable in Model. And the variable is checked in cAlarmView::setupScreen() and different messages can be placed on the screen.

void cAlarmView::setupScreen()
{
    uint32_t mostRecentEventID;
 
    cAlarmViewBase::setupScreen();
 
    /* Kyle */
    mostRecentEventID = getMostRecentEventID();
 
#if defined(__TARGET_BOARD__)
    DBG_PRINT(DBG_DEBUG, "most recent event: %08x\r\n", mostRecentEventID);
#endif /* __TARGET_BOARD__ */
 
    switch(mostRecentEventID) {
        case TGFX_EVENT_ALERT_FILM_SCRAPS_FULL:
#if defined(__TARGET_BOARD__)
    DBG_PRINT(DBG_DEBUG, "updateScreen4FilmScrapsFull() called\r\n");
#endif /* __TARGET_BOARD__ */
 
            updateScreen4FilmScrapsFull();
            break;
        case TGFX_EVENT_ALERT_DRUM_NOT_DETECTED:
#if defined(__TARGET_BOARD__)
    DBG_PRINT(DBG_DEBUG, "updateScreen4FilmDrumSensorNotDetected() called\r\n");
#endif /* __TARGET_BOARD__ */
 
            updateScreen4FilmDrumSensorNotDetected();
            break;
        default:
            break;
    }
}

I wonder if there is a direct method to pass the event code to the screen on creation as an argument.

Please give advice if you think there are better ways to implement this.

Kyle

2 REPLIES 2
MM..1
Chief III

I mean your idea change application code isnt best, and too i dont undestand what your code do when no alarm, but by docu

void Model::tick()
{
  // Pseudo-code for sampling data
  if (OS_Poll(GuiTaskMBox))
  {
    // Here we assume that you have defined a "Message" struct containing type and data,
    // along with some event definitions.
    struct Message msg = OS_Read(GuiTaskMBox);
    if (msg.eventType == EVT_TEMP_CHANGED)
    {
       // We received information that temperature has changed.
       // First, update Model state variable
       currentTemperature = msg.data;
 
      // Second, notify the currently active Presenter that temperature has changed.
      // The modelListener pointer points to the currently active Presenter.
      if (modelListener != 0)
      {
        modelListener->notifyTemperatureChanged(currentTemperature);
      }
    }
  }
}

all check in touchGFX is ok placed in model.tick. And with notify you can change actual screen objects or invoke switch screen and in setup call model getter for alarm type ... Backend Communication | TouchGFX Documentation

Thank you for your reply.

I'm new to TouchGFX. I do this to keep the application size smaller in a way. And I can have all warning/error pages in one source file, View file.

I placed the sources in FrontApplication. It's about Screen Switch. So I think it would be better to place the codes in FrontApplication so that I can focus on Data with Model.

Best regards,

Kyle Shim