Update MNF proprietary data immediately after wake-up

I'm using the ble_app_sleepmode project as starting point for a simple counter on DA14531, using the MNF proprietary data.

The flow is quite simple:

  1. The application starts and advertises. The user can read the MNF proprietary data, in which the count is 0.
  2. After a predefined amount of time (N seconds) it goes into extended sleep.
  3. When clicking on a specific button (A), the application should wake up and increment the counter by 1.
    1. If the user clicks on another button (B), the application should wake up, but it should not increment the counter by 1.
  4. The user can read the MNF proprietary data, in which the count is now incremented by 1 (if A was pressed) or the same as before (if B was pressed).
  5. After N seconds, it goes to extended sleep again.

This is what ble_app_sleepmode already does, except it increments the counter before going into extended sleep. I have tried to change this, such that I call `mnf_data_update` in `app_button_press_cb` or in `app_wakeup_cb`. The counter does change, but it is only broadcasted the next time the device wakes up. In other words, it is always exactly one behind.

I.e. the actual flow becomes:

  1. Boot: count=0, mnf=0
  2. First wake up: count=1, mnf=0
  3. Second wake up: count=2, mnf=1
  4. ...and so on

How do I make sure that the advertising data is updated on the fly, but after waking up from extended sleep, such that mnf is equal to count? I would highly appreciate an example based on the ble_app_sleepmode project, as that is a suitable starting point for my project.