MAX6955 LED driver
Revision 3:fbcb79f6e0a8, committed 2018-08-11
- Comitter:
- Kentaro Okuda
- Date:
- Sat Aug 11 15:27:43 2018 -0400
- Parent:
- 2:f6c4ed9cbf0e
- Commit message:
- refactoring. extract a method to generate printable char.
Changed in this revision
MAX6955.cpp | Show annotated file Show diff for this revision Revisions of this file |
diff -r f6c4ed9cbf0e -r fbcb79f6e0a8 MAX6955.cpp --- a/MAX6955.cpp Sat Aug 11 10:56:18 2018 -0400 +++ b/MAX6955.cpp Sat Aug 11 15:27:43 2018 -0400 @@ -6,14 +6,20 @@ MAX6955::MAX6955(PinName sda, PinName scl, char driver): i2c_(sda, scl), driver_(driver){} -static void prepareString(char* buffer, char* i2cData) { +static char getPrintableChar(char c) { + if (c < 32 || c > 126) { // make sure its printable + return 32; // if not, replace it with "space" + } + return c; +} + +static char* getString(char* buffer) { + static char i2cData[9]; + i2cData[0] = 0x20; // first digit for (int i = 0; i < 8; i++) { - if (buffer[i] < 32 || buffer[i] > 126) { // make sure its printable - i2cData[i+1] = 32; // if not, replace it with "space" - } else { - i2cData[i+1] = buffer[i]; - } + i2cData[i+1] = getPrintableChar(buffer[i]); } + return i2cData; } int MAX6955::write(char command, char data) { @@ -26,10 +32,9 @@ } int MAX6955::writeS(char* buffer) { - char i2cData[9]; - i2cData[0] = 0x20; // first digit - prepareString(buffer, i2cData); - int result = i2c_.write(driver_, (char *) i2cData, 9); + char* i2cData; + i2cData = getString(buffer); + int result = i2c_.write(driver_, i2cData, 9); wait(0.07); return result; }