neu-rah / ArduinoMenu

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

adafruitGfxOut draws menu only once #353

Open steinerlein opened 3 years ago

steinerlein commented 3 years ago

Hi, I am having an issue where the menu only draws once after uploading my sketch. After uploading, I can see the menu displayed on the OLED display. When I turn the encoder, nothing changes. At the same time, I can see the menu change over serial just fine. If I print the encoder value to the screen directly, it displays it fine also. (See the lines I commented out)

What am I doing wrong? Thanks!

edit: I changed the provided code and removed the threading library for now. It still behaves as described above. I really could use some help, as I can't seem to figure it out on my own :-(

#include "Arduino.h"
#include "QuadEncoder.h"
#include <Adafruit_SSD1327.h>
#include <menu.h>
#include <menuIO/adafruitGfxOut.h>
#include <menuIO/chainStream.h>
#include <menuIO/rotaryEventIn.h>
#include <menuIO/serialOut.h>

using namespace Menu;

//ROTARY_ENCODER
#define ROTARY_PIN_A 31
#define ROTARY_PIN_B 33
#define ROTARY_PIN_BUT 37

//DISPLAY
#define PIN_CS 10
#define PIN_DC 9
#define PIN_RST 6

int usermenuThreadId;

Adafruit_SSD1327 disp(128, 128, &SPI, PIN_DC, PIN_RST, PIN_CS);

const colorDef<uint16_t> colors[6] MEMMODE = {
    {{SSD1327_WHITE, SSD1327_BLACK}, {SSD1327_WHITE, SSD1327_BLACK, SSD1327_BLACK}}, //bgColor
    {{SSD1327_BLACK, SSD1327_WHITE}, {SSD1327_BLACK, SSD1327_WHITE, SSD1327_WHITE}}, //fgColor
    {{SSD1327_BLACK, SSD1327_WHITE}, {SSD1327_BLACK, SSD1327_WHITE, SSD1327_WHITE}}, //valColor
    {{SSD1327_BLACK, SSD1327_WHITE}, {SSD1327_BLACK, SSD1327_WHITE, SSD1327_WHITE}}, //unitColor
    {{SSD1327_BLACK, SSD1327_WHITE}, {SSD1327_WHITE, SSD1327_WHITE, SSD1327_WHITE}}, //cursorColor
    {{SSD1327_BLACK, SSD1327_WHITE}, {SSD1327_WHITE, SSD1327_BLACK, SSD1327_BLACK}}, //titleColor
};

#define gfxWidth 128
#define gfxHeight 128
#define fontX 7
#define fontY 12

#define MAX_DEPTH 1

unsigned int timeOn  = 10;
unsigned int timeOff = 90;

using namespace Menu;
MENU(mainMenu, "Blink menu", Menu::doNothing, Menu::noEvent, Menu::wrapStyle, FIELD(timeOn, "On", "ms", 0, 1000, 10, 1, Menu::doNothing, Menu::noEvent, Menu::noStyle), FIELD(timeOff, "Off", "ms", 0, 10000, 10, 1, Menu::doNothing, Menu::noEvent, Menu::noStyle), EXIT("<Back"));

RotaryEventIn reIn(
    RotaryEventIn::EventType::BUTTON_CLICKED |
    RotaryEventIn::EventType::ROTARY_CCW |
    RotaryEventIn::EventType::ROTARY_CW |
    RotaryEventIn::EventType::BUTTON_DOUBLE_CLICKED |
    RotaryEventIn::EventType::BUTTON_LONG_PRESSED);
MENU_INPUTS(in, &reIn);

MENU_OUTPUTS(out, MAX_DEPTH,
             ADAGFX_OUT(disp, colors, fontX, fontY, {0, 0, gfxWidth / fontX, gfxHeight / fontY}),
             SERIAL_OUT(Serial));

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

long int encoder = 0;
QuadEncoder enc(1, ROTARY_PIN_B, ROTARY_PIN_A, 1);

void setup()
{
    Serial.begin(115200);

    pinMode(ROTARY_PIN_BUT, INPUT_PULLUP);

    enc.setInitConfig();
    enc.init();

    SPI.begin();

    disp.begin();
    disp.clearDisplay();
}

void loop()
{
    long int newEncoder = enc.read();
    if (newEncoder != encoder)
    {
        if (newEncoder > encoder)
        {
            //CW
            reIn.registerEvent(RotaryEventIn::EventType::ROTARY_CW);
        }
        if (newEncoder < encoder)
        {
            //CCW
            reIn.registerEvent(RotaryEventIn::EventType::ROTARY_CCW);
        }
        encoder = newEncoder;
    }

    //disp.fillScreen(SSD1327_WHITE);
    //disp.setCursor(3, 20);
    //disp.print(encoder);

    nav.doInput();
    nav.doOutput();
    disp.display();
    delay(10);
}
steinerlein commented 3 years ago

@neu-rah can you make out anything that could help me with this issue? Thanks!