From ebc7a8059ac8c640104f91a7ec4dd0261289af94 Mon Sep 17 00:00:00 2001 From: Giles Bathgate Date: Mon, 6 Dec 2021 00:16:48 +0000 Subject: [PATCH] Support for up/down arrows as lcd control buttons (#348) * Support for up/down arrows as lcd control buttons * Add arrow keys to scripting and tests Co-authored-by: VintagePC <53943260+vintagepc@users.noreply.github.com> --- MK404.cpp | 1 + parts/KeyController.cpp | 15 +++++++++++++++ parts/KeyController.h | 3 +++ parts/components/RotaryEncoder.cpp | 7 ++++++- scripts/tests/snaps/ext1/GFXLiteKey13.png | Bin 0 -> 1525 bytes scripts/tests/test_lite_gfx_keys.txt | 5 ++++- utility/MK3SGL.cpp | 13 ++++++++++--- 7 files changed, 39 insertions(+), 5 deletions(-) create mode 100644 scripts/tests/snaps/ext1/GFXLiteKey13.png diff --git a/MK404.cpp b/MK404.cpp index 94572a7c..604f0f5c 100644 --- a/MK404.cpp +++ b/MK404.cpp @@ -283,6 +283,7 @@ int initGL() // Set up projection matrix glutDisplayFunc(displayCB); /* set window's display callback */ glutKeyboardFunc(KeyCB); /* set window's key callback */ + glutSpecialFunc(KeyController::GLSpecialKeyReceiver); glutMouseFunc(MouseCB); glutPassiveMotionFunc(PassiveMotionCB); glutMotionFunc(MotionCB); diff --git a/parts/KeyController.cpp b/parts/KeyController.cpp index b2dcd62e..e6ca6f27 100644 --- a/parts/KeyController.cpp +++ b/parts/KeyController.cpp @@ -22,6 +22,7 @@ #include "KeyController.h" #include "IKeyClient.h" #include "IScriptable.h" +#include #include #include // for allocator_traits<>::value_type #include @@ -46,6 +47,14 @@ IScriptable::LineStatus KeyController::ProcessAction(unsigned int /*iAction*/, c { key = 0xd; } + else if (vArgs.at(0) == "up") + { + key = GLUT_KEY_UP | SPECIAL_KEY_MASK; + } + else if (vArgs.at(0) == "down") + { + key = GLUT_KEY_DOWN | SPECIAL_KEY_MASK; + } OnKeyPressed(key); return LineStatus::Finished; } @@ -78,6 +87,12 @@ void KeyController::PutNiceKeyName(unsigned char key) case 0xd: std::cout << "Enter"; break; + case GLUT_KEY_UP | SPECIAL_KEY_MASK: + std::cout << "Up Arrow"; + break; + case GLUT_KEY_DOWN | SPECIAL_KEY_MASK: + std::cout << "DOwn Arrow"; + break; default: std::cout << key; break; diff --git a/parts/KeyController.h b/parts/KeyController.h index 9c023ea5..77e507f4 100644 --- a/parts/KeyController.h +++ b/parts/KeyController.h @@ -28,6 +28,8 @@ #include // for string #include // for vector +static constexpr uint8_t SPECIAL_KEY_MASK = 0x80; + class IKeyClient; class KeyController: private Scriptable @@ -46,6 +48,7 @@ class KeyController: private Scriptable void PrintKeys(bool bMarkdown); static inline void GLKeyReceiver(unsigned char key, int /*x*/, int /*y*/) { KeyController::GetController().OnKeyPressed(key); }; + static inline void GLSpecialKeyReceiver(int key, int /*x*/, int /*y*/) { KeyController::GetController().OnKeyPressed(key | SPECIAL_KEY_MASK); }; protected: KeyController(); diff --git a/parts/components/RotaryEncoder.cpp b/parts/components/RotaryEncoder.cpp index e35a6d0f..a50ae94a 100644 --- a/parts/components/RotaryEncoder.cpp +++ b/parts/components/RotaryEncoder.cpp @@ -21,10 +21,11 @@ along with MK404. If not, see . */ - +#include "KeyController.h" #include "RotaryEncoder.h" #include "TelemetryHost.h" #include "gsl-lite.hpp" +#include #include // for copy #include @@ -173,11 +174,13 @@ void RotaryEncoder::OnKeyPress(const Key &key) { switch (key) { + case GLUT_KEY_UP | SPECIAL_KEY_MASK: case 'w': std::cout << '<'; Twist(RotaryEncoder::CCW_CLICK); //if (m_pVis) m_pVis->TwistKnob(true); break; + case GLUT_KEY_DOWN | SPECIAL_KEY_MASK: case 's': std::cout << '>'; Twist(RotaryEncoder::CW_CLICK); @@ -202,7 +205,9 @@ RotaryEncoder::RotaryEncoder(bool bVerbose):Scriptable("Encoder"),IKeyClient(),m RegisterActionAndMenu("TwistCCW", "Twists the encoder once cycle counterclockwise",ActTwistCCW); RegisterKeyHandler('w', "Twists encoder CCW"); + RegisterKeyHandler(GLUT_KEY_UP | SPECIAL_KEY_MASK, "Twists encoder CCW"); RegisterKeyHandler('s', "Twists encoder CW"); + RegisterKeyHandler(GLUT_KEY_DOWN | SPECIAL_KEY_MASK, "Twists encoder CW"); RegisterKeyHandler('h', "Pushes and long-holds the encoder button."); RegisterKeyHandler(0xd, "Pushes and releases the encoder button"); } diff --git a/scripts/tests/snaps/ext1/GFXLiteKey13.png b/scripts/tests/snaps/ext1/GFXLiteKey13.png new file mode 100644 index 0000000000000000000000000000000000000000..016c273898fe31ef258ed906d6e660638bdc1799 GIT binary patch literal 1525 zcmaKsdpOez7{_O}HbY4>tYM+!vR_y$w>cP_q-1065{KM7l1svJolR;M$bW;`fDwIKN@~qj4a2j~ee}p3g zF2SQSkF88Lgfo$9H_Qkfg;G*)AK505*Pn_{@O`3#1b!jc+uL6}FK6iw@BH_(5Dcll z$g^&$=xhS4F@@91I$rxi~#Jt=9@i zQ&ZBM1&BiX86AWw2^Z+#+}L2x953w6=-1HUqBH5xU*Z@Bd>;!Fz2H-6VETCoG7opo zZomPUTAnj(j2g5?bE|RwG#R!f!Z$JLODPCE@Fnd`INR_5X;-MC?zKoW6hh#^(6Y=n zH>bbeP7%pq5mCCzSXHR01rqocvEisc5WC^cX_e+fG2jP=S=N(qXObw|#T3&T-vdg4 z!nu(YW6GuD^Pz}&>UlHNg_2kJLkdM7%G9dX0L^rj*7TfgpD7NqpvX@?CkSFzQgPRoCrQw^l5M+# zUSBE|IYtFz#nMdG;p0iGGJ_4dGM36%JiS=UB3ty)idFp$P+_eeaZCQI=jZGqW>bWU zMGz8G&DS42sTh$R|^2-dW?Xcu_$O$1K&_WMEMvPXqgaa?i#17I$8aM z^8Eg6wSI^E!-%tb@C?9MW%H_LcZ;9V;-c@ki6iXg1h=Wi7< z`h_?lN{Ty<;#n}lSU}$H6MufKC*;$J4`p|B-NG6tD^;D=+c~_!QAMyOL?Pg(fk@K= z|AzGLcv0BUK@oy9UooPs@7Oh^g@XVV;LMY4DNsN>b}QGtpBvlT1|aQo?~{7$)YV~p zy)y2yV62eo{XzfHct`pN*Y;VSf%CCsjbwM4T4K!^RC=tAkmqh{C{pNpA(~&QGjr$+SGH##XAt3~rp&DPaf^%refVMqVRivOr`Q@Zw}jBBeT S@yM3WL5C^F$c;9BX@3KVv#F>6 literal 0 HcmV?d00001 diff --git a/scripts/tests/test_lite_gfx_keys.txt b/scripts/tests/test_lite_gfx_keys.txt index debf03d2..78aad880 100644 --- a/scripts/tests/test_lite_gfx_keys.txt +++ b/scripts/tests/test_lite_gfx_keys.txt @@ -14,7 +14,7 @@ Board::WaitMs(10) 3DView::SnapRect(tests/snaps/GFXLiteKey03,477,711,88,88) KeyCtl::Key(s) Board::WaitMs(1) -KeyCtl::Key(s) +KeyCtl::Key(down) Board::WaitMs(10) 3DView::SnapRect(tests/snaps/GFXLiteKey04,477,711,88,88) KeyCtl::Key(c) @@ -48,4 +48,7 @@ GLHelper::SnapRect(tests/snaps/GFXLiteKey11,0,0,500,200) KeyCtl::Key(t) Board::WaitMs(100) GLHelper::SnapRect(tests/snaps/GFXLiteKey11a,0,0,500,200) +KeyCtl::Key(up) +Board::WaitMs(10) +3DView::SnapRect(tests/snaps/GFXLiteKey13,477,711,88,88) KeyCtl::Key(q) diff --git a/utility/MK3SGL.cpp b/utility/MK3SGL.cpp index aa65978b..d651614b 100644 --- a/utility/MK3SGL.cpp +++ b/utility/MK3SGL.cpp @@ -106,8 +106,10 @@ MK3SGL::MK3SGL(const std::string &strModel, bool bMMU, Printer *pParent):Scripta RegisterAction("MouseMove", "Simulates a mouse move (x,y)", ActMouseMove, {ArgType::Int,ArgType::Int}); RegisterKeyHandler('`', "Reset camera view to default"); - RegisterKeyHandler('w',""); - RegisterKeyHandler('s',""); + RegisterKeyHandler('w', ""); + RegisterKeyHandler(GLUT_KEY_UP | SPECIAL_KEY_MASK, ""); + RegisterKeyHandler('s', ""); + RegisterKeyHandler(GLUT_KEY_DOWN | SPECIAL_KEY_MASK, ""); // RegisterKeyHandler('5',""); // RegisterKeyHandler('6',""); @@ -132,6 +134,7 @@ MK3SGL::MK3SGL(const std::string &strModel, bool bMMU, Printer *pParent):Scripta glutDisplayFunc(fcnDraw); glutKeyboardFunc(KeyController::GLKeyReceiver); // same func as main window. + glutSpecialFunc(KeyController::GLSpecialKeyReceiver); auto fwd = [](int button, int state, int x, int y) {g_pMK3SGL->MouseCB(button,state,x,y);}; glutMouseFunc(fwd); @@ -210,9 +213,13 @@ void MK3SGL::OnKeyPress(const Key& key) case '`': ResetCamera(); break; + case GLUT_KEY_UP | SPECIAL_KEY_MASK: case 'w': + TwistKnob(true); + break; + case GLUT_KEY_DOWN | SPECIAL_KEY_MASK: case 's': - TwistKnob(key=='w'); + TwistKnob(false); break; // case '5': // case '6':