Size optimizations
This commit is contained in:
parent
d9ac375268
commit
d9fe7e072f
4 changed files with 21 additions and 37 deletions
33
Lcd.cpp
33
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));
|
||||
|
|
4
Lcd.h
4
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;
|
||||
};
|
||||
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in a new issue