Have verified this code works on all of the non AVR boards I have ESP32 and ESP8266 8 diferent varieties
Arduino UNO WiFi Rev 2 Totally different result will produce expected result regardless of code.
The code does not run correctly the following boards unless there are two calls to inc_Buffer & inc_low in the sketch
Arduino UNO
Arduino Mega2560
Elegoo Mega2560
Generic Mega2560
Generic UNO 3 diferent
Generic NANO
So I asume all 8 bit AVR board but these are the only units I have on hand
Can someone who works with C++ run thing on non Arduino IDE to see if it compiles and runs?
char *Buffer[] = {
// 0123456789
"ack 100099",
"nak ======",
"cmd ======",
"sta ======",
};
void setup() {
Serial.begin(38400);
Serial.println("ASCII Buffer Inc test");
// Comment out following line inc_Buffer does not work ******************
inc_Buffer(Buffer[0], 9, 3); // Should rollover to 100
Serial.println(Buffer[0]);
}
uint32_t tmp = 0;
void loop() {
inc_Buffer(Buffer[0], 9, 1); // Just inc the least sig byte
if(tmp++ < 15) { Serial.println(Buffer[0]); } // Just do 15
}
void inc_Buffer(char p_Buf[], uint8_t pos, uint8_t len){
while (inc_low(p_Buf, pos--) && --len );
inc_low(p_Buf, 4); // This is required to get inc_low to work **********************
// for some reason two calls to inc_Buffer and inc_low in
// sketch are required for routine to work
}
bool inc_low (char p_Buf[], uint8_t pos){ // true = overflow
if (++p_Buf[pos] < 58) { // Get and inc 9 out of 10 times nothing else needed
return false; } // indicate were done = no overflow
p_Buf[pos] = 48; // take care of over flow
return true; // indicate overflow
}
This is the expected output
Buffer Inc test
========10
========11
========12
========13
========14
========15
========16
========17
========18
========19
========20
========21
========22
========23
========24
========25
This is output with setup inc_Buffer commented out
Buffer Inc test
==========
========10
========10
========10
========10
========10
========10
========10
========10
========10
========10
========10
========10
========10
========10
========10
For reference I cant say 100% but 99% as long as there are two or more calls to inc_Buffer in the compiled program it produces desired output which is why I think it may have to do with optimization.
Having just the main loop call and a call in a unused function does not produce the desired output.
And again I am at a total loss as to why comment out incrementing the rollover digit stops the inc of the primary digit making me think I am somehow misusing the by ref aspect of the function call.