feat: example basically works!!
This commit is contained in:
commit
8ea6b47708
|
@ -0,0 +1,3 @@
|
|||
.pio
|
||||
/.cache/
|
||||
/compile_commands.json
|
|
@ -0,0 +1,39 @@
|
|||
|
||||
This directory is intended for project header files.
|
||||
|
||||
A header file is a file containing C declarations and macro definitions
|
||||
to be shared between several project source files. You request the use of a
|
||||
header file in your project source file (C, C++, etc) located in `src` folder
|
||||
by including it, with the C preprocessing directive `#include'.
|
||||
|
||||
```src/main.c
|
||||
|
||||
#include "header.h"
|
||||
|
||||
int main (void)
|
||||
{
|
||||
...
|
||||
}
|
||||
```
|
||||
|
||||
Including a header file produces the same results as copying the header file
|
||||
into each source file that needs it. Such copying would be time-consuming
|
||||
and error-prone. With a header file, the related declarations appear
|
||||
in only one place. If they need to be changed, they can be changed in one
|
||||
place, and programs that include the header file will automatically use the
|
||||
new version when next recompiled. The header file eliminates the labor of
|
||||
finding and changing all the copies as well as the risk that a failure to
|
||||
find one copy will result in inconsistencies within a program.
|
||||
|
||||
In C, the usual convention is to give header files names that end with `.h'.
|
||||
It is most portable to use only letters, digits, dashes, and underscores in
|
||||
header file names, and at most one dot.
|
||||
|
||||
Read more about using header files in official GCC documentation:
|
||||
|
||||
* Include Syntax
|
||||
* Include Operation
|
||||
* Once-Only Headers
|
||||
* Computed Includes
|
||||
|
||||
https://gcc.gnu.org/onlinedocs/cpp/Header-Files.html
|
|
@ -0,0 +1,46 @@
|
|||
|
||||
This directory is intended for project specific (private) libraries.
|
||||
PlatformIO will compile them to static libraries and link into executable file.
|
||||
|
||||
The source code of each library should be placed in a an own separate directory
|
||||
("lib/your_library_name/[here are source files]").
|
||||
|
||||
For example, see a structure of the following two libraries `Foo` and `Bar`:
|
||||
|
||||
|--lib
|
||||
| |
|
||||
| |--Bar
|
||||
| | |--docs
|
||||
| | |--examples
|
||||
| | |--src
|
||||
| | |- Bar.c
|
||||
| | |- Bar.h
|
||||
| | |- library.json (optional, custom build options, etc) https://docs.platformio.org/page/librarymanager/config.html
|
||||
| |
|
||||
| |--Foo
|
||||
| | |- Foo.c
|
||||
| | |- Foo.h
|
||||
| |
|
||||
| |- README --> THIS FILE
|
||||
|
|
||||
|- platformio.ini
|
||||
|--src
|
||||
|- main.c
|
||||
|
||||
and a contents of `src/main.c`:
|
||||
```
|
||||
#include <Foo.h>
|
||||
#include <Bar.h>
|
||||
|
||||
int main (void)
|
||||
{
|
||||
...
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
PlatformIO Library Dependency Finder will find automatically dependent
|
||||
libraries scanning project source files.
|
||||
|
||||
More information about PlatformIO Library Dependency Finder
|
||||
- https://docs.platformio.org/page/librarymanager/ldf.html
|
|
@ -0,0 +1,17 @@
|
|||
; PlatformIO Project Configuration File
|
||||
;
|
||||
; Build options: build flags, source filter
|
||||
; Upload options: custom upload port, speed and extra flags
|
||||
; Library options: dependencies, extra library storages
|
||||
; Advanced options: extra scripting
|
||||
;
|
||||
; Please visit documentation for the other options and examples
|
||||
; https://docs.platformio.org/page/projectconf.html
|
||||
|
||||
[env:esp32dev]
|
||||
platform = espressif32
|
||||
board = esp32dev
|
||||
framework = arduino
|
||||
lib_deps = neu-rah/ArduinoMenu library@^4.21.4
|
||||
olikraus/U8g2@^2.35.17
|
||||
; build_flags = -Ilib -Isrc
|
|
@ -0,0 +1,282 @@
|
|||
#include "esp32-hal-gpio.h"
|
||||
#include "menuBase.h"
|
||||
#include <Arduino.h>
|
||||
|
||||
/********#include "esp32-hal-gpio.h"
|
||||
************
|
||||
Arduino generic menu system
|
||||
U8G2 menu exampl#include "esp32-hal-gpio.h"
|
||||
e
|
||||
U8G2: https://github.com/olikraus/u8g2
|
||||
|
||||
Oct. 2016 Stephen Denne https://github.com/datacute
|
||||
Based on example from Rui Azevedo - ruihfazevedo(@rrob@)gmail.com
|
||||
Original from: https://github.com/christophepersoz
|
||||
|
||||
menu on U8G2 device
|
||||
output: Wemos D1 mini OLED Shield (SSD1306 64x48 I2C) + Serial
|
||||
input: Serial + encoder
|
||||
mcu: nano328p
|
||||
|
||||
*/
|
||||
|
||||
#include <menu.h>
|
||||
#include <menuIO/u8g2Out.h>
|
||||
// #include <menuIO/encoderIn.h>
|
||||
#include <menuIO/altKeyIn.h>
|
||||
#include <menuIO/chainStream.h>
|
||||
#include <menuIO/serialIn.h>
|
||||
#include <menuIO/serialOut.h>
|
||||
|
||||
using namespace Menu;
|
||||
|
||||
#define LEDPIN 9
|
||||
#define BTN_SEL 33
|
||||
#define BTN_UP 32
|
||||
#define BTN_DOWN 25
|
||||
|
||||
// #define USE_PCD8544
|
||||
#define USE_SSD1306
|
||||
|
||||
#if defined(USE_PCD8544)
|
||||
// rotary encoder pins
|
||||
// #define encA 2
|
||||
// #define encB 3
|
||||
// #define encBtn 4
|
||||
|
||||
#include <SPI.h>
|
||||
#define USE_HWSPI
|
||||
#define U8_DC 9
|
||||
#define U8_CS 8
|
||||
#define U8_RST 7
|
||||
#define fontName u8g2_font_5x7_tf
|
||||
#define fontX 5
|
||||
#define fontY 9
|
||||
#define offsetX 0
|
||||
#define offsetY 0
|
||||
#define U8_Width 84
|
||||
#define U8_Height 48
|
||||
U8G2_PCD8544_84X48_1_4W_HW_SPI u8g2(U8G2_R0, U8_CS, U8_DC, U8_RST);
|
||||
#elif defined(USE_SSD1306)
|
||||
// rotary encoder pins
|
||||
// #define encA 5
|
||||
// #define encB 6
|
||||
// #define encBtn 7
|
||||
|
||||
#include <Wire.h>
|
||||
#define fontName u8g2_font_7x13_mf
|
||||
#define fontX 7
|
||||
#define fontY 16
|
||||
#define offsetX 0
|
||||
#define offsetY 3
|
||||
#define U8_Width 128
|
||||
#define U8_Height 64
|
||||
#define USE_HWI2C
|
||||
// U8G2_SSD1306_128X64_NONAME_F_HW_I2C u8g2(U8G2_R0);//, SCL, SDA);
|
||||
// U8G2_SSD1306_128X64_NONAME_F_HW_I2C u8g2(U8G2_R2, U8X8_PIN_NONE, 4, 5);
|
||||
// U8G2_SSD1306_128X64_VCOMH0_F_HW_I2C u8g2(U8G2_R2, U8X8_PIN_NONE, 4, 5);
|
||||
U8G2_SSD1306_128X64_NONAME_1_HW_I2C u8g2(U8G2_R0, U8X8_PIN_NONE, 4, 5);
|
||||
#else
|
||||
#error DEFINE YOUR OUTPUT HERE.
|
||||
#endif
|
||||
|
||||
// define menu colors --------------------------------------------------------
|
||||
// each color is in the format:
|
||||
// {{disabled normal,disabled selected},{enabled normal,enabled selected,
|
||||
// enabled editing}}
|
||||
// this is a monochromatic color table
|
||||
const colorDef<uint8_t> colors[6] MEMMODE = {
|
||||
{{0, 0}, {0, 1, 1}}, // bgColor
|
||||
{{1, 1}, {1, 0, 0}}, // fgColor
|
||||
{{1, 1}, {1, 0, 0}}, // valColor
|
||||
{{1, 1}, {1, 0, 0}}, // unitColor
|
||||
{{0, 1}, {0, 0, 1}}, // cursorColor
|
||||
{{1, 1}, {1, 0, 0}}, // titleColor
|
||||
};
|
||||
|
||||
result doAlert(eventMask e, prompt &item);
|
||||
|
||||
int test = 55;
|
||||
|
||||
int ledCtrl = HIGH;
|
||||
|
||||
result myLedOn() {
|
||||
ledCtrl = HIGH;
|
||||
return proceed;
|
||||
}
|
||||
result myLedOff() {
|
||||
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
|
||||
// panelNr) override {
|
||||
// return out.printRaw(F("special prompt!"),len);;
|
||||
// }
|
||||
// };
|
||||
|
||||
MENU(subMenu, "Sub-Menu", doNothing, noEvent, noStyle,
|
||||
OP("Sub1", doNothing, noEvent)
|
||||
// ,altOP(altPrompt,"",doNothing,noEvent)
|
||||
,
|
||||
EXIT("<Back"));
|
||||
|
||||
uint16_t hrs = 0;
|
||||
uint16_t mins = 0;
|
||||
|
||||
// define a pad style menu (single line menu)
|
||||
// here with a set of fields to enter a date in YYYY/MM/DD format
|
||||
altMENU(menu, timeMenu, "Time", doNothing, noEvent, noStyle,
|
||||
(systemStyles)(_asPad | Menu::_menuData | Menu::_canNav | _parentDraw),
|
||||
FIELD(hrs, "", ":", 0, 11, 1, 0, doNothing, noEvent, noStyle),
|
||||
FIELD(mins, "", "", 0, 59, 10, 1, doNothing, noEvent, wrapStyle));
|
||||
|
||||
char *constMEM hexDigit MEMMODE = "0123456789ABCDEF";
|
||||
char *constMEM hexNr[] MEMMODE = {"0", "x", hexDigit, hexDigit};
|
||||
char buf1[] = "0x11";
|
||||
|
||||
MENU(mainMenu, "Main menu", doNothing, noEvent, wrapStyle,
|
||||
OP("Op1", doNothing, noEvent),
|
||||
OP("Op2", doNothing, noEvent)
|
||||
//,FIELD(test,"Test","%",0,100,10,1,doNothing,noEvent,wrapStyle)
|
||||
,
|
||||
SUBMENU(timeMenu), SUBMENU(subMenu), SUBMENU(setLed),
|
||||
OP("LED On", myLedOn, enterEvent), OP("LED Off", myLedOff, enterEvent),
|
||||
SUBMENU(selMenu), SUBMENU(chooseMenu),
|
||||
OP("Alert test", doAlert, enterEvent),
|
||||
EDIT("Hex", buf1, hexNr, doNothing, noEvent, noStyle), EXIT("<Exit"));
|
||||
|
||||
#define MAX_DEPTH 2
|
||||
|
||||
// encoderIn<encA,encB> encoder;//simple quad encoder driver
|
||||
// encoderInStream<encA,encB> encStream(encoder,4);// simple quad encoder fake
|
||||
// Stream
|
||||
|
||||
keyMap joystickBtn_map[] = {
|
||||
{BTN_SEL, defaultNavCodes[enterCmd].ch, INPUT_PULLUP},
|
||||
{BTN_UP, defaultNavCodes[upCmd].ch, INPUT_PULLUP},
|
||||
{BTN_DOWN, defaultNavCodes[downCmd].ch, INPUT_PULLUP}}; // negative pin
|
||||
keyIn<3> joystickBtns(joystickBtn_map); // the input driver
|
||||
serialIn serial(Serial);
|
||||
|
||||
// numbers use internal pull-up, this is on when low keyIn<1>
|
||||
// encButton(encBtn_map); // 1 is the number of keys
|
||||
|
||||
// menuIn *inputsList[] = {&joystickBtns, &serial};
|
||||
// chainStream<2> in(inputsList); // 1 is the number of inputs
|
||||
|
||||
// MENU_INPUTS(in, &serial);
|
||||
MENU_INPUTS(in, &joystickBtns, &serial);
|
||||
|
||||
MENU_OUTPUTS(out, MAX_DEPTH,
|
||||
U8G2_OUT(u8g2, colors, fontX, fontY, offsetX, offsetY,
|
||||
{0, 0, U8_Width / fontX, U8_Height / fontY}),
|
||||
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("press [select]");
|
||||
o.setCursor(0, 2);
|
||||
o.print("to continue...");
|
||||
}
|
||||
return proceed;
|
||||
}
|
||||
|
||||
result doAlert(eventMask e, prompt &item) {
|
||||
nav.idleOn(alert);
|
||||
return proceed;
|
||||
}
|
||||
|
||||
// when menu is suspended
|
||||
result idle(menuOut &o, idleEvent e) {
|
||||
o.clear();
|
||||
switch (e) {
|
||||
case idleStart:
|
||||
o.println("suspending menu!");
|
||||
break;
|
||||
case idling:
|
||||
o.println("suspended...");
|
||||
break;
|
||||
case idleEnd:
|
||||
o.println("resuming menu.");
|
||||
break;
|
||||
}
|
||||
return proceed;
|
||||
}
|
||||
|
||||
void setup() {
|
||||
joystickBtns.begin();
|
||||
pinMode(BTN_UP, INPUT_PULLUP);
|
||||
pinMode(BTN_DOWN, INPUT_PULLUP);
|
||||
pinMode(BTN_SEL, INPUT_PULLUP);
|
||||
|
||||
Serial.begin(115200);
|
||||
while (!Serial)
|
||||
;
|
||||
Serial.println("menu 4.x test");
|
||||
Serial.flush();
|
||||
// encButton.begin();
|
||||
// encoder.begin();
|
||||
pinMode(LEDPIN, OUTPUT); // cant use pin 13 when using hw spi
|
||||
// and on esp12 i2c can be on pin 2, and that is also led pin
|
||||
// so check first if this is adequate for your board
|
||||
#if defined(USE_HWSPI)
|
||||
SPI.begin();
|
||||
u8g2.begin();
|
||||
#elif defined(USE_HWI2C)
|
||||
Wire.begin();
|
||||
u8g2.begin();
|
||||
#else
|
||||
#error "please choose your interface (I2c,SPI)"
|
||||
#endif
|
||||
u8g2.setFont(fontName);
|
||||
// u8g2.setBitmapMode(0);
|
||||
|
||||
// disable second option
|
||||
mainMenu[1].enabled = disabledStatus;
|
||||
nav.idleTask = idle; // point a function to be used when menu is suspended
|
||||
Serial.println("setup done.");
|
||||
Serial.flush();
|
||||
}
|
||||
|
||||
void loop() {
|
||||
nav.doInput();
|
||||
digitalWrite(LEDPIN, ledCtrl);
|
||||
if (nav.changed(0)) { // only draw if menu changed for gfx device
|
||||
// change checking leaves more time for other tasks
|
||||
u8g2.firstPage();
|
||||
do
|
||||
nav.doOutput();
|
||||
while (u8g2.nextPage());
|
||||
}
|
||||
delay(100); // simulate other tasks delay
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
|
||||
This directory is intended for PlatformIO Test Runner and project tests.
|
||||
|
||||
Unit Testing is a software testing method by which individual units of
|
||||
source code, sets of one or more MCU program modules together with associated
|
||||
control data, usage procedures, and operating procedures, are tested to
|
||||
determine whether they are fit for use. Unit testing finds problems early
|
||||
in the development cycle.
|
||||
|
||||
More information about PlatformIO Unit Testing:
|
||||
- https://docs.platformio.org/en/latest/advanced/unit-testing/index.html
|
Loading…
Reference in New Issue