Size optimizations

master
mandlm 2017-03-02 08:16:35 +01:00
parent d9ac375268
commit d9fe7e072f
4 changed files with 21 additions and 37 deletions

33
Lcd.cpp
View File

@ -5,27 +5,25 @@
void Lcd::initDisplay() void Lcd::initDisplay()
{ {
static const Command resetCommand{0, 0, 0, 0, 1, 1, 0, 0}; 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, 5000);
execute(resetCommand, false, 0.1); execute(resetCommand, false, 100);
execute(resetCommand, false, 0.0); execute(resetCommand, false, 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(fourBitModeCommand, false, 0);
execute(functionSetCommand, false, 39);
execute(displayOnOffCommand, false, 39);
clear(); clear();
execute(entryModeCommand, false, 39);
// entry mode
execute({0, 1, 1, 0, 0, 0, 0, 0}, false, 0.039);
} }
void Lcd::clear() 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) void Lcd::setPos(const uint8_t &pos)
@ -33,13 +31,12 @@ void Lcd::setPos(const uint8_t &pos)
Command posCommand; Command posCommand;
posCommand.data = pos | (1 << 7); posCommand.data = pos | (1 << 7);
execute(posCommand, false, 0.039); execute(posCommand, false, 39);
} }
void Lcd::output(const char &character) 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) 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]; static char buf[5];
output(itoa(val, buf, 10)); output(itoa(val, buf, 10));

4
Lcd.h
View File

@ -27,11 +27,11 @@ public:
void output(const char &character); void output(const char &character);
void output(const char *string); void output(const char *string);
void output(const uint16_t &val); void output(const uint16_t val);
private: private:
void setPos(const uint8_t &pos); 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;
}; };

View File

@ -4,24 +4,13 @@ void ShiftRegister::set(uint8_t value)
{ {
for (uint8_t bit = 0; bit < 8; ++bit) for (uint8_t bit = 0; bit < 8; ++bit)
{ {
setSerialPin(value & (1 << (7 - bit))); bool currentBit = (value >> (7 - bit)) & 1;
setSerialPin(currentBit);
pulseShiftPin(); pulseShiftPin();
} }
pulseStoragePin(); pulseStoragePin();
} }
void ShiftRegister::pulseShiftPin()
{
setShiftPin(false);
setShiftPin(true);
setShiftPin(false);
}
void ShiftRegister::pulseStoragePin()
{
setStoragePin(false);
setStoragePin(true);
setStoragePin(false);
}

View File

@ -9,10 +9,8 @@ class ShiftRegister
private: private:
virtual void setSerialPin(bool value) = 0; virtual void setSerialPin(bool value) = 0;
virtual void setShiftPin(bool value) = 0;
virtual void setStoragePin(bool value) = 0;
void pulseShiftPin(); virtual void pulseShiftPin() = 0;
void pulseStoragePin(); virtual void pulseStoragePin() = 0;
}; };