Skip to content

OpenMoCo Menu Manager - 2 Questions #15

@stuartmp

Description

@stuartmp

Hi Drone,

As a new user to OMMenuMgr I must say its a great piece of code.

It took me a while to work out what was going on and how to customize it for my own needs.

But finally I have it working and I am very happy.

I have two small question that would help me improve my code.

I was wondering if you could help me.

Q1. Relates to this quoted text from the 'OMMenuMgr.h' file.

@code
byte foo = 0;

                        //       Data Type        Max    Min    Target

MENU_VALUE value_foo = { TYPE_BYTE, 100, 0, MENU_TARGET(&foo) };

            //        LABEL           TYPE        LENGTH    TARGET

MENU_ITEM item_foo = { {"Foo Edit"}, ITEM_VALUE, 0, MENU_TARGET(&value_foo) };
@Endcode

Here, we see that we can specify the type of data the item points to, a maximum value, a minimum
value, and the target variable (by address) to be edited. Minimum and Maximum values are limited
to the range of a signed long, no matter the data type, and are not used for select lists.

Now specifically the Max and Min value and data type for 'MENU_VALUE value_foo'
I am trying to replace '100' and '0' with a variable.

The help file says
Minimum and Maximum values are limited to the range of a signed long, no matter the data type

But I have tried a rang of data types with no luck.

Could you please get back to me with you to solve this.

Below is a sample of what I have tried

int z_max = 100;
int z_min = 100;
MENU_VALUE lst_ang_z_s_value = { TYPE_UINT,z_max, z_min,MENU_TARGET(&lst_ang_z_s), Adr_zs_lstread };
MENU_ITEM item_zoom = { {"Zoom"},ITEM_VALUE,0,MENU_TARGET(&lst_ang_z_s_value)};

End Q1.

Q2. When you are exiting the value of a 'ITEM_VALUE' using the LCD and you are increasing or decreasing the values.

Is it possible for it to run some method to do something with the value on the screen.
Currently it appears to me that is only saves the variable once you press the 'BUTTON_SELECT'

The reason I ask is I am trying to set the position of a servo and if I use a 'ITEM_VALUE' menu item I can not get the servo to update as the value changes.

It only updates one I press the 'BUTTON_SELECT' which I assume is as designed.

So at this stage I have written a method that is called by the 'ITEM_ACTION' menu item.
this works but I don't think its the best solution.

Below is a sample of the code I wrote for my method.

void setHeightServo() {
servo_adjustment_State = true;

lcd.clear();
Menu.enable(false);

String Mnu_lbl = menuLabel();

lcd.print("<- Adj " + Mnu_lbl + " ->");

lcd.setCursor(0, 1);

String str_new_lst_ang_ls_s = String(lst_ang_ls_s);
lcd.print(str_new_lst_ang_ls_s);

int org_lst_ang_ls_s = lst_ang_ls_s;
unsigned int old_lst_ang_ls_s = lst_ang_ls_s;

while( Menu.checkInput() != BUTTON_SELECT ) {
//; // wait!
uint8_t btnPressed =Menu.checkInput();

currentTime = millis();

if (currentTime - previousScreenOnTime > screenTimeUntilSleep ){
if (servo_OnOff_ControlState == 1)sleepServos();
if (LCD_OnOff_ControlState == 1)sleepDisplay();
}

if(btnPressed != BUTTON_NONE){

setPreviouseTime();

if (btnPressed == BUTTON_INCREASE)lst_ang_ls_s = lst_ang_ls_s--;
if (btnPressed == BUTTON_DECREASE)lst_ang_ls_s = lst_ang_ls_s++;

if (lst_ang_ls_s != old_lst_ang_ls_s){
if (servo_OnOff_ControlState == 0)wakeServos();
if (LCD_OnOff_ControlState == 0)wakeDisplay();

old_lst_ang_ls_s = lst_ang_ls_s;
lense_shift_Servo.write(lst_ang_ls_s);

lcd.setCursor(0, 1);
lcd.print(String(lst_ang_ls_s));
}

if (btnPressed == BUTTON_BACK){
lst_ang_ls_s = org_lst_ang_ls_s;
lense_shift_Servo.write(org_lst_ang_ls_s);

if (servo_OnOff_ControlState == 1)sleepServos();

Menu.enable(true);
lcd.clear();
servo_adjustment_State = false;
return;
}

}

}

I also changed on of your variables from private to public so I could
get the current menu item.

below is the code I used to get the menu item on the LCD.
String menuLabel()
{

//Serial.println("getMenuLabel");

int i;    // counter variable
char myChar;
String menuLabel = "";

// read back a char
  int len = strlen_P(Menu.m_curSel->label);

  for (i = 0; i < len; i++)
  {
    myChar =  pgm_read_byte_near(Menu.m_curSel->label + i);
    //Serial.print(myChar);
    menuLabel = menuLabel + myChar;
  }

  //Serial.print(menuLabel);
  return menuLabel;

}

End Q2.

Thanks again for providing such a awesome library for us to use.

Cheers.

Stuart

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions