Skip to content

Conversation

icapurro
Copy link

This pull request enhances the firmware by adding more BLE configuration capabilities for the user-defined configurations. This enables configuration with the latest Companion App code.

Key Changes

  1. EEPROM Refactoring:

    • Increased EEPROM_SIZE from 2 bytes to 9 bytes to store additional configuration parameters.
    • Added a SIGNATURE_ADDR (with value 0xAA) to detect if EEPROM has been initialized.
    • Expanded stored variables to include:
      • WEIGHT_ADDR: Goal weight (unchanged).
      • OFFSET_ADDR: Weight offset (unchanged).
      • New fields: MOMENTARY_ADDR, REEDSWITCH_ADDR, AUTOTARE_ADDR, MIN_SHOT_DURATION_S_ADDR, MAX_SHOT_DURATION_S_ADDR, DRIP_DELAY_S_ADDR.
    • Introduced loadOrInitEEPROM() to initialize EEPROM with defaults if uninitialized or load existing values.
  2. Dynamic Configuration and Logic Updates:

    • Replaced hardcoded #define constants (e.g., MOMENTARY, REEDSWITCH, AUTOTARE, MIN_SHOT_DURATION_S, MAX_SHOT_DURATION_S, DRIP_DELAY_S) with runtime variables (momentary, reedSwitch, autoTare, minShotDurationS, maxShotDurationS, dripDelayS).
    • These variables are loaded from EEPROM at startup and can be updated via BLE, with changes persisted back to EEPROM.
    • Updated loop() and related functions to use these dynamic variables instead of static defines.
  3. BLE Enhancements:

    • Added new BLE characteristics:
      • reedSwitchCharacteristic, momentaryCharacteristic, autoTareCharacteristic: Switch and tare settings.
      • minShotDurationSCharacteristic, maxShotDurationSCharacteristic, dripDelaySCharacteristic: Shot timing parameters.
      • firmwareVersionCharacteristic: Read-only firmware version.
      • scaleStatusCharacteristic: Notifies scale connection status (STATUS_DISCONNECTED or STATUS_CONNECTED).
    • Implemented initializeBLE() to set up services and characteristics with initial values.
    • Added pollAndReadBLE() to handle runtime updates from BLE writes, persisting changes to EEPROM.
  4. Scale Connection Logic:

    • Replaced the blocking while(!scale.isConnected()) loop with an if(!scale.isConnected()) condition in loop().
    • This change ensures the Arduino main loop continues running, allowing:
      • Periodic scale connection attempts without blocking.
      • Bluetooth configuration updates (via pollAndReadBLE()) to execute after every connection attempt, even when the scale is disconnected.
    • Added updateScaleStatus() to track and notify scale connection state changes.

IMPORTANT: I have tested this with the ESP-WROOM-32 board, which is similar to the shotStopper board, but not the same.

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.

1 participant