mui class
This commit is contained in:
parent
69ae0ac215
commit
a11b71aeb3
|
@ -0,0 +1,78 @@
|
|||
/*
|
||||
|
||||
MUIU8g2.h
|
||||
|
||||
C++ Arduino wrapper for mui.h (monochome minimal user interface)
|
||||
|
||||
Universal 8bit Graphics Library (https://github.com/olikraus/u8g2/)
|
||||
|
||||
Copyright (c) 2016, olikraus@gmail.com
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
are permitted provided that the following conditions are met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright notice, this list
|
||||
of conditions and the following disclaimer.
|
||||
|
||||
* Redistributions in binary form must reproduce the above copyright notice, this
|
||||
list of conditions and the following disclaimer in the documentation and/or other
|
||||
materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
|
||||
CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
||||
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
|
||||
*/
|
||||
|
||||
|
||||
#ifndef MUIU8G2_HH
|
||||
#define MUIU8G2_HH
|
||||
|
||||
#include "mui.h"
|
||||
#include "mui_u8g2.h"
|
||||
|
||||
class MUIU8G2
|
||||
{
|
||||
protected:
|
||||
mui_t mui;
|
||||
public:
|
||||
MUIU8G2(void) { }
|
||||
|
||||
MUIU8G2(U8G2 &u8g2, fds_t *fds, muif_t *muif_list, size_t muif_cnt) {
|
||||
mui_Init(&mui, (void *)u8g2.getU8g2(), fds, muif_list, muif_cnt);
|
||||
}
|
||||
void begin(U8G2 &u8g2, fds_t *fds, muif_t *muif_list, size_t muif_cnt) {
|
||||
mui_Init(&mui, (void *)u8g2.getU8g2(), fds, muif_list, muif_cnt);
|
||||
}
|
||||
mui_t *getMUI(void) { return &mui; }
|
||||
|
||||
uint8_t getCurrentCursorFocusPosition(void) { return mui_GetCurrentCursorFocusPosition(&mui); }
|
||||
void draw(void) { mui_Draw(&mui); }
|
||||
void getSelectableFieldTextOption(uint8_t form_id, uint8_t cursor_position, uint8_t nth_token)
|
||||
{ mui_GetSelectableFieldTextOption(&mui, form_id, cursor_position, nth_token); }
|
||||
void enterForm(fds_t *fds, uint8_t initial_cursor_position) { mui_EnterForm(&mui, fds, initial_cursor_position); }
|
||||
void leaveForm(void) { mui_LeaveForm(&mui); }
|
||||
uint8_t gotoForm(uint8_t form_id, uint8_t initial_cursor_position) { return mui_GotoForm(&mui, form_id, initial_cursor_position); }
|
||||
|
||||
void saveForm(void) { mui_SaveForm(&mui); }
|
||||
void restoreForm(void) { mui_RestoreForm(&mui); }
|
||||
void nextField(void) { mui_NextField(&mui); }
|
||||
void prevField(void) { mui_PrevField(&mui); }
|
||||
void sendSelect(void) { mui_SendSelect(&mui); }
|
||||
int isFormActive(void) { return mui_IsFormActive(&mui); }
|
||||
};
|
||||
|
||||
|
||||
#endif /* MUIU8G2_HH */
|
|
@ -35,8 +35,7 @@
|
|||
|
||||
#include <Arduino.h>
|
||||
#include <U8g2lib.h>
|
||||
#include <mui.h>
|
||||
#include <mui_u8g2.h>
|
||||
#include <MUIU8g2.h>
|
||||
|
||||
#ifdef U8X8_HAVE_HW_SPI
|
||||
#include <SPI.h>
|
||||
|
@ -294,7 +293,7 @@ U8G2_UC1701_EA_DOGS102_1_4W_HW_SPI u8g2(U8G2_R0, /* cs=*/ 10, /* dc=*/ 9, /* res
|
|||
|
||||
|
||||
|
||||
mui_t ui;
|
||||
MUIU8G2 mui;
|
||||
|
||||
|
||||
|
||||
|
@ -519,9 +518,11 @@ void setup(void) {
|
|||
//u8g2.begin(/*Select=*/ A0, /*Right/Next=*/ 5, /*Left/Prev=*/ 9, /*Up=*/ 8, /*Down=*/ 10, /*Home/Cancel=*/ A1); // Arduboy DevKit
|
||||
//u8g2.begin(/*Select=*/ 7, /*Right/Next=*/ A1, /*Left/Prev=*/ A2, /*Up=*/ A0, /*Down=*/ A3, /*Home/Cancel=*/ 8); // Arduboy 10 (Production)
|
||||
|
||||
mui_Init(&ui, u8g2.getU8g2(), fds_data, muif_list, sizeof(muif_list)/sizeof(muif_t));
|
||||
mui_GotoForm(&ui, /* form_id= */ 1, /* initial_cursor_position= */ 0);
|
||||
|
||||
mui.begin(u8g2, fds_data, muif_list, sizeof(muif_list)/sizeof(muif_t));
|
||||
mui.gotoForm(/* form_id= */ 1, /* initial_cursor_position= */ 0);
|
||||
//mui_Init(&ui, u8g2.getU8g2(), fds_data, muif_list, sizeof(muif_list)/sizeof(muif_t));
|
||||
//mui_GotoForm(&ui, /* form_id= */ 1, /* initial_cursor_position= */ 0);
|
||||
}
|
||||
|
||||
uint8_t is_redraw = 1;
|
||||
|
@ -529,7 +530,8 @@ uint8_t is_redraw = 1;
|
|||
void loop(void) {
|
||||
|
||||
/* check whether the menu is active */
|
||||
if ( mui_IsFormActive(&ui) )
|
||||
//if ( mui_IsFormActive(&ui) )
|
||||
if ( mui.isFormActive() )
|
||||
{
|
||||
|
||||
/* if so, then draw the menu */
|
||||
|
@ -537,7 +539,7 @@ void loop(void) {
|
|||
if ( is_redraw ) {
|
||||
u8g2.firstPage();
|
||||
do {
|
||||
mui_Draw(&ui);
|
||||
mui.draw();
|
||||
} while( u8g2.nextPage() );
|
||||
is_redraw = 0;
|
||||
}
|
||||
|
@ -546,15 +548,15 @@ void loop(void) {
|
|||
|
||||
switch(u8g2.getMenuEvent()) {
|
||||
case U8X8_MSG_GPIO_MENU_SELECT:
|
||||
mui_SendSelect(&ui);
|
||||
mui.sendSelect();
|
||||
is_redraw = 1;
|
||||
break;
|
||||
case U8X8_MSG_GPIO_MENU_NEXT:
|
||||
mui_NextField(&ui);
|
||||
mui.nextField();
|
||||
is_redraw = 1;
|
||||
break;
|
||||
case U8X8_MSG_GPIO_MENU_PREV:
|
||||
mui_PrevField(&ui);
|
||||
mui.prevField();
|
||||
is_redraw = 1;
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
CFLAGS = -g -Wall -I../../../csrc/. `sdl2-config --cflags`
|
||||
|
||||
SRC = $(shell ls ../../../csrc/*.c) $(shell ls ../common/*.c ) $(shell ls *.c )
|
||||
SRC = $(shell ls ../../../csrc/*.c) $(shell ls ../common/*.c ) $(shell ls ../../bitmap/common/*.c ) $(shell ls *.c )
|
||||
|
||||
OBJ = $(SRC:.c=.o)
|
||||
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
|
||||
#include "u8g2.h"
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include "mui.h"
|
||||
|
@ -209,6 +210,24 @@ MUI_XYAT("G1",64, 59, 1, " OK ")
|
|||
|
||||
;
|
||||
|
||||
int screenshot_n = 0;
|
||||
|
||||
void do_screenshot(void)
|
||||
{
|
||||
char s[4096];
|
||||
u8x8_SaveBitmapTGA(u8g2_GetU8x8(&u8g2), "screenshot.tga");
|
||||
sprintf( s,
|
||||
"convert -border 4 -bordercolor 'rgb(255,190,40)'"
|
||||
" -fill 'rgb(255,170,0)' -opaque white"
|
||||
" -filter point -resize 200%%"
|
||||
" screenshot.tga pic%04d.png", screenshot_n);
|
||||
system(s);
|
||||
screenshot_n++;
|
||||
/*
|
||||
gif animation:
|
||||
convert -delay 40 -loop 0 pic*.png animation.gif
|
||||
*/
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
|
@ -220,9 +239,10 @@ int main(void)
|
|||
u8x8_InitDisplay(u8g2_GetU8x8(&u8g2));
|
||||
u8x8_SetPowerSave(u8g2_GetU8x8(&u8g2), 0);
|
||||
|
||||
u8x8_ConnectBitmapToU8x8(u8g2_GetU8x8(&u8g2)); /* connect to bitmap */
|
||||
|
||||
mui_Init(&ui, &u8g2, fds, muif_list, sizeof(muif_list)/sizeof(muif_t));
|
||||
mui_EnterForm(&ui, 1);
|
||||
mui_GotoForm(&ui, 1, 0);
|
||||
|
||||
//puts(fds);
|
||||
|
||||
|
@ -238,6 +258,7 @@ int main(void)
|
|||
{
|
||||
mui_Draw(&ui);
|
||||
} while( u8g2_NextPage(&u8g2) );
|
||||
do_screenshot();
|
||||
|
||||
// printf("mui_GetCurrentCursorFocusPosition=%d\n", mui_GetCurrentCursorFocusPosition(&ui));
|
||||
|
||||
|
@ -260,10 +281,24 @@ int main(void)
|
|||
|
||||
if ( k == 'q' ) break;
|
||||
|
||||
if ( k == 'n' ) mui_NextField(&ui);
|
||||
if ( k == 'p' ) mui_PrevField(&ui);
|
||||
if ( k == 's' ) mui_SendSelect(&ui);
|
||||
if ( k == 'n' )
|
||||
{
|
||||
mui_NextField(&ui);
|
||||
}
|
||||
if ( k == 'p' )
|
||||
{
|
||||
mui_PrevField(&ui);
|
||||
}
|
||||
if ( k == 's' )
|
||||
{
|
||||
mui_SendSelect(&ui);
|
||||
}
|
||||
|
||||
if ( k == 't' )
|
||||
{
|
||||
puts("screenshot");
|
||||
do_screenshot();
|
||||
}
|
||||
|
||||
if ( x < 0 )
|
||||
x = 0;
|
||||
|
|
|
@ -89,7 +89,10 @@ int main(void)
|
|||
if ( k == 'q' ) break;
|
||||
|
||||
if ( k == 't' )
|
||||
{
|
||||
puts("screenshot");
|
||||
u8x8_SaveBitmapTGA(u8g2_GetU8x8(&u8g2), "screenshot.tga");
|
||||
}
|
||||
}
|
||||
|
||||
//u8x8_Set8x8Font(u8g2_GetU8x8(&u8g2), bdf_font);
|
||||
|
|
Loading…
Reference in New Issue