Pages: 1 ... 10 11 [12] 13 14 15   Go Down
Author Topic: Menu for Display  (Read 16354 times)
0 Members and 1 Guest are viewing this topic.
Germany
Offline Offline
Edison Member
*
Karma: 137
Posts: 1552
If you believe something is right, you won't see what's wrong (David Straker).
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Well, i have no idea about that virtual wire library.
I was thinking that something like
Code:
  m2.checkKey();
  // read and process all messages...
  while( vw_have_message() )
  {
     if (vw_get_message(buf, &buflen)) // Non-blocking
     {
        ... // handle message
     }   
  }
  // ... before any redraw

  if ( m2.handleKey() ) {
    m2.draw();
  }

might solve the problem.
But this is just an idea.

Oliver
Logged

Offline Offline
Sr. Member
****
Karma: 2
Posts: 433
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi Oliver,
Ok :-) I've understand what you mean :-) ... but I was thinking ...

the fact the transmission part is inside the menu ... than should be already draw the menu or the menu is re-draw each time ? so for example when I press the ok button after I go to the previuos level and in this way after I can see the label changing based on the devices state ... in this time the menu is re-draw or is draw only one time ?

Thanks
Gnux
Logged

Germany
Offline Offline
Edison Member
*
Karma: 137
Posts: 1552
If you believe something is right, you won't see what's wrong (David Straker).
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

You are in the Arduino loop(). Inside this loop you see this code:
Code:
  if ( m2.handleKey() ) {
    m2.draw();
  }

This means: Whenever you pressed a button, the menu will be redrawn.
You might have additional sources, which might require redraw. For example if you receive a message with an information which should be displayed, then this might also require a redraw:
Code:
  if ( m2.handleKey() || display_update_required ) {
    m2.draw();
    display_update_required = 0;
  }
With this expanded code, whenever you set display_update_required to 1, it will refresh the screen once.
Not sure if i really answered your question. All in all, m2.draw() just draws the screen and then returns back to your program.

Oliver


Logged

Offline Offline
Sr. Member
****
Karma: 2
Posts: 433
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks for the explanation ...

so I post to you what I do when I press the button and then I give a question for you :-).

Code:
/* --------------------------------- MENU DEVICES:1 ------------------------ */
void back_button(m2_el_fnarg_p fnarg) {
  LeggiEeprom();
  m2_SetRoot(&top_el_expandable_menu);
}
void fn_clean_dev(m2_el_fnarg_p fnarg) {
  u8dev = 0;
}

void dev_ok_button(m2_el_fnarg_p fnarg)
{
  int offset1;
  offset1 = u8dev * rlen;
  if (u8stato == 0) // if state is 0 then I send out 0 this means shutdown devices
  { 
    array[u8dev][1] = 1;
    array[u8dev][14] = 1;
    array[u8dev][19] = 1;
    array[u8dev][32] = 1;
    array[u8dev][12] = 0;
    array[u8dev][0] = u8dev;       
    TxMsg(array[u8dev][0]);
    ProcessaMessaggio(u8dev); 
    delay(450);
   
    if (array[u8dev][6] == 2)
     {
         delay(2000);
        TxMsg(array[u8dev][0]);
        ProcessaMessaggio(u8dev); 
      }
     
    if (array[u8dev][6] == 2)
     {
         delay(2000);
        TxMsg(array[u8dev][0]);
        ProcessaMessaggio(u8dev); 
      }

    if (array[u8dev][6] == 2)
      {
       array[u8dev][12] = 2;   
      } 

    m2_SetRoot(&top_el_expandable_menu);
    // m2_SetRoot(&m2_null_element);
  }
  else
   if (u8stato == 1) // if state is 1 then i send out 32 that means turn on devices
     {   
      array[u8dev][1] = 1;
      array[u8dev][14] = 1;
      array[u8dev][19] = 1;
      array[u8dev][32] = 1;
      array[u8dev][12] = 32;
      array[u8dev][0] = u8dev; 
      TxMsg((array[u8dev][0] + 32));
      ProcessaMessaggio(u8dev);       
      // m2_SetRoot(&m2_null_element);
      delay(450);
     
     if (array[u8dev][6] == 2)
          {
            delay(2000);
            TxMsg((array[u8dev][0] + 32));
            ProcessaMessaggio(u8dev);
          }     
         
     if (array[u8dev][6] == 2)
          {
            delay(2000);
            TxMsg((array[u8dev][0] + 32));
            ProcessaMessaggio(u8dev);
          }               
         
    if (array[u8dev][6] == 2)  // bad state finale
          {
            array[u8dev][12] = 2;
   
          }     
      m2_SetRoot(&top_el_expandable_menu);
  }

}

