Hi Oliver,
I'm trying to do a couple of things that don't seem to be working:
-
Im trying to setup an intro screen. I found two examples that are supposed to work - but they didnt make sense and didnt work in my case.
-
is there an easy way to find which menu (root) is being used. Reason is that i want update_required = 0 when some menus are being used such as menus used to get an input. For example, an input variable might be constantly updated (such as a clock reading) but shouldn't get updated when the user is entering new values in the 'change time' menu.
The test code i'm using is attached:
#include "U8glib.h"
#include "M2tk.h"
#include "utility/m2ghu8g.h"
#include "myimages.h"
//U8GLIB(Â Â Â Â Â Â d0, d1, d2, d3, d4, d5, d6, d7, en, cs1, cs2, di, rw, reset)
U8GLIB_KS0108_128 u8g(22, 23, 24, 25, 26, 27, 28, 29, 37, 33, 34, 36, 35, 30);
uint32_t global_value_1 = 0;
uint32_t global_value_2 = 0;
uint32_t global_value_3 = 0;
uint8_t update_required = 0;
uint8_t timeout = 50;   // 60 seconds (approx)Â
#define INTRO 0
#define MAIN_MENU 1
uint8_t state;
M2_EXTERN_ALIGN(el_m01);
M2_EXTERN_ALIGN(el_m02);
M2_EXTERN_ALIGN(el_m03);
uint32_t u32_cb_1(m2_rom_void_p el_u32_cb, uint8_t msg, uint32_t val)
{
//Â if ( msg == M2_U32_MSG_GET_VALUE ){
  // wrong place to increment, do this in loop()
  // global_value ++;
  // Serial.println(global_value);
//Â }
 return global_value_1;
}
uint32_t u32_cb_2(m2_rom_void_p el_u32_cb, uint8_t msg, uint32_t val)
{
//Â if ( msg == M2_U32_MSG_GET_VALUE ){
//Â }
 return global_value_2;
}
M2_LABEL(el_m00_label, "b0", "-=  Main Menu  =-" );
M2_LABEL(el_underline, "b0", "---------------------" );
M2_ROOT(el_m00_submenu1, "f0", "Menu 1", &el_m01 );
M2_ROOT(el_m00_submenu2, "f0", "Menu 2", &el_m02 );
M2_ROOT(el_m00_submenu3, "f0", "Menu 3", &el_m03 );
M2_LIST(el_m00_l1) = { &el_m00_label, &el_underline, &el_m00_submenu1, &el_m00_submenu2, &el_m00_submenu3 };
M2_VLIST(el_m00_vl, NULL, el_m00_l1);Â
M2_ALIGN(el_m00, "-0|2W128H64", &el_m00_vl);
M2_U32NUMFN(el_u32_cb_1, "r1c4", u32_cb_1);
M2_LABEL(el_space1, "b1", " ");
M2_BUTTON(el_m01_ok, NULL, " ok ", fn_ok1);
M2_LIST(el_l1) = { &el_u32_cb_1, &el_space1, &el_space1, &el_m01_ok };
M2_VLIST( el_v1, NULL, el_l1);
M2_ALIGN(el_m01, "-0|2W128H64", &el_v1);
M2_U32NUMFN(el_u32_cb_2, "r1c4", u32_cb_2);
//M2_LABEL(el_space1, "b1", " ");
M2_BUTTON(el_m02_ok, NULL, " ok ", fn_ok2);
M2_LIST(el_l2) = { &el_u32_cb_2, &el_space1, &el_space1, &el_m02_ok };
M2_VLIST( el_v2, NULL, el_l2);
M2_ALIGN(el_m02, "-0|2W128H64", &el_v2);
M2_U32NUM(el_u32_cb_3, "r1c4", &global_value_3);
//M2_LABEL(el_space1, "b1", " ");
M2_BUTTON(el_m03_ok, NULL, " ok ", fn_ok3);
M2_LIST(el_l3) = { &el_u32_cb_3, &el_space1, &el_space1, &el_m03_ok };
M2_VLIST( el_v3, NULL, el_l3);
M2_ALIGN(el_m03, "-0|2W128H64", &el_v3);
// m2 object and constructor
M2tk m2(&el_m00, m2_es_arduino_serial, m2_eh_4bs, m2_gh_u8g_bf);
void fn_ok1(m2_el_fnarg_p fnarg) {
 m2.setRoot(&el_m00, 0);
}
void fn_ok2(m2_el_fnarg_p fnarg) {
 m2.setRoot(&el_m00, 1);
}
void fn_ok3(m2_el_fnarg_p fnarg) {
 m2.setRoot(&el_m00, 2);
}
void draw(void) {
  m2.draw();
}
void setup() {
 state = INTRO;
//Â IntroScreen();
 // Connect u8glib with m2tklib
 m2_SetU8g(u8g.getU8g(), m2_u8g_box_icon);
 m2.setFont(0, u8g_font_6x10 );
}
void loop() {
 m2.checkKey();
Â
 if ( m2.handleKey() != 0 ) {
  // key pressed
  timeout = 50;
 }
Â
 // introduce a new variable "update_required"
 if ( m2.handleKey() != 0 || update_required != 0 ) {
  update_required = 0;
  u8g.firstPage();
  do {
   m2.checkKey();
   draw();
  } while( u8g.nextPage() );
 }
 // calling draw() is useless here, picture loop is missing
 // draw();
 delay(100);
 timeout--;
 if ( timeout == 0 ) {
  // change to home menu...
  m2.setRoot(&el_m00);
 }
 global_value_1 ++;
 global_value_2 += 2;
 global_value_3 = global_value_1;
 // force redraw by setting this variable to 1
 update_required = 1;
 // Serial.println(global_value);
Â
 //SetNextState();
}
void SetNextState(void) {
 switch (state) {
  case INTRO:
   break;
  case MAIN_MENU:
   break;
 }
}
//Intro screen
void IntroScreen() {Â
  u8g.firstPage();Â
  do {
   u8g.drawXBM( 0, 0, 128, 64, image);
   draw();
  } while( u8g.nextPage() );
 delay(1000);
//Â state = MAIN_MENU;
Â
}
Any help is appreciated...
Michael