bridystone / SevSegShift

Seven segment display controller library for Arduino
MIT License
28 stars 8 forks source link

Change to local memory allocation for pin arrays - Fixes issues #7 and #9 #10

Open foxblock opened 2 years ago

foxblock commented 2 years ago

Fixes #7 and #9

Instead of copying just the pointer of the shiftRegisterMapDigits and shiftRegisterMapSegments arrays passed to begin, we allocate the memory for them in SegSevShift and copy the values manually. This removes the implicit need for passing global/static variables, so begin can be called with local/temporary memory.

Sorry this took a while. I had no access to hardware to test it until today.

Personally I would have used malloc and memcpy, but I kept it similar to how it is done in SevSeg. Besides this approach should only be marginally slower and someone who really cares about speed would probably roll their own library anyway...

loginov-rocks commented 1 year ago

It should be considered as critical bug fix! Big vote to merge!

Otherwise, the display breaks in case more or less complex logic uses memory.