const char *fn_idx_to_state(uint8_t idx)
{
  switch(array[u8dev][12])
  {
  case 0:
    u8stato = 1;
    return "On";
  case 2:
    u8stato = 1;
    return "On"; 
  case 32:
    u8stato = 0;
    return "Off";
  }
  return "";
}
const char *label_cb(m2_rom_void_p element)

  switch (array[u8dev][12]) {
  case 0:
    return "Off";
  case 2:
    return "BadState";
  case 32:
    return "On";
  }   
  return "";
}
const char *label_what(m2_rom_void_p element)

  switch (array[u8dev][13]) {
  case 0:
    return "Bathro";
  case 1:
    return "Kitche";
  case 2:
    return "Garage";
  case 3:
    return "LivRoo"; 
  case 4:
    return "BedRoo";
  case 5:
    return "BedChi";
  case 6:
    return "WarmSl"; 
  case 7:
    return "WarmS1";
  case 8:
    return "Tv";
  case 9:
    return "Hi-Fi";
  case 10:
    return "OLigh1";

  }   
  return  "";
}

M2_LABELFN(el_v_state_apply, "x4y1", label_cb);
M2_COMBO(el_v_state, fmt_x3y0r1, &select_priority, 20, fn_idx_to_state);
M2_BUTTON(el_dev_ok, fmt_x7y0, "Ok", dev_ok_button);

M2_LIST(num_list) = {
  &el_G_Timer, &el_G_Timer_dev,
  &el_G_What,
  &el_G_Timer_State, &el_v_state,
  &el_G_Timer_Ac,&el_v_state_apply,&el_dev_ok, &el_G_back, 
};
M2_XYLIST(el_num_menu, NULL, num_list);

Ok the menu part i think that is not necessary to explain ;-) because you are the teacher :-)

into the ok button I call this 2 procedure passing different value based on the device state ...

    TxMsg(array[u8dev][0]);
    ProcessaMessaggio(u8dev); 

where TxMsg --> transmit message and wait until the message is gone
immediately after that is call

ProcessaMessaggio(u8dev);

this procedure wait the reply from the slave devices ...

well if i not understood bad both of this procedure should be execute one of the other ... then theoretically there isn't delay from display side because are all included in the same function named " dev_ok_button " .

but here I have the issues, sometimes is working and sometimes no ...

from the transmission side as was explaining I have try to stress the modem without display and after the transmission tuning no issues appear,
then I've though to insert the display ... but I've noted the issues ... this is the reason of my questions :-)

however thanks for your great patient and your professionalism :-)

I hope that it's more clear for you :-)

regards,
Gnux
Logged

Germany
Offline Offline
Edison Member
*
Karma: 137
Posts: 1552
If you believe something is right, you won't see what's wrong (David Straker).
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Well, having the code inside the button callback will for sure freeze the menu, but it should work. I do not see a reason why it should not work. :-(

Oliver
Logged

Offline Offline
Sr. Member
****
Karma: 2
Posts: 433
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi Oliver,
due the fact of course I'm try to stress the system for discovered the bugs.

and I'm try a lot of pushing quickly ...

It's working at 97 % ... :-( ... i was trying to outgoing 100 % ...

Anyway I will put a backup procedure ...

Thanks for the moment,
Gnux
Logged

Offline Offline
Sr. Member
****
Karma: 2
Posts: 433
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Ciao Oliver,
my friend has bought for me this :

http://www.ebay.it/itm/111005370687?ssPageName=STRK:MEWNX:IT&_trksid=p3984.m1497.l2649

do you think that is compatible with your library ?

Thanks
Gnux
Logged

Germany
Offline Offline
Edison Member
*
Karma: 137
Posts: 1552
If you believe something is right, you won't see what's wrong (David Straker).
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi

Unfortunately this not supported by u8glib. I think you can use UTFT with it (however, UTFT is not supported by m2tklib).

Oliver
Logged

Offline Offline
Sr. Member
****
Karma: 2
Posts: 433
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Good Afternoon Olivier :-) How are you ? so, I've started again to use your library :-)
so right now during no key pressed I print lcd date and time and etc etc ... when i press button the menu is appearing ...

