Go Down

Topic: Menu for Display (Read 17 times) previous topic - next topic

gnusso

Hi Oliver :-) ,

smiling serenely because you are a very good teacher ... so I'm starting to entry into the mechanism :-) now it's more clear then before ... now I will try to modify the sketch in order to see if I have understood correctly and then I'll you know :-) ... so with your explanation it's more clear now ... the wiki and tutorial one time that you have take the confidence it's pratical :-) ...
So, like my example ... before i need to understand the logical stand point and then one times that i have understood at least a little bit the logical stand point , i can start to play with a code :-) ... Then you're more able like a teacher ...

So now I try and i'll replay back :-)

regards,
Gnux

gnusso

Good Morning Oliver again,
so I've tried to do my first menu starting from the example. In attachment the screen shot of serial monitor.
Iniside "SetDate 1-1" sub menu into button ok function I've put my function that call the root element if not understood bad and also call my function ... So, I cannot test RTC Function because I didn't install RTC again but seems correct ...What do you think ? here the code:

Code: [Select]

#include <LiquidCrystal.h> // ensure that the include path is set
#include "M2tk.h"
#include <VirtualWire.h>
#include <Wire.h>

// Forward declaration of the toplevel element
M2_EXTERN_HLIST(top_el_expandable_menu);

/* edit date dialog */
uint8_t dt_day = 1;
uint8_t dt_month = 1;
uint8_t dt_year = 12;
void SetDate()
{
  Wire.beginTransmission(0x68); //1°st byte where i set registry write
  Wire.write((byte)0x00);
  //set date 
  byte DayOfMonth = dt_day; //Wire.write((byte)0x01); //4° byte day of month
  Wire.write((byte)(DayOfMonth)); //5° byte GIORNO del mese da 0x00 a 0x31
 
  byte Month = dt_month;
  Wire.write((byte)(Month)); //6° byte month between 0x00 and 0x12
 
  byte Year = dt_year;
  Wire.write((byte)(Year)); //7° byte year between 0x00 a 0x99
  Wire.endTransmission();
}
void dt_ok_date(m2_el_fnarg_p fnarg) 
{
  m2_SetRoot(&top_el_expandable_menu);
  SetDate();
}

M2_U8NUM(el_dt_year, "c2", 0,99,&dt_year);
M2_LABEL(el_dt_sep1, "b1", "-");
M2_U8NUM(el_dt_month, "c2", 1,12,&dt_month);
M2_LABEL(el_dt_sep2, "b1", "-");
M2_U8NUM(el_dt_day, "c2", 1,31,&dt_day);

M2_LIST(list_date) = { &el_dt_year, &el_dt_sep1, &el_dt_month, &el_dt_sep2, &el_dt_day };
M2_HLIST(el_date, NULL, list_date);

M2_ROOT(el_dt_cancel, NULL, "cancel", &top_el_expandable_menu);
M2_BUTTON(el_dt_ok, NULL, "ok", dt_ok_date);
M2_LIST(list_dt_buttons) = {&el_dt_cancel, &el_dt_ok };
M2_HLIST(el_dt_buttons, NULL, list_dt_buttons);

M2_LIST(list_dt) = {&el_date, &el_dt_buttons };
M2_VLIST(el_top_dt, NULL, list_dt);

/* main menu */
m2_menu_entry m2_2lmenu_data[] =
{
  { "Date/Time 1", NULL },
  { ". SetDate 1-1", &el_top_dt },
  { NULL, NULL },
};

uint8_t m2_2lmenu_first;
uint8_t m2_2lmenu_cnt;

M2_2LMENU(el_2lmenu,"l4e1w12",&m2_2lmenu_first,&m2_2lmenu_cnt, m2_2lmenu_data,'+','-','\0');
M2_VSB(el_vsb, "l4w1r1", &m2_2lmenu_first, &m2_2lmenu_cnt);
M2_LIST(list_2lmenu) = { &el_2lmenu, &el_vsb };
M2_HLIST(top_el_expandable_menu, NULL, list_2lmenu);

// m2 object and constructor
M2tk m2(&top_el_expandable_menu, m2_es_arduino_serial, m2_eh_2bs, m2_gh_arduino_serial);

void setup()
{
  Wire.begin();
}

void loop() {
  m2.checkKey();
  m2.checkKey();
  if ( m2.handleKey() )
    m2.draw();
  m2.checkKey();
}


So now the question is, how I can add another sub menu : ". SetTime 1-2 " ?
So I've insight that now I think is necessary to proceed to define ... M2_LIST(list_time) and M2_HLIST(el_time, NULL, list_time); could be  ?

I hope to be a good students ...

regards,
gnux

olikraus

#22
Jan 20, 2013, 11:10 am Last Edit: Jan 20, 2013, 11:15 am by olikraus Reason: 1
Hi

So far your code seems quite ok. The callback procedure will store the date into the RTC once the ok button is pressed.

For the time menu, you probably need to consider which elements are needed on your menu.
If you need only hour and minutes than two U8NUM elements will do the job (similar to the data entry, but different ranges)
Of course you will need again a cancel and an ok button.

You can takeover the date code and transform it like this:
Code: [Select]
M2_U8NUM(el_dt_hour, "c2", 0,23,&dt_hour);
M2_LABEL(el_dt_c, "b1", ":");
M2_U8NUM(el_dt_min, "c2", 0,59,&dt_min);

M2_LIST(list_time) = { &el_dt_hour, &el_dt_c, &el_dt_min};


The rest should be almost identical to the date menu. Of course element and procedure names need to be renamend.

Oliver

Edit: Hour and Minute ranges

gnusso

Hi Oliver,
so now I've tried to add the hours also, but I don't understand why doesn't store the hours ...

should be correct from the code stand - point for you ?

Code: [Select]

#include <LiquidCrystal.h> // ensure that the include path is set
#include "M2tk.h"
#include <VirtualWire.h>
#include <Wire.h>
#include <DS1307.h>
#if defined(ARDUINO) && ARDUINO >= 100
#include "Arduino.h"
#else
#include "WProgram.h"
#endif

// Forward declaration of the toplevel element
M2_EXTERN_HLIST(top_el_expandable_menu);

/* edit date dialog */
uint8_t dt_day = 1;
uint8_t dt_month = 1;
uint8_t dt_year = 12;
uint8_t dt_min = 1;
uint8_t dt_hour = 1;

void dt_current()
{
  Serial.print(RTC.get(DS1307_HR,true)); //read the hour and also update all the values by pushing in true
  Serial.print(":");
  Serial.print(RTC.get(DS1307_MIN,false));//read minutes without update (false)
  Serial.print(":");
  Serial.print(RTC.get(DS1307_SEC,false));//read seconds
  Serial.print("      ");                 // some space for a more happy life
  Serial.print(RTC.get(DS1307_DATE,false));//read date
  Serial.print("/");
  Serial.print(RTC.get(DS1307_MTH,false));//read month
  Serial.print("/");
  Serial.print(RTC.get(DS1307_YR,false)); //read year
  Serial.println();
}


void dt_get_from_RTC(void)
{
  dt_day = RTC.get(DS1307_DATE,false);
  dt_month = RTC.get(DS1307_MTH,false);
  dt_year = (RTC.get(DS1307_YR,false)-2000);
  dt_min = RTC.get(DS1307_MIN,false);
  dt_hour = RTC.get(DS1307_HR,true);
}

void dt_put_to_RTC(void)
{
  RTC.set(DS1307_DATE,dt_day);
  RTC.set(DS1307_MTH,dt_month);
  RTC.set(DS1307_YR,dt_year);
  RTC.start();
}

void time_put_to_RTC(void)
{
 
  RTC.set(DS1307_HR,dt_hour);
  RTC.set(DS1307_MIN,dt_min);
  RTC.start();
}
void dt_ok_date(m2_el_fnarg_p fnarg) 
{
  dt_put_to_RTC();
  m2_SetRoot(&top_el_expandable_menu);
  dt_current();
}

void dt_ok_time(m2_el_fnarg_p fnarg)
{
  time_put_to_RTC();
  m2_SetRoot(&top_el_expandable_menu);
  dt_current();
}

M2_U8NUM(el_dt_year, "c2", 0,99,&dt_year);
M2_LABEL(el_dt_sep1, "b1", "-");
M2_U8NUM(el_dt_month, "c2", 1,12,&dt_month);
M2_LABEL(el_dt_sep2, "b1", "-");
M2_U8NUM(el_dt_day, "c2", 1,31,&dt_day);

M2_LIST(list_date) = { &el_dt_year, &el_dt_sep1, &el_dt_month, &el_dt_sep2, &el_dt_day };
M2_HLIST(el_date, NULL, list_date);

M2_ROOT(el_dt_cancel, NULL, "cancel", &top_el_expandable_menu);
M2_BUTTON(el_dt_ok, NULL, "ok", dt_ok_date);
M2_LIST(list_dt_buttons) = {&el_dt_cancel, &el_dt_ok };
M2_HLIST(el_dt_buttons, NULL, list_dt_buttons);

M2_LIST(list_dt) = {&el_date, &el_dt_buttons };
M2_VLIST(el_top_dt, NULL, list_dt);

/* edit time */

M2_U8NUM(el_dt_hour, "c2", 0,23,&dt_hour);
M2_LABEL(el_dt_c, "b1", ":");
M2_U8NUM(el_dt_min, "c2", 0,59,&dt_min);

M2_LIST(list_time) = { &el_dt_hour, &el_dt_c, &el_dt_min,&el_dt_cancel, &el_dt_ok};
M2_VLIST(el_top_time, NULL, list_time);

M2_BUTTON(el_dt_ok_tim, NULL, "ok", dt_ok_time);


/* main menu */
m2_menu_entry m2_2lmenu_data[] =
{
  { "Date/Time 1", NULL },
  { ". SetDate 1-1", &el_top_dt },
  { ". SetTime 1-2", &el_top_time},
  { NULL, NULL },
};

uint8_t m2_2lmenu_first;
uint8_t m2_2lmenu_cnt;

M2_2LMENU(el_2lmenu,"l4e1w12",&m2_2lmenu_first,&m2_2lmenu_cnt, m2_2lmenu_data,'+','-','\0');
M2_VSB(el_vsb, "l4w1r1", &m2_2lmenu_first, &m2_2lmenu_cnt);
M2_LIST(list_2lmenu) = { &el_2lmenu, &el_vsb };
M2_HLIST(top_el_expandable_menu, NULL, list_2lmenu);

// m2 object and constructor
M2tk m2(&top_el_expandable_menu, m2_es_arduino_serial, m2_eh_2bs, m2_gh_arduino_serial);

void setup()
{
  Wire.begin();
}

void loop() {
  m2.checkKey();
  m2.checkKey();
  if ( m2.handleKey() )
    m2.draw();
  m2.checkKey();
}


thx gnux

gnusso

Hi Oliver,
so i was found a little issues inside a code ... now should be better but i still to have a issues ... i don't know why i cannot store the h: and minutes... and also on the menu appears only one element ... could you help kindly me ?

Code: [Select]
#include <LiquidCrystal.h> // ensure that the include path is set
#include "M2tk.h"
#include <VirtualWire.h>
#include <Wire.h>
#include <DS1307.h>
#if defined(ARDUINO) && ARDUINO >= 100
#include "Arduino.h"
#else
#include "WProgram.h"
#endif

// Forward declaration of the toplevel element
M2_EXTERN_HLIST(top_el_expandable_menu);

/* edit date dialog */
uint8_t dt_day = 1;
uint8_t dt_month = 1;
uint8_t dt_year = 12;
uint8_t dt_min = 1;
uint8_t dt_hour = 1;

void dt_current()
{
  Serial.print(RTC.get(DS1307_HR,true)); //read the hour and also update all the values by pushing in true
  Serial.print(":");
  Serial.print(RTC.get(DS1307_MIN,false));//read minutes without update (false)
  Serial.print(":");
  Serial.print(RTC.get(DS1307_SEC,false));//read seconds
  Serial.print("      ");                 // some space for a more happy life
  Serial.print(RTC.get(DS1307_DATE,false));//read date
  Serial.print("/");
  Serial.print(RTC.get(DS1307_MTH,false));//read month
  Serial.print("/");
  Serial.print(RTC.get(DS1307_YR,false)); //read year
  Serial.println();
}


