diff options
author | David Crocker <dcrocker@eschertech.com> | 2018-02-06 02:38:47 +0300 |
---|---|---|
committer | David Crocker <dcrocker@eschertech.com> | 2018-02-06 02:38:47 +0300 |
commit | c5a8315c2d0ab6eb6a7c961e0f44cea198bee38d (patch) | |
tree | c15f0b8d3d7eb6a378992816a4b4223f56d858ef /src/Display/Display.cpp | |
parent | 1448121041393c9a878c3dd84ddd97dff2a4687f (diff) |
More work on SAM4S port
Renamed IoPort{.cpp,.h} to avoid name clash with ASF
Fixes to 12864 display
Support beeper on 12864 display
Encoder parameters are now configurable (M918)
Diffstat (limited to 'src/Display/Display.cpp')
-rw-r--r-- | src/Display/Display.cpp | 52 |
1 files changed, 49 insertions, 3 deletions
diff --git a/src/Display/Display.cpp b/src/Display/Display.cpp index aa8fcba6..264978ce 100644 --- a/src/Display/Display.cpp +++ b/src/Display/Display.cpp @@ -7,14 +7,18 @@ #include "Display.h" #include "GCodes/GCodes.h" +#include "IoPort.h" +#include "Pins.h" + +constexpr int DefaultPulsesPerClick = -4; // values that work with displays I have are 2 and -4 extern const LcdFont font16x16; -//extern const LcdFont font10x10; +extern const LcdFont font10x10; static int val = 0; Display::Display() - : lcd(LcdCSPin), encoder(EncoderPinA, EncoderPinB, EncoderPinSw, 4) + : lcd(LcdCSPin), encoder(EncoderPinA, EncoderPinB, EncoderPinSw), present(false) { //TODO init menus here } @@ -22,7 +26,7 @@ Display::Display() void Display::Init() { lcd.Init(); - encoder.Init(); + encoder.Init(DefaultPulsesPerClick); //TODO display top menu here // For now we just print some text to test the display @@ -35,6 +39,9 @@ void Display::Init() lcd.SetCursor(20, 5); lcd.SetRightMargin(50); lcd.print(val); + + IoPort::SetPinMode(LcdBeepPin, OUTPUT_PWM_LOW); + beepActive = false; } void Display::Spin(bool full) @@ -67,6 +74,11 @@ void Display::Spin(bool full) lcd.FlushSome(); } + + if (beepActive && millis() - whenBeepStarted > beepLength) + { + IoPort::WriteAnalog(LcdBeepPin, 0.0, 0); + } } void Display::Exit() @@ -74,4 +86,38 @@ void Display::Exit() // TODO display a "shutdown" message, or turn the display off? } +void Display::Beep(unsigned int frequency, unsigned int milliseconds) +{ + whenBeepStarted = millis(); + beepLength = milliseconds; + beepActive = true; + IoPort::WriteAnalog(LcdBeepPin, 0.5, (uint16_t)frequency); +} + +GCodeResult Display::Configure(GCodeBuffer& gb, const StringRef& reply) +{ + if (gb.Seen('P') && gb.GetUIValue() == 1) + { + // 12864 display configuration + present = true; + if (gb.Seen('E')) + { + encoder.Init(gb.GetIValue()); // configure encoder pulses per click and direction + } + } + return GCodeResult::ok; +} + +// Suspend normal operation and display an "Updating firmware" message +void Display::UpdatingFirmware() +{ + IoPort::WriteAnalog(LcdBeepPin, 0.0, 0); // stop any beep + lcd.TextInvert(false); + lcd.Clear(); + lcd.SetFont(&font10x10); + lcd.SetCursor(20, 0); + lcd.print("Updating firmware..."); + lcd.FlushAll(); +} + // End |