neu-rah / ArduinoMenu

Arduino generic menu/interactivity system
GNU Lesser General Public License v2.1
952 stars 192 forks source link

Support for Adafruit S7789 breakout board using teensy NOT esp #316

Open ghost opened 4 years ago

ghost commented 4 years ago

I want to use my ST7789 display. If I include all the headers and setup code for this display it turns on. I can't change the background.

neu-rah commented 4 years ago

Hi! have you tried to mess with the colors table?

ghost commented 4 years ago

I have been busy moving to platformio from the Arduino IDE. I am also making some progress. I am using your btnNav sketch and trying to send the output to an ST7789.

The code is below. It fails on line 201 with the macro

,ADAGFX_OUT(gfx,colors,6*textScale,9*textScale,{0,0,14,8},{14,0,14,8})

no instance of constructor Menu::adaGfxOut::adaGfxOut matches the argument list -- argument types are: (Adafruit_ST7789, const Menu::colorDef<uint16_t> [5], Menu::idx_t [4], Menu::panelsList, int, int)

I can's figure out the last four arguments to the macro. The line I am using is from your code somewhere else in the library. I got the gfx and colors arguments to work.

Thanks for your attention.

/** This is a library for several Adafruit displays based on ST77* drivers.

Works with the Adafruit 1.8" gfx Breakout w/SD card ----> http://www.adafruit.com/products/358 The 1.8" gfx shield ----> https://www.adafruit.com/product/802 The 1.44" gfx breakout ----> https://www.adafruit.com/product/2088 The 1.14" gfx breakout ----> https://www.adafruit.com/product/4383 The 1.3" gfx breakout ----> https://www.adafruit.com/product/4313 The 1.54" gfx breakout ----> https://www.adafruit.com/product/3787 The 2.0" gfx breakout ----> https://www.adafruit.com/product/4311 as well as Adafruit raw 1.8" gfx display ----> http://www.adafruit.com/products/618

Check out the links above for our tutorials and wiring diagrams. These displays use SPI to communicate, 4 or 5 pins are required to interface (RST is optional).

Written by Limor Fried/Ladyada for Adafruit Industries. MIT license, all text above must be included in any redistribution Adafruit invests time and resources providing this open source code, please support Adafruit and open-source hardware by purchasing products from Adafruit!

/* Arduino menu library example
Oct. 2016 Rui Azevedo (ruihfazevedo@gmail.com) www.r-site.net

Digital keypad (3 buttons) using the menu keyIn driver
*/

#include <Arduino.h>
#include <menu.h>
#include <menuIO/serialIn.h>
#include <menuIO/serialOut.h>
#include <menuIO/altKeyIn.h>
#include <menuIO/chainStream.h>
//#include <menuIO/chainStream.h>    // Core graphics library
#include <Adafruit_GFX.h>
#include <menuIO/adafruitGfxOut.h> // Hardware-specific library for ST77XX
#include <Adafruit_ST7789.h> // Hardware-specific library for ST7789
#include <Adafruit_ST77xx.h>
#include <SPI.h>

#if defined(ARDUINO_FEATHER_ESP32) // Feather Huzzah32
  #define gfx_CS         14
  #define gfx_RST        15
  #define gfx_DC         32

#elif defined(ESP8266)
  #define gfx_CS         4
  #define gfx_RST        16                                            
  #define gfx_DC         5

#else
  // For the breakout board, you can use any 2 or 3 pins.
  // These pins will also work for the 1.8" gfx shield.
  #define gfx_CS        10
  #define gfx_RST        9 // Or set to -1 and connect to Arduino RESET pin
  #define gfx_DC         8
#endif
   #define MAX_DEPTH 4
  #define textScale 1

// OPTION 1 (recommended) is to use the HARDWARE SPI pins, which are unique
// to each board and not reassignable. For Arduino Uno: MOSI = pin 11 and
// SCLK = pin 13. This is the fastest mode of operation and is required if
// using the breakout board's microSD card.

// For 1.44" and 1.8" gfx with ST77XX use:
//Adafruit_ST77XX gfx = Adafruit_ST77XX(gfx_CS, gfx_DC, gfx_RST);

// For 1.14", 1.3", 1.54", and 2.0" gfx with ST7789:
Adafruit_ST7789 gfx = Adafruit_ST7789(gfx_CS, gfx_DC, gfx_RST);

const colorDef<uint16_t> colors[5] MEMMODE={
  {{(uint16_t)ST77XX_BLACK,(uint16_t)ST77XX_BLACK}, {(uint16_t)ST77XX_BLACK, (uint16_t)ST77XX_BLUE,  (uint16_t)ST77XX_BLUE}},//bgColor
//  {{(uint16_t)ST77XX_GREY, (uint16_t)ST77XX_GRAY},  {(uint16_t)ST77XX_WHITE, (uint16_t)ST77XX_WHITE, (uint16_t)ST77XX_WHITE}},//fgColor
  {{(uint16_t)ST77XX_WHITE,(uint16_t)ST77XX_BLACK}, {(uint16_t)ST77XX_YELLOW,(uint16_t)ST77XX_YELLOW,(uint16_t)ST77XX_RED}},//valColor
  {{(uint16_t)ST77XX_WHITE,(uint16_t)ST77XX_BLACK}, {(uint16_t)ST77XX_WHITE, (uint16_t)ST77XX_YELLOW,(uint16_t)ST77XX_YELLOW}},//unitColor
  {{(uint16_t)ST77XX_WHITE,(uint16_t)ST77XX_BLUE},  {(uint16_t)ST77XX_BLACK, (uint16_t)ST77XX_BLUE,  (uint16_t)ST77XX_WHITE}},//cursorColor
  {{(uint16_t)ST77XX_WHITE,(uint16_t)ST77XX_YELLOW},{(uint16_t)ST77XX_BLUE,  (uint16_t)ST77XX_RED,   (uint16_t)ST77XX_RED}},//titleColor
};