void dt_get_from_RTC(void)
{
  dt_day = RTC.get(DS1307_DATE,false);
  dt_month = RTC.get(DS1307_MTH,false);
  dt_year = (RTC.get(DS1307_YR,false)-2000);
  dt_min = RTC.get(DS1307_MIN,false);
  dt_hour = RTC.get(DS1307_HR,true);
}

void dt_put_to_RTC(void)
{
  RTC.set(DS1307_DATE,dt_day);
  RTC.set(DS1307_MTH,dt_month);
  RTC.set(DS1307_YR,dt_year);
  RTC.start();
}

void time_put_to_RTC(void)
{
 
  RTC.set(DS1307_HR,dt_hour);
  RTC.set(DS1307_MIN,dt_min);
  RTC.start();
}
void dt_ok_date(m2_el_fnarg_p fnarg) 
{
  dt_put_to_RTC();
  m2_SetRoot(&top_el_expandable_menu);
  dt_current();
}

void dt_ok_time(m2_el_fnarg_p fnarg)
{
  time_put_to_RTC();
  m2_SetRoot(&top_el_expandable_menu);
  dt_current();
}

M2_U8NUM(el_dt_year, "c2", 0,99,&dt_year);
M2_LABEL(el_dt_sep1, "b1", "-");
M2_U8NUM(el_dt_month, "c2", 1,12,&dt_month);
M2_LABEL(el_dt_sep2, "b1", "-");
M2_U8NUM(el_dt_day, "c2", 1,31,&dt_day);

M2_LIST(list_date) = { &el_dt_year, &el_dt_sep1, &el_dt_month, &el_dt_sep2, &el_dt_day };
M2_HLIST(el_date, NULL, list_date);

M2_ROOT(el_dt_cancel, NULL, "cancel", &top_el_expandable_menu);
M2_BUTTON(el_dt_ok, NULL, "ok", dt_ok_date);
M2_LIST(list_dt_buttons) = {&el_dt_cancel, &el_dt_ok };
M2_HLIST(el_dt_buttons, NULL, list_dt_buttons);

M2_LIST(list_dt) = {&el_date, &el_dt_buttons };
M2_VLIST(el_top_dt, NULL, list_dt);

/* edit time */

M2_U8NUM(el_dt_hour, "c2", 0,23,&dt_hour);
M2_LABEL(el_dt_c, "b1", ":");
M2_U8NUM(el_dt_min, "c2", 0,59,&dt_min);

M2_BUTTON(el_dt_ok_time, NULL, "ok", dt_ok_time);

M2_LIST(list_time) = { &el_dt_hour, &el_dt_c, &el_dt_min,&el_dt_cancel, &el_dt_ok_time};
M2_VLIST(el_top_time, NULL, list_time);




/* main menu */
m2_menu_entry m2_2lmenu_data[] =
{
  { "Date/Time 1", NULL },
  { ". SetDate 1-1", &el_top_dt },
  { ". SetTime 1-2", &el_top_time},
  { NULL, NULL },
};

uint8_t m2_2lmenu_first;
uint8_t m2_2lmenu_cnt;

M2_2LMENU(el_2lmenu,"l4e1w12",&m2_2lmenu_first,&m2_2lmenu_cnt, m2_2lmenu_data,'+','-','\0');
M2_VSB(el_vsb, "l4w1r1", &m2_2lmenu_first, &m2_2lmenu_cnt);
M2_LIST(list_2lmenu) = { &el_2lmenu, &el_vsb };
M2_HLIST(top_el_expandable_menu, NULL, list_2lmenu);

// m2 object and constructor
M2tk m2(&top_el_expandable_menu, m2_es_arduino_serial, m2_eh_2bs, m2_gh_arduino_serial);

void setup()
{
  Wire.begin();
}

void loop() {
  m2.checkKey();
  m2.checkKey();
  if ( m2.handleKey() )
    m2.draw();
  m2.checkKey();
}


So now i go for a launch because i pass 5 hours in front off the pc ... So I've forget you to tell that i've connect RTC clock in the meantime :-)

regards,
Andrea

Go Up