From d9fe7e072fdfb0b70c3bbf794b34497149f1e7a4 Mon Sep 17 00:00:00 2001 From: Michael Mandl Date: Thu, 2 Mar 2017 08:16:35 +0100 Subject: [PATCH] Size optimizations --- Lcd.cpp | 33 +++++++++++++++------------------ Lcd.h | 4 ++-- ShiftRegister.cpp | 15 ++------------- ShiftRegister.h | 6 ++---- 4 files changed, 21 insertions(+), 37 deletions(-) diff --git a/Lcd.cpp b/Lcd.cpp index 65ad921..3e94d49 100644 --- a/Lcd.cpp +++ b/Lcd.cpp @@ -5,27 +5,25 @@ void Lcd::initDisplay() { static const Command resetCommand{0, 0, 0, 0, 1, 1, 0, 0}; + static const Command fourBitModeCommand{0, 1, 0, 0, 0, 0, 0, 0}; + static const Command functionSetCommand{0, 0, 1, 1, 0, 1, 0, 0}; + static const Command displayOnOffCommand{0, 0, 1, 1, 0, 0, 0, 0}; + static const Command entryModeCommand{0, 1, 1, 0, 0, 0, 0, 0}; - execute(resetCommand, false, 5.0); - execute(resetCommand, false, 0.1); - execute(resetCommand, false, 0.0); - execute({0, 1, 0, 0, 0, 0, 0, 0}, false, 0.0); - - // function set - execute({0, 0, 1, 1, 0, 1, 0, 0}, false, 0.039); - - // display on/off - execute({0, 0, 1, 1, 0, 0, 0, 0}, false, 0.039); + execute(resetCommand, false, 5000); + execute(resetCommand, false, 100); + execute(resetCommand, false, 0); + execute(fourBitModeCommand, false, 0); + execute(functionSetCommand, false, 39); + execute(displayOnOffCommand, false, 39); clear(); - - // entry mode - execute({0, 1, 1, 0, 0, 0, 0, 0}, false, 0.039); + execute(entryModeCommand, false, 39); } void Lcd::clear() { - execute({1, 0, 0, 0, 0, 0, 0, 0}, false, 1.53); + execute({1, 0, 0, 0, 0, 0, 0, 0}, false, 1530); } void Lcd::setPos(const uint8_t &pos) @@ -33,13 +31,12 @@ void Lcd::setPos(const uint8_t &pos) Command posCommand; posCommand.data = pos | (1 << 7); - execute(posCommand, false, 0.039); + execute(posCommand, false, 39); } void Lcd::output(const char &character) { - execute((const Command &)character, true, 0.043); - + execute((const Command &)character, true, 43); } void Lcd::output(const char *string) @@ -56,7 +53,7 @@ void Lcd::output(const char *string) } } -void Lcd::output(const uint16_t &val) +void Lcd::output(const uint16_t val) { static char buf[5]; output(itoa(val, buf, 10)); diff --git a/Lcd.h b/Lcd.h index 60fed32..46cb21c 100644 --- a/Lcd.h +++ b/Lcd.h @@ -27,11 +27,11 @@ public: void output(const char &character); void output(const char *string); - void output(const uint16_t &val); + void output(const uint16_t val); private: void setPos(const uint8_t &pos); - virtual void execute(const Command &cmd, bool RS, double delay) = 0; + virtual void execute(const Command &cmd, bool RS, uint16_t delay_us) = 0; }; diff --git a/ShiftRegister.cpp b/ShiftRegister.cpp index 2294df0..7967a2f 100644 --- a/ShiftRegister.cpp +++ b/ShiftRegister.cpp @@ -4,24 +4,13 @@ void ShiftRegister::set(uint8_t value) { for (uint8_t bit = 0; bit < 8; ++bit) { - setSerialPin(value & (1 << (7 - bit))); + bool currentBit = (value >> (7 - bit)) & 1; + setSerialPin(currentBit); pulseShiftPin(); } pulseStoragePin(); } -void ShiftRegister::pulseShiftPin() -{ - setShiftPin(false); - setShiftPin(true); - setShiftPin(false); -} -void ShiftRegister::pulseStoragePin() -{ - setStoragePin(false); - setStoragePin(true); - setStoragePin(false); -} diff --git a/ShiftRegister.h b/ShiftRegister.h index f9a8e5f..8355284 100644 --- a/ShiftRegister.h +++ b/ShiftRegister.h @@ -9,10 +9,8 @@ class ShiftRegister private: virtual void setSerialPin(bool value) = 0; - virtual void setShiftPin(bool value) = 0; - virtual void setStoragePin(bool value) = 0; - void pulseShiftPin(); - void pulseStoragePin(); + virtual void pulseShiftPin() = 0; + virtual void pulseStoragePin() = 0; };