using namespace Menu;

#define LEDPIN 13
// #define MAX_DEPTH 2

#define BTN_SEL -4  // Select button
#define BTN_UP -1 // Up
#define BTN_DOWN -0 // Down

result doAlert(eventMask e, prompt &item);

result showEvent(eventMask e) {
  gfx.print("event: ");
  gfx.println(e);
  return proceed;
}

int test=55;

result action1(eventMask e,navNode& nav, prompt &item) {
  gfx.print("action1 event:");
  gfx.println(e);
  gfx.flush();
  return proceed;
}

result action2(eventMask e) {
  gfx.print("actikcon2 event:");
  gfx.println(e);
  gfx.flush();
  return quit;
}

int ledCtrl=LOW;

result myLedOn() {
  ledCtrl=HIGH;
  return proceed;
}
result myLedOff() {
  ledCtrl=LOW;
  return proceed;
}

TOGGLE(ledCtrl,setLed,"Led: ",doNothing,noEvent,wrapStyle//,doExit,enterEvent,noStyle
  ,VALUE("On",HIGH,doNothing,noEvent)
  ,VALUE("Off",LOW,doNothing,noEvent)
);

int selTest=0;
SELECT(selTest,selMenu,"Select",doNothing,noEvent,wrapStyle
  ,VALUE("Zero",0,doNothing,noEvent)
  ,VALUE("One",1,doNothing,noEvent)
  ,VALUE("Two",2,doNothing,noEvent)
);

int chooseTest=-1;
CHOOSE(chooseTest,chooseMenu,"Choose",doNothing,noEvent,wrapStyle
  ,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(F("special prompt!"),len);;
  }
};

MENU(subMenu,"Sub-Menu",doNothing,anyEvent,wrapStyle
  ,OP("Sub1",showEvent,enterEvent)
  ,OP("Sub2",showEvent,enterEvent)
  ,OP("Sub3",showEvent,enterEvent)
  ,altOP(altPrompt,"",showEvent,enterEvent)
  ,EXIT("<Back")
);

MENU(mainMenu,"Main menu",doNothing,noEvent,wrapStyle
  ,OP("Op1",action1,anyEvent)
  ,OP("Op2",action2,enterEvent)
  //,SUBMENU(togOp)
  ,FIELD(test,"Test","%",0,100,10,1,doNothing,noEvent,wrapStyle)
  ,SUBMENU(subMenu)
  ,SUBMENU(setLed)
  ,OP("LED On",myLedOn,enterEvent)
  ,OP("LED Off",myLedOff,enterEvent)
  ,SUBMENU(selMenu)
  ,SUBMENU(chooseMenu)
  ,OP("Alert test",doAlert,enterEvent)
  ,EXIT("<Back")
);

keyMap joystickBtn_map[]={
 {-BTN_SEL, defaultNavCodes[enterCmd].ch,INPUT_PULLUP} ,
 {-BTN_UP, defaultNavCodes[upCmd].ch,INPUT_PULLUP} ,
 {-BTN_DOWN, defaultNavCodes[downCmd].ch,INPUT_PULLUP}  ,
};
keyIn<3> joystickBtns(joystickBtn_map);

serialIn serial(serial);
menuIn* inputsList[]={&joystickBtns,&serial};
chainStream<2> in(inputsList);//3 is the number of inputs

MENU_OUTPUTS(out,MAX_DEPTH
  ,ADAGFX_OUT(gfx,colors,6*textScale,9*textScale,{0,0,14,8},{14,0,14,8})
  ,SERIAL_OUT(Serial)
  );

NAVROOT(nav,mainMenu,MAX_DEPTH,in,out);

result alert(menuOut& o,idleEvent e) {
  if (e==idling) {
    o.setCursor(0,0);
    o.print("alert test");
    o.setCursor(0,1);
    o.print("[select] to continue...");
  }
  return proceed;
}

result doAlert(eventMask e, prompt &item) {
  nav.idleOn(alert);
  return proceed;
}

void setup() {
  Serial.begin(115200);
  while(!Serial);
  pinMode(LEDPIN, OUTPUT);
  joystickBtns.begin();

SPI.begin();
  gfx.init(240,135,0);
  gfx.setRotation(3);
  gfx.setTextSize(textScale);//test scalling
  gfx.setTextWrap(false);
  gfx.fillScreen(ST77XX_BLACK);
  gfx.setTextColor(ST77XX_RED,ST77XX_BLACK);
  gfx.println("Menu 4.x test on GFX");
  delay(1000);

#define SOFT_DEBOUNCE_MS 100
}
void loop() {

  nav.poll();//also do  input
  digitalWrite(LEDPIN, ledCtrl);
}