so now I would like introduce also this ... when i didn't use the menu and no button pressed I would like to use Keypad for do something ...

is possible for your stand point ?

Thanks and have a nice day
Andrea
Logged

Germany
Offline Offline
Edison Member
*
Karma: 137
Posts: 1552
If you believe something is right, you won't see what's wrong (David Straker).
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi

Nice, a one year old thread gets reactivated. And yes, i am fine, still working and graphics displays and menues...   smiley-lol
To answer your question: Yes, shure this should be possible. I see two options:
1. Fully stop calling any M2tklib procedures (especially do not call M2tk::checkKey())
2. Still call M2tk::checkKey(void) and manually examine results from m2::getKey() (http://code.google.com/p/m2tklib/wiki/fnref#getKey)

Oliver
Logged

Offline Offline
Sr. Member
****
Karma: 2
Posts: 433
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Ciao Oliver, firstable really thanks for your help :-) because otherwise will be no possibility to use the library without your help :-)
so right now I'm in this situation I post only "loop" in order that you can have more clear it.

Code:
void loop() {       
  Alarm.delay(0);
 if ( m2.getRoot() == &m2_null_element )
  {
    digitalWrite(13, HIGH);
    // yes, it is our manual written screen
    // place your manual commands here
    lcd.setCursor(1, 2);
    lcd.print("*Home Sweet Home*");
    digitalClockDisplay();
    // check if the user has pressed a key while manual screen is active
   uint8_t key = m2.getKey();

   if ( key != M2_KEY_NONE )
    {
      if (key == M2_KEY_HOME2)
     {
          digitalWrite(13, LOW);
          m2.setRoot(&el_num_menu);   // refer to a suitable menu
     }
     else
      {
          digitalWrite(13, LOW);
          m2.setRoot(&top_el_expandable_menu);   // refer to a suitable menu
      } 
   }
   
  }
  // do normal menu display 
  m2.checkKey();
  if ( m2.handleKey() ) {
    m2.draw();
  }
}

in this code I would like that "Welcome Menu" still to be display on the LCD and If didn't use button that has been configured, I can run other command via keypad for example this:
Code:
char customKey = customKeypad.getKey();
  if (customKey){
    Serial.println(customKey);
  }

Could you give an example code in order to understand better ? from teorically  stand point I've understood ;-)

Thanks
Gnux
Logged

Germany
Offline Offline
Edison Member
*
Karma: 137
Posts: 1552
If you believe something is right, you won't see what's wrong (David Straker).
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi

The first part looks correct. It should work as intended.
Your second code is more difficult. First my question  is: What is "customKeypad.getKey();" ? I do not know/see what customKeypad is. Do you mean m2.getKey() instead? If you mean m2.getKey(), then  printing this with serial.print does not make sense, as the return values from m2.getKey() are not printable.
Basically you can only use constants to check for the return values. A list of constants is defined here:
http://code.google.com/p/m2tklib/wiki/t11#Return_Values_of_the_Event_Source_Procedure

Oliver

Logged

Offline Offline
Sr. Member
****
Karma: 2
Posts: 433
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Ciao Oliver the second Part code is just an example how to use get key from a keypad ... :-) I would like use keypad when no pressed button related to display menu are pressed :-)  please let me know if you need other information ;-)

thanks
gnux
Logged

Germany
Offline Offline
Edison Member
*
Karma: 137
Posts: 1552
If you believe something is right, you won't see what's wrong (David Straker).
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi

Well, then the simple answer is: Yes you can use your keypad in parallel with m2tklib.

Oliver
Logged

Offline Offline
Sr. Member
****
Karma: 2
Posts: 433
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Perfect and which inside the loop the correct point where I've to put  a code related to keypad in parallel ?

After I would like to know if you have news about display :-) if have you tried something that I can try to use ;-)

thanks
Gnux
Logged

Pages: 1 ... 10 11 [12] 13 14 15   Go Up
Jump to: