gpstar81 / GPStar-proton-pack

GPStar Proton Pack and Neutrona Wand
https://www.gpstartechnologies.com
GNU General Public License v3.0
37 stars 8 forks source link

Unsigned int underflow in powercellLoop() #294

Closed nomakewan closed 4 months ago

nomakewan commented 4 months ago

There is presently an unsigned 16-bit integer underflow error in powercellLoop() (and potentially other areas of the code relating to ramping actions, such as the cyclotron). This underflow is a direct result of r_2021_ramp.update() calls which are then used to set other timer delays between both the cyclotron and power cell. The most obvious error condition can be replicated by performing the following sequence:

  1. Start with the Proton Pack in Afterlife or Frozen Empire mode.
  2. With the pack on, shut down the pack.
  3. Flip the year switch inside the cyclotron cavity to 1984.
  4. Wait for the ramp down sequence to complete so that the year change will take effect.
  5. Power the pack back up.

This will cause the first LED of the power cell to come on solid and appear to be frozen. However, it is not frozen. If you wait 64 seconds from the moment you flipped the ion arm switch, the power cell will resume normal functionality. This indicates that the initial startup timer delay was set to some 64000 milliseconds, which is in line with a 16-bit unsigned integer underflow (subtracting 1050--the value of i_1984_delay--from 75--the value of i_powercell_delay in 1984 mode--would result in a value of 64560).

PR #293 includes some cleanup of the code around this and other locations, but as I am not intimately familiar with the functionality of the Ramp library or how the powercell/cyclotron timers are set and reset, I felt it best to get some assistance with this issue.

The likely location of this underflow from my investigation is the line in powercellLoop() that triggers if waiting for the initial ramp up on start or ramp down on power-down:

i_pc_delay = i_powercell_delay + (r_2021_ramp.update() - i_1984_delay);

The Afterlife-to-1984 switch results in a 64-second underflow, but I imagine the 1.4s lag before the first LED of the powercell ramps after switching from 1984/1989 to Afterlife has something to do with a math error as well. May be worth confirming all of the initial values for the Powercell and Cyclotron are what they are expected to be and not underflowing.

Toy203 commented 4 months ago

Saw the mono led turning on myself as well