{"action":"closed","issue":{"url":"https://api.github.com/repos/jonblack/arduino-menusystem/issues/48","repository_url":"https://api.github.com/repos/jonblack/arduino-menusystem","labels_url":"https://api.github.com/repos/jonblack/arduino-menusystem/issues/48/labels{/name}","comments_url":"https://api.github.com/repos/jonblack/arduino-menusystem/issues/48/comments","events_url":"https://api.github.com/repos/jonblack/arduino-menusystem/issues/48/events","html_url":"https://github.com/jonblack/arduino-menusystem/issues/48","id":207058262,"number":48,"title":"Using data from NumericMenuItem","user":{"login":"GotoNext","id":25724115,"avatar_url":"https://avatars1.githubusercontent.com/u/25724115?v=4","gravatar_id":"","url":"https://api.github.com/users/GotoNext","html_url":"https://github.com/GotoNext","followers_url":"https://api.github.com/users/GotoNext/followers","following_url":"https://api.github.com/users/GotoNext/following{/other_user}","gists_url":"https://api.github.com/users/GotoNext/gists{/gist_id}","starred_url":"https://api.github.com/users/GotoNext/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/GotoNext/subscriptions","organizations_url":"https://api.github.com/users/GotoNext/orgs","repos_url":"https://api.github.com/users/GotoNext/repos","events_url":"https://api.github.com/users/GotoNext/events{/privacy}","received_events_url":"https://api.github.com/users/GotoNext/received_events","type":"User","site_admin":false},"labels":[{"id":662603175,"url":"https://api.github.com/repos/jonblack/arduino-menusystem/labels/difficulty:easy","name":"difficulty:easy","color":"c2e0c6","default":false},{"id":662610573,"url":"https://api.github.com/repos/jonblack/arduino-menusystem/labels/type:question","name":"type:question","color":"c5def5","default":false}],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":6,"created_at":"2017-02-12T15:47:21Z","updated_at":"2017-08-05T19:21:43Z","closed_at":"2017-08-05T19:21:43Z","body":"Hello, newbie question.\r\n\r\nI am using your menu system with great success. \r\nNow I am trying to to use te value in the `NumericMenuItem` in my own program, but because I am a newbie I would request some help.\r\nI have managed to get the value of\r\n `CustomNumericMenuItem mu1_mi3(12, \"Level 2 - Cust Item 3 (Item)\", 80, 65, 121, 3, format_int);` \r\nbut 1. not sure this is the right way \r\n2. how to handle the other menu items that use the 'format_int'\r\nI hope my questions makes sense? if not please let me know and I will try to re-phrase it.\r\n'\r\nThere my code :\r\n```\r\n`\r\n#include <MenuSystem.h>\r\n#include \"CustomNumericMenuItem.h\"\r\n#include \"MyRenderer.h\"\r\n\r\nint ledState = LOW;\r\nString temp[10];\r\n// forward declarations\r\nconst String format_float(const float value);\r\nconst String format_int(const float value);\r\nconst String format_color(const float value);   //color options !!!\r\nconst String stoomaan(const float value);  //to switch on and off the steamgenerator should be true or false  !!!\r\n\r\nvoid on_item1_selected(MenuItem* p_menu_item);\r\nvoid on_item2_selected(MenuItem* p_menu_item);\r\nvoid on_item3_selected(MenuItem* p_menu_item);\r\nvoid on_back_item_selected(MenuItem* p_menu_item);\r\n\r\n// Menu variables\r\n\r\nMyRenderer my_renderer;\r\nMenuSystem ms(my_renderer);\r\n\r\nMenu mm(\"Main Menu\"); // this is possibly not needed ???\r\n \r\n      NumericMenuItem mm_mi1(\"1. Stoomgenerator \", nullptr, 2, 0, 1, 1, stoomaan);// startwaarde,minimaal,maximaal,increment\r\n      NumericMenuItem mm_mi2(\"2. Lamp aan/uit   \", nullptr, 2, 0, 1, 1, stoomaan);// startwaarde,minimaal,maximaal,increment\r\n\r\n      Menu mu1(\"3. Settings> \");  // menu 2 menu item\r\n      BackMenuItem mu1_mi1(\"Level 1 - Back (Item)\", &on_back_item_selected, &ms); //menu 2 item 1\r\n\r\n      MenuItem mu1_mi2(\"3.Settings in sub >\", &on_item1_selected); //menu 2 item 2\r\n      NumericMenuItem mu1_mi3(\"   3.1. tijds instelling\", nullptr, 45, 0, 120, 1, format_int);  //startwaarde,minimaal,maximaal,increment \r\n      CustomNumericMenuItem mu1_mi4(12, \"   3.2 temperatuurs instelling\", 43, 20, 70, 1, format_int); // startwaarde,minimaal,maximaal,increment\r\n      NumericMenuItem mm_mi4(\"5. - Float Item 4 (Item)\", nullptr, 0.5, 0.0, 1.0, 0.1, format_float);\r\n      NumericMenuItem mm_mi5(\"6. - Int Item 5 (Item)\", nullptr, 50, -100, 100, 1, format_int);\r\n    Menu mu2(\"4. level menu 2 ??\");\r\n  BackMenuItem mu2_mi1(\"Level 2 - Back (Item)\", &on_back_item_selected, &ms);\r\n\r\nMenuItem mu2_mi2(\"Level 2 - Item 1 (Item)\", &on_item3_selected);\r\nNumericMenuItem mu2_mi3(\"Level 2 - Txt Item 2 (Item)\", nullptr, 0, 0, 3, 1, format_color);  // \"??\",\"??\",aantal opties,\"??\"\r\n\r\n// Menu callback function\r\n\r\n// writes the (int) value of a float into a char buffer.\r\nconst String format_int(const float value)\r\n{\r\n   Serial.println (\"hier wordt de format_int aangepast ?:\");\r\n   Serial.println (value );\r\n   temp[1]=( String((int) value));                         //////////  ECL copy menu value in my own integer    Serial.println (temp[1]);\r\n   Serial.println(ms.get_current_menu()->get_name());      //////////  how to get value of other format_int ?\r\n   return String((int) value);\r\n   }\r\n\r\n// writes the value of a float into a char buffer.\r\nconst String format_float(const float value)\r\n{\r\n  return String(value);\r\n}\r\n\r\n// writes the value of a float into a char buffer as settings.     ECL stoomaan toegevoegd\r\nconst String stoomaan(const float value)\r\n{\r\n  String buffer;\r\n\r\n  switch ((int) value)\r\n  {\r\n    case 0:\r\n      buffer += \"uit\";\r\n      break;\r\n    case 1:\r\n      buffer += \"aan\";\r\n      break;\r\n\r\n    default:\r\n      buffer += \"uit\";\r\n  }\r\n\r\n  return buffer;\r\n}\r\n\r\n\r\n// writes the value of a float into a char buffer as predefined colors.\r\nconst String format_color(const float value)\r\n{\r\n  String buffer;\r\n\r\n  switch ((int) value)\r\n  {\r\n    case 0:\r\n      buffer += \"Red\";\r\n      break;\r\n    case 1:\r\n      buffer += \"Green\";\r\n      break;\r\n    case 2:\r\n      buffer += \"Blue\";\r\n      break;\r\n    case 3:\r\n      buffer += \"Emiel\";\r\n      break;\r\n    default:\r\n      buffer += \"undef\";\r\n  }\r\n\r\n  return buffer;\r\n}\r\n\r\n// In this example all menu items use the same callback. //ECL shows only menu with subs in it???\r\n\r\nvoid on_item1_selected(MenuItem* p_menu_item)\r\n{\r\n  Serial.println(\"Item1 Selected\");\r\n\r\nledState = !ledState;\r\n  //igitalWrite(led,ledState);\r\n  //lcd.setCursor(0,1);\r\n  Serial.print(\"Led state: \");\r\n  if(ledState)\r\n    Serial.print(\"ON\");\r\n  else\r\n    Serial.print(\"OFF\");\r\n  //delay(SELECTED_DISPLAY_DELAY);\r\n}\r\n  \r\n \r\nvoid on_item2_selected(MenuItem* p_menu_item)\r\n{\r\n  Serial.println(\"Item2 Selected\");\r\n}\r\n\r\nvoid on_item3_selected(MenuItem* p_menu_item)\r\n{\r\n  Serial.println(\"Item3 Selected\");\r\n}\r\n\r\nvoid on_back_item_selected(MenuItem* p_menu_item)\r\n{\r\n  Serial.println(\"Back item Selected\");\r\n}\r\n\r\nvoid display_help() {\r\n  Serial.println(\"***************\");\r\n  Serial.println(\"w: go to previus item (up)\");\r\n  Serial.println(\"s: go to next item (down)\");\r\n  Serial.println(\"a: go back (right)\");\r\n  Serial.println(\"d: select \\\"selected\\\" item\");\r\n  Serial.println(\"?: print this help\");\r\n  Serial.println(\"h: print this help\");\r\n  Serial.println(\"***************\");\r\n}\r\n\r\nvoid serial_handler()\r\n{\r\n  char inChar;\r\n  if ((inChar = Serial.read()) > 0)\r\n  {\r\n    switch (inChar)\r\n    {\r\n      case 'w': // Previus item\r\n        ms.prev();\r\n        ms.display();\r\n        Serial.println(\"\");\r\n        break;\r\n      case 's': // Next item\r\n        ms.next();\r\n        ms.display();\r\n        Serial.println(\"\");\r\n        break;\r\n      case 'a': // Back presed\r\n        ms.back();\r\n        ms.display();\r\n        Serial.println(\"\");\r\n        break;\r\n      case 'd': // Select presed\r\n        ms.select();\r\n        ms.display();\r\n        Serial.println(\"\");\r\n        break;\r\n      case '?':\r\n      case 'h': // Display help\r\n        ms.display();\r\n        Serial.println(\"\");\r\n        break;\r\n      default:\r\n        break;\r\n    }\r\n  }\r\n}\r\n\r\n// Standard arduino functions\r\n\r\nvoid setup()\r\n{\r\n  Serial.begin(9600);\r\n\r\n  ms.get_root_menu().add_item(&mm_mi1);\r\n  ms.get_root_menu().add_item(&mm_mi2);\r\n  \r\n  ms.get_root_menu().add_menu(&mu1);\r\n  mu1.add_item(&mu1_mi1);\r\n  //   ms.get_root_menu().add_item(&mm_mi2);\r\n  //ms.get_root_menu().add_menu(&mu2);\r\n  //mu1.add_item(&mu1_mi1);\r\n  mu1.add_item(&mu1_mi2);\r\n  mu1.add_item(&mu1_mi3);\r\n  mu1.add_item(&mu1_mi4);\r\n  //added by emiel\r\n  ms.get_root_menu().add_menu(&mu2);\r\n  mu2.add_item(&mu2_mi1);\r\n  mu2.add_item(&mu2_mi2);\r\n  mu2.add_item(&mu2_mi3);\r\n  ms.get_root_menu().add_item(&mm_mi4);\r\n  ms.get_root_menu().add_item(&mm_mi5);\r\n\r\n  \r\n  display_help();\r\n  ms.display();\r\n  Serial.println(\"\");\r\n  // stoomgenerator aan/uit functie als geselecteerd beginnen ECL\r\n  ms.select();\r\n  ms.display();\r\n  Serial.println(\"\");\r\n\r\n}\r\n\r\nvoid loop()\r\n{\r\n  serial_handler();`\r\n```\r\n"}}
{"actor":{"display_login":"jonblack"}}