Skip to content

Fix race condition with keyboard and Wifi entry#204

Merged
daveallie merged 1 commit intocrosspoint-reader:masterfrom
olearycrew:fix/187-fix-wifi-race-condition
Jan 2, 2026
Merged

Fix race condition with keyboard and Wifi entry#204
daveallie merged 1 commit intocrosspoint-reader:masterfrom
olearycrew:fix/187-fix-wifi-race-condition

Conversation

@olearycrew
Copy link
Contributor

Summary

  • What is the goal of this PR? Fixes a bug - No connection to WiFi anymore #187 - where the screen would freeze after entering a WiFi password, causing the device to appear hung.

  • What changes are included?

    • Fixed a race condition in WifiSelectionActivity::displayTaskLoop() that caused rendering of an empty screen when transitioning from the keyboard subactivity
    • Added vTaskDelay() when a subactivity is active to prevent CPU starvation from a tight continue loop
    • Added a check to skip rendering when in PASSWORD_ENTRY state, allowing the state machine to properly transition to CONNECTING before the display updates

Additional Context

  • Root cause: When the keyboard subactivity exited after password entry, the display task would wake up and attempt to render. However, the state was still PASSWORD_ENTRY (before attemptConnection() changed it to CONNECTING), and since there was no render case for PASSWORD_ENTRY, the display would show a cleared/empty buffer, appearing frozen.

  • Performance implications: The added vTaskDelay(10) calls when subactivity is active or in PASSWORD_ENTRY state actually improve performance by preventing CPU starvation - previously the display task would spin in a tight loop with continue while a subactivity was present.

  • Testing focus: Test the full WiFi connection flow:

    1. Enter network selection
    2. Select a network requiring a password
    3. Enter password and press OK
    4. Verify "Connecting..." screen appears
    5. Verify connection completes and prompts to save password

Copy link
Member

@daveallie daveallie left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apologies, I think I broke this, thanks for fixing it!

@daveallie daveallie merged commit 9e59a51 into crosspoint-reader:master Jan 2, 2026
1 check passed
yingirene pushed a commit to yingirene/crosspoint-reader that referenced this pull request Jan 16, 2026
## Summary

* **What is the goal of this PR?** Fixes a bug -
crosspoint-reader#187 - where the
screen would freeze after entering a WiFi password, causing the device
to appear hung.

* **What changes are included?**
- Fixed a race condition in `WifiSelectionActivity::displayTaskLoop()`
that caused rendering of an empty screen when transitioning from the
keyboard subactivity
- Added `vTaskDelay()` when a subactivity is active to prevent CPU
starvation from a tight `continue` loop
- Added a check to skip rendering when in `PASSWORD_ENTRY` state,
allowing the state machine to properly transition to `CONNECTING` before
the display updates

## Additional Context

* **Root cause:** When the keyboard subactivity exited after password
entry, the display task would wake up and attempt to render. However,
the `state` was still `PASSWORD_ENTRY` (before `attemptConnection()`
changed it to `CONNECTING`), and since there was no render case for
`PASSWORD_ENTRY`, the display would show a cleared/empty buffer,
appearing frozen.

* **Performance implications:** The added `vTaskDelay(10)` calls when
subactivity is active or in `PASSWORD_ENTRY` state actually improve
performance by preventing CPU starvation - previously the display task
would spin in a tight loop with `continue` while a subactivity was
present.

* **Testing focus:** Test the full WiFi connection flow:
  1. Enter network selection
  2. Select a network requiring a password
  3. Enter password and press OK
  4. Verify "Connecting..." screen appears
  5. Verify connection completes and prompts to save password
Unintendedsideeffects pushed a commit to Unintendedsideeffects/crosspoint-reader that referenced this pull request Feb 17, 2026
## Summary

* **What is the goal of this PR?** Fixes a bug -
crosspoint-reader#187 - where the
screen would freeze after entering a WiFi password, causing the device
to appear hung.

* **What changes are included?**
- Fixed a race condition in `WifiSelectionActivity::displayTaskLoop()`
that caused rendering of an empty screen when transitioning from the
keyboard subactivity
- Added `vTaskDelay()` when a subactivity is active to prevent CPU
starvation from a tight `continue` loop
- Added a check to skip rendering when in `PASSWORD_ENTRY` state,
allowing the state machine to properly transition to `CONNECTING` before
the display updates

## Additional Context

* **Root cause:** When the keyboard subactivity exited after password
entry, the display task would wake up and attempt to render. However,
the `state` was still `PASSWORD_ENTRY` (before `attemptConnection()`
changed it to `CONNECTING`), and since there was no render case for
`PASSWORD_ENTRY`, the display would show a cleared/empty buffer,
appearing frozen.

* **Performance implications:** The added `vTaskDelay(10)` calls when
subactivity is active or in `PASSWORD_ENTRY` state actually improve
performance by preventing CPU starvation - previously the display task
would spin in a tight loop with `continue` while a subactivity was
present.

* **Testing focus:** Test the full WiFi connection flow:
  1. Enter network selection
  2. Select a network requiring a password
  3. Enter password and press OK
  4. Verify "Connecting..." screen appears
  5. Verify connection completes and prompts to save password
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants