From b7e0707164659a6a2274d15658c7fd791bddbf8f Mon Sep 17 00:00:00 2001 From: Carl Pedersen Date: Sun, 28 Jan 2018 13:53:38 +0100 Subject: [PATCH] Added OzOled menuIO and example --- examples/OzOledAscii/OzOledAscii.ino | 166 +++++++++++++++++++++++++++ src/menuIO/OzOledAsciiOut.h | 44 +++++++ 2 files changed, 210 insertions(+) create mode 100644 examples/OzOledAscii/OzOledAscii.ino create mode 100644 src/menuIO/OzOledAsciiOut.h diff --git a/examples/OzOledAscii/OzOledAscii.ino b/examples/OzOledAscii/OzOledAscii.ino new file mode 100644 index 00000000..2d93a2c9 --- /dev/null +++ b/examples/OzOledAscii/OzOledAscii.ino @@ -0,0 +1,166 @@ + +//using https://github.com/kdkanishka/ozoled-oled-display-096-i2c-driver-library + +#include +#include "OzOLED.h" + +#include +#include +#include +using namespace Menu; + +//Redefine already existing object +#define oled OzOled + +result doAlert(eventMask e, prompt &item); + +result showEvent(eventMask e,navNode& nav,prompt& item) { + Serial.print("event: "); + Serial.println(e); + return proceed; +} + +int test=55; + +result action1(eventMask e) { + Serial.print(e); + Serial.println(" action1 executed, proceed menu");Serial.flush(); + return proceed; +} + +result action2(eventMask e,navNode& nav, prompt &item) { + Serial.print(e); + Serial.println(" action2 executed, quiting menu"); + return quit; +} + +int ledCtrl=LOW; + +result ledOn() { + ledCtrl=HIGH; + return proceed; +} +result ledOff() { + ledCtrl=LOW; + return proceed; +} + +TOGGLE(ledCtrl,setLed,"Led: ",doNothing,noEvent,noStyle//,doExit,enterEvent,noStyle + ,VALUE("On",HIGH,doNothing,noEvent) + ,VALUE("Off",LOW,doNothing,noEvent) +); + +int selTest=0; +SELECT(selTest,selMenu,"Select",doNothing,noEvent,noStyle + ,VALUE("Zero",0,doNothing,noEvent) + ,VALUE("One",1,doNothing,noEvent) + ,VALUE("Two",2,doNothing,noEvent) +); + +int chooseTest=-1; +CHOOSE(chooseTest,chooseMenu,"Choose",doNothing,noEvent,noStyle + ,VALUE("First",1,doNothing,noEvent) + ,VALUE("Second",2,doNothing,noEvent) + ,VALUE("Third",3,doNothing,noEvent) + ,VALUE("Last",-1,doNothing,noEvent) +); + +//customizing a prompt look! +//by extending the prompt class +class altPrompt:public prompt { +public: + altPrompt(constMEM promptShadow& p):prompt(p) {} + Used printTo(navRoot &root,bool sel,menuOut& out, idx_t idx,idx_t len,idx_t) override { + return out.printRaw("special prompt!",len); + } +}; + +MENU(subMenu,"Sub-Menu",showEvent,anyEvent,noStyle + ,OP("Sub1",showEvent,anyEvent) + ,OP("Sub2",showEvent,anyEvent) + ,OP("Sub3",showEvent,anyEvent) + ,altOP(altPrompt,"",showEvent,anyEvent) + ,EXIT(" + // #include + + namespace Menu { + + class OzOledAsciiOut:public menuOut { + public: + OzOLED* device; + inline OzOledAsciiOut(OzOLED* o,idx_t *t,panelsList &p,menuOut::styles s=menuOut::minimalRedraw) + :menuOut(t,p,s),device(o) {} + size_t write(uint8_t ch) override { device->printChar(ch); return 1;} + void clearLine(idx_t ln,idx_t panelNr=0,colorDefs color=bgColor,bool selected=false,status stat=enabledStatus,bool edit=false) override { + setCursor(0,ln,panelNr); + for(int n=0;nclearDisplay(); + panels.reset(); + } + void clear(idx_t panelNr) override { + const panel p=panels[panelNr]; + fill(p.x,p.y,p.x+p.w-1,p.y+p.h-1); + setCursor(0,0,panelNr); + panels.nodes[panelNr]=NULL; + } + void setCursor(idx_t x,idx_t y,idx_t panelNr=0) override { + const panel p=panels[panelNr]; + device->setCursorXY(p.x+x,p.y+y); + } + }; + + }//namespace Menu + +#endif