kornel-schrenk/DiveIno

Repetitive dive: compartment overflow

Closed this issue · 1 comments

During a repetitive dive a compartment overflow can happen at least on Arduino Mega.

It was an overflow. On Arduino Mega the int data type is a (2-byte) value with a range of -32,768 to 32,767. If the surface time is for instance 1040 minutes, the algorithm implementation converts it to seconds. 1040*60=62,400, which is above 32,767, so it is an overflow situation.

The solution was to use long instead of int, which is a 4 byte value on Arduino Mega and Due with a range of -2,147,483,648 to 2,147,483,647. It is more than enough surface time in seconds.