搜索
bottom↓
回复: 121

2017作品系列(一):发布文本菜单神器menu_creator_v1.0

  [复制链接]

出10入23汤圆

发表于 2017-3-9 13:30:13 | 显示全部楼层 |阅读模式
本帖最后由 zouzhichao 于 2017-3-9 21:06 编辑

缘由:近来在做一个手持设备(12864+四个操作按键),在确定程序架构后,修修改改甚是烦躁,于是乎在架构稳定之后写了这么一个菜单程序生成器。
1)先上菜单描述文件范例menu_test.xml,伪造的xml文件,实际解析自己lex&yacc做的。
  1. <menu>
  2.         <item>
  3.                 <item_para item_type = "PUSH_BUTTON" item_name = "数字输出端口" is_item_checked = "0" func_onclick = "NULL" />
  4.                 <item>
  5.                         <item_para item_type = "PUSH_BUTTON" item_name = "端口A设置" is_item_checked = "0" func_onclick = "NULL" />
  6.                         <item>
  7.                                 <item_para item_type = "CHECK_BUTTON" item_name = "Bit0输出低" is_item_checked = "0" func_onclick = "NULL" />
  8.                         </item>
  9.                         <item>
  10.                                 <item_para item_type = "CHECK_BUTTON" item_name = "Bit1输出低" is_item_checked = "0" func_onclick = "NULL" />
  11.                         </item>
  12.                         <item>
  13.                                 <item_para item_type = "CHECK_BUTTON" item_name = "Bit2输出低" is_item_checked = "0" func_onclick = "NULL" />
  14.                         </item>
  15.                         <item>
  16.                                 <item_para item_type = "CHECK_BUTTON" item_name = "Bit3输出低" is_item_checked = "0" func_onclick = "NULL" />
  17.                         </item>
  18.                         <item>
  19.                                 <item_para item_type = "CHECK_BUTTON" item_name = "Bit4输出低" is_item_checked = "0" func_onclick = "NULL" />
  20.                         </item>
  21.                         <item>
  22.                                 <item_para item_type = "CHECK_BUTTON" item_name = "Bit5输出低" is_item_checked = "0" func_onclick = "NULL" />
  23.                         </item>
  24.                         <item>
  25.                                 <item_para item_type = "CHECK_BUTTON" item_name = "Bit6输出低" is_item_checked = "0" func_onclick = "NULL" />
  26.                         </item>
  27.                         <item>
  28.                                 <item_para item_type = "CHECK_BUTTON" item_name = "Bit7输出低" is_item_checked = "0" func_onclick = "NULL" />
  29.                         </item>
  30.                 </item>
  31.                 <item>
  32.                         <item_para item_type = "PUSH_BUTTON" item_name = "端口B设置" is_item_checked = "0" func_onclick = "NULL" />
  33.                         <item>
  34.                                 <item_para item_type = "CHECK_BUTTON" item_name = "Bit0输出低" is_item_checked = "0" func_onclick = "NULL" />
  35.                         </item>
  36.                         <item>
  37.                                 <item_para item_type = "CHECK_BUTTON" item_name = "Bit1输出低" is_item_checked = "0" func_onclick = "NULL" />
  38.                         </item>
  39.                         <item>
  40.                                 <item_para item_type = "CHECK_BUTTON" item_name = "Bit2输出低" is_item_checked = "0" func_onclick = "NULL" />
  41.                         </item>
  42.                         <item>
  43.                                 <item_para item_type = "CHECK_BUTTON" item_name = "Bit3输出低" is_item_checked = "0" func_onclick = "NULL" />
  44.                         </item>
  45.                         <item>
  46.                                 <item_para item_type = "CHECK_BUTTON" item_name = "Bit4输出低" is_item_checked = "0" func_onclick = "NULL" />
  47.                         </item>
  48.                         <item>
  49.                                 <item_para item_type = "CHECK_BUTTON" item_name = "Bit5输出低" is_item_checked = "0" func_onclick = "NULL" />
  50.                         </item>
  51.                         <item>
  52.                                 <item_para item_type = "CHECK_BUTTON" item_name = "Bit6输出低" is_item_checked = "0" func_onclick = "NULL" />
  53.                         </item>
  54.                         <item>
  55.                                 <item_para item_type = "CHECK_BUTTON" item_name = "Bit7输出低" is_item_checked = "0" func_onclick = "NULL" />
  56.                         </item>
  57.                 </item>
  58.         </item>
  59.         <item>
  60.                 <item_para item_type = "PUSH_BUTTON" item_name = "输出源选择" is_item_checked = "0" func_onclick = "NULL" />
  61.                 <item>
  62.                         <item_para item_type = "PUSH_BUTTON" item_name = "4-20mA源选择" is_item_checked = "0" func_onclick = "NULL" />
  63.                         <item>
  64.                                 <item_para item_type = "RADIO_BUTTON" item_name = "0:PT100电阻" is_item_checked = "0" func_onclick = "NULL" />
  65.                         </item>
  66.                         <item>
  67.                                 <item_para item_type = "RADIO_BUTTON" item_name = "1:K型热电偶" is_item_checked = "0" func_onclick = "NULL" />
  68.                         </item>
  69.                         <item>
  70.                                 <item_para item_type = "RADIO_BUTTON" item_name = "2:MBUS变量A" is_item_checked = "0" func_onclick = "NULL" />
  71.                         </item>
  72.                         <item>
  73.                                 <item_para item_type = "RADIO_BUTTON" item_name = "3:MBUS变量B" is_item_checked = "0" func_onclick = "NULL" />
  74.                         </item>
  75.                 </item>
  76.                 <item>
  77.                         <item_para item_type = "PUSH_BUTTON" item_name = "0-5V源选择" is_item_checked = "0" func_onclick = "NULL" />
  78.                         <item>
  79.                                 <item_para item_type = "RADIO_BUTTON" item_name = "0:PT100电阻" is_item_checked = "0" func_onclick = "NULL" />
  80.                         </item>
  81.                         <item>
  82.                                 <item_para item_type = "RADIO_BUTTON" item_name = "1:K型热电偶" is_item_checked = "0" func_onclick = "NULL" />
  83.                         </item>
  84.                         <item>
  85.                                 <item_para item_type = "RADIO_BUTTON" item_name = "2:MBUS变量A" is_item_checked = "0" func_onclick = "NULL" />
  86.                         </item>
  87.                         <item>
  88.                                 <item_para item_type = "RADIO_BUTTON" item_name = "3:MBUS变量B" is_item_checked = "0" func_onclick = "NULL" />
  89.                         </item>
  90.                 </item>
  91.         </item>
  92.         <item>
  93.                 <item_para item_type = "PUSH_BUTTON" item_name = "线性化设置" is_item_checked = "0" func_onclick = "NULL" />
  94.                 <item>
  95.                         <item_para item_type = "PUSH_BUTTON" item_name = "4-20mA线性化" is_item_checked = "0" func_onclick = "NULL" />
  96.                         <item>
  97.                                 <item_para item_type = "PUSH_BUTTON" item_name = "4mA-温度" is_item_checked = "0" func_onclick = "NULL" />
  98.                                 <item>
  99.                                         <item_para item_type = "RADIO_BUTTON" item_name = "-100" is_item_checked = "0" func_onclick = "NULL" />
  100.                                 </item>
  101.                                 <item>
  102.                                         <item_para item_type = "RADIO_BUTTON" item_name = "0" is_item_checked = "0" func_onclick = "NULL" />
  103.                                 </item>
  104.                                 <item>
  105.                                         <item_para item_type = "RADIO_BUTTON" item_name = "100" is_item_checked = "0" func_onclick = "NULL" />
  106.                                 </item>
  107.                                 <item>
  108.                                         <item_para item_type = "RADIO_BUTTON" item_name = "200" is_item_checked = "0" func_onclick = "NULL" />
  109.                                 </item>
  110.                                 <item>
  111.                                         <item_para item_type = "RADIO_BUTTON" item_name = "300" is_item_checked = "0" func_onclick = "NULL" />
  112.                                 </item>
  113.                                 <item>
  114.                                         <item_para item_type = "RADIO_BUTTON" item_name = "400" is_item_checked = "0" func_onclick = "NULL" />
  115.                                 </item>
  116.                                 <item>
  117.                                         <item_para item_type = "RADIO_BUTTON" item_name = "500" is_item_checked = "0" func_onclick = "NULL" />
  118.                                 </item>
  119.                                 <item>
  120.                                         <item_para item_type = "RADIO_BUTTON" item_name = "600" is_item_checked = "0" func_onclick = "NULL" />
  121.                                 </item>
  122.                                 <item>
  123.                                         <item_para item_type = "RADIO_BUTTON" item_name = "700" is_item_checked = "0" func_onclick = "NULL" />
  124.                                 </item>
  125.                                 <item>
  126.                                         <item_para item_type = "RADIO_BUTTON" item_name = "800" is_item_checked = "0" func_onclick = "NULL" />
  127.                                 </item>
  128.                                 <item>
  129.                                         <item_para item_type = "RADIO_BUTTON" item_name = "900" is_item_checked = "0" func_onclick = "NULL" />
  130.                                 </item>
  131.                                 <item>
  132.                                         <item_para item_type = "RADIO_BUTTON" item_name = "1000" is_item_checked = "0" func_onclick = "NULL" />
  133.                                 </item>
  134.                                 <item>
  135.                                         <item_para item_type = "RADIO_BUTTON" item_name = "1100" is_item_checked = "0" func_onclick = "NULL" />
  136.                                 </item>
  137.                                 <item>
  138.                                         <item_para item_type = "RADIO_BUTTON" item_name = "1200" is_item_checked = "0" func_onclick = "NULL" />
  139.                                 </item>
  140.                         </item>
  141.                         <item>
  142.                                 <item_para item_type = "PUSH_BUTTON" item_name = "20mA-温度" is_item_checked = "0" func_onclick = "NULL" />
  143.                                 <item>
  144.                                         <item_para item_type = "RADIO_BUTTON" item_name = "-100" is_item_checked = "0" func_onclick = "NULL" />
  145.                                 </item>
  146.                                 <item>
  147.                                         <item_para item_type = "RADIO_BUTTON" item_name = "0" is_item_checked = "0" func_onclick = "NULL" />
  148.                                 </item>
  149.                                 <item>
  150.                                         <item_para item_type = "RADIO_BUTTON" item_name = "100" is_item_checked = "0" func_onclick = "NULL" />
  151.                                 </item>
  152.                                 <item>
  153.                                         <item_para item_type = "RADIO_BUTTON" item_name = "200" is_item_checked = "0" func_onclick = "NULL" />
  154.                                 </item>
  155.                                 <item>
  156.                                         <item_para item_type = "RADIO_BUTTON" item_name = "300" is_item_checked = "0" func_onclick = "NULL" />
  157.                                 </item>
  158.                                 <item>
  159.                                         <item_para item_type = "RADIO_BUTTON" item_name = "400" is_item_checked = "0" func_onclick = "NULL" />
  160.                                 </item>
  161.                                 <item>
  162.                                         <item_para item_type = "RADIO_BUTTON" item_name = "500" is_item_checked = "0" func_onclick = "NULL" />
  163.                                 </item>
  164.                                 <item>
  165.                                         <item_para item_type = "RADIO_BUTTON" item_name = "600" is_item_checked = "0" func_onclick = "NULL" />
  166.                                 </item>
  167.                                 <item>
  168.                                         <item_para item_type = "RADIO_BUTTON" item_name = "700" is_item_checked = "0" func_onclick = "NULL" />
  169.                                 </item>
  170.                                 <item>
  171.                                         <item_para item_type = "RADIO_BUTTON" item_name = "800" is_item_checked = "0" func_onclick = "NULL" />
  172.                                 </item>
  173.                                 <item>
  174.                                         <item_para item_type = "RADIO_BUTTON" item_name = "900" is_item_checked = "0" func_onclick = "NULL" />
  175.                                 </item>
  176.                                 <item>
  177.                                         <item_para item_type = "RADIO_BUTTON" item_name = "1000" is_item_checked = "0" func_onclick = "NULL" />
  178.                                 </item>
  179.                                 <item>
  180.                                         <item_para item_type = "RADIO_BUTTON" item_name = "1100" is_item_checked = "0" func_onclick = "NULL" />
  181.                                 </item>
  182.                                 <item>
  183.                                         <item_para item_type = "RADIO_BUTTON" item_name = "1200" is_item_checked = "0" func_onclick = "NULL" />
  184.                                 </item>
  185.                         </item>
  186.                 </item>
  187.                 <item>
  188.                         <item_para item_type = "PUSH_BUTTON" item_name = "0-5V线性化" is_item_checked = "0" func_onclick = "NULL" />
  189.                         <item>
  190.                                 <item_para item_type = "PUSH_BUTTON" item_name = "0V-温度" is_item_checked = "0" func_onclick = "NULL" />
  191.                                 <item>
  192.                                         <item_para item_type = "RADIO_BUTTON" item_name = "-100" is_item_checked = "0" func_onclick = "NULL" />
  193.                                 </item>
  194.                                 <item>
  195.                                         <item_para item_type = "RADIO_BUTTON" item_name = "0" is_item_checked = "0" func_onclick = "NULL" />
  196.                                 </item>
  197.                                 <item>
  198.                                         <item_para item_type = "RADIO_BUTTON" item_name = "100" is_item_checked = "0" func_onclick = "NULL" />
  199.                                 </item>
  200.                                 <item>
  201.                                         <item_para item_type = "RADIO_BUTTON" item_name = "200" is_item_checked = "0" func_onclick = "NULL" />
  202.                                 </item>
  203.                                 <item>
  204.                                         <item_para item_type = "RADIO_BUTTON" item_name = "300" is_item_checked = "0" func_onclick = "NULL" />
  205.                                 </item>
  206.                                 <item>
  207.                                         <item_para item_type = "RADIO_BUTTON" item_name = "400" is_item_checked = "0" func_onclick = "NULL" />
  208.                                 </item>
  209.                                 <item>
  210.                                         <item_para item_type = "RADIO_BUTTON" item_name = "500" is_item_checked = "0" func_onclick = "NULL" />
  211.                                 </item>
  212.                                 <item>
  213.                                         <item_para item_type = "RADIO_BUTTON" item_name = "600" is_item_checked = "0" func_onclick = "NULL" />
  214.                                 </item>
  215.                                 <item>
  216.                                         <item_para item_type = "RADIO_BUTTON" item_name = "700" is_item_checked = "0" func_onclick = "NULL" />
  217.                                 </item>
  218.                                 <item>
  219.                                         <item_para item_type = "RADIO_BUTTON" item_name = "800" is_item_checked = "0" func_onclick = "NULL" />
  220.                                 </item>
  221.                                 <item>
  222.                                         <item_para item_type = "RADIO_BUTTON" item_name = "900" is_item_checked = "0" func_onclick = "NULL" />
  223.                                 </item>
  224.                                 <item>
  225.                                         <item_para item_type = "RADIO_BUTTON" item_name = "1000" is_item_checked = "0" func_onclick = "NULL" />
  226.                                 </item>
  227.                                 <item>
  228.                                         <item_para item_type = "RADIO_BUTTON" item_name = "1100" is_item_checked = "0" func_onclick = "NULL" />
  229.                                 </item>
  230.                                 <item>
  231.                                         <item_para item_type = "RADIO_BUTTON" item_name = "1200" is_item_checked = "0" func_onclick = "NULL" />
  232.                                 </item>
  233.                         </item>
  234.                         <item>
  235.                                 <item_para item_type = "PUSH_BUTTON" item_name = "5V-温度" is_item_checked = "0" func_onclick = "NULL" />
  236.                                 <item>
  237.                                         <item_para item_type = "RADIO_BUTTON" item_name = "-100" is_item_checked = "0" func_onclick = "NULL" />
  238.                                 </item>
  239.                                 <item>
  240.                                         <item_para item_type = "RADIO_BUTTON" item_name = "0" is_item_checked = "0" func_onclick = "NULL" />
  241.                                 </item>
  242.                                 <item>
  243.                                         <item_para item_type = "RADIO_BUTTON" item_name = "100" is_item_checked = "0" func_onclick = "NULL" />
  244.                                 </item>
  245.                                 <item>
  246.                                         <item_para item_type = "RADIO_BUTTON" item_name = "200" is_item_checked = "0" func_onclick = "NULL" />
  247.                                 </item>
  248.                                 <item>
  249.                                         <item_para item_type = "RADIO_BUTTON" item_name = "300" is_item_checked = "0" func_onclick = "NULL" />
  250.                                 </item>
  251.                                 <item>
  252.                                         <item_para item_type = "RADIO_BUTTON" item_name = "400" is_item_checked = "0" func_onclick = "NULL" />
  253.                                 </item>
  254.                                 <item>
  255.                                         <item_para item_type = "RADIO_BUTTON" item_name = "500" is_item_checked = "0" func_onclick = "NULL" />
  256.                                 </item>
  257.                                 <item>
  258.                                         <item_para item_type = "RADIO_BUTTON" item_name = "600" is_item_checked = "0" func_onclick = "NULL" />
  259.                                 </item>
  260.                                 <item>
  261.                                         <item_para item_type = "RADIO_BUTTON" item_name = "700" is_item_checked = "0" func_onclick = "NULL" />
  262.                                 </item>
  263.                                 <item>
  264.                                         <item_para item_type = "RADIO_BUTTON" item_name = "800" is_item_checked = "0" func_onclick = "NULL" />
  265.                                 </item>
  266.                                 <item>
  267.                                         <item_para item_type = "RADIO_BUTTON" item_name = "900" is_item_checked = "0" func_onclick = "NULL" />
  268.                                 </item>
  269.                                 <item>
  270.                                         <item_para item_type = "RADIO_BUTTON" item_name = "1000" is_item_checked = "0" func_onclick = "NULL" />
  271.                                 </item>
  272.                                 <item>
  273.                                         <item_para item_type = "RADIO_BUTTON" item_name = "1100" is_item_checked = "0" func_onclick = "NULL" />
  274.                                 </item>
  275.                                 <item>
  276.                                         <item_para item_type = "RADIO_BUTTON" item_name = "1200" is_item_checked = "0" func_onclick = "NULL" />
  277.                                 </item>
  278.                         </item>
  279.                 </item>
  280.         </item>
  281. </menu>
复制代码


描述内容无非就是菜单结构(子菜单关系),还有每项菜单的描述,比如菜单类型(普通菜单,单选菜单,多选菜单),菜单名字,是否勾选,响应函数名等

2)怎么使用神器,以一个bat文件内容为例自动生成C代码.bat
  1. menu_creator.exe menu_test.xml 16 4 >main.c
  2. pause
复制代码

16 4表示12864的缓存区大小:每行16个字符,一共4行

3)生成的C代码main.c
  1. /************************************************************************************************************************
  2. 使用说明:
  3. 01.本文件用于四按键文本菜单架构!
  4. 02.本文件可以直接在PC上编译成控制台模拟程序,软件作者使用CFree测试!
  5. 03.控制台模拟程序使用上下左右方向键控制菜单!
  6. 04.上下方向键对应菜单上下翻,左方向键对应菜单回退,右方向键对应点击菜单,ESC键表示结束程序!
  7. 05.本程序可以很方便地移植到单片机系统!
  8. 06.嵌入式移植需重写void update_screen(const int8_t* buffer)函数!
  9. 07.void update_screen(const int8_t* buffer)函数表示把buffer里面的内容放到屏幕中,比如12864屏的buffer大小为4R16C = 64!
  10. 08.本文件提供函数void menu_update(void)用于在屏幕上刷新菜单!
  11. 09.本文件提供函数void menu_init(void)用于初始化菜单!
  12. 10.本文件提供函数ITEM* get_item_index_now(void)用于获取当前选定的菜单项!
  13. 11.本文件提供函数void menu_item_enable(int32_t index)用于使能菜单项!
  14. 12.本文件提供函数void menu_item_disable(int32_t index)用于禁止菜单项!
  15. 13.本文件提供函数void menu_item_rename(int32_t index, const int8_t* name)用于修改菜单项的名字!
  16. 14.本文件提供函数void key_func(int8_t key)用于处理按键消息!
  17. ************************************************************************************************************************/

  18. #include <stdio.h>
  19. #include <stdint.h>

  20. #define SCREEN_X_SIZE (16)
  21. #define SCREEN_Y_SIZE (4)
  22. #define MENU_DEPTH (4)
  23. #define ITEM_AMOUNT (93)
  24. #define PAGE_AMOUNT (14)
  25. #define PUSH_BUTTON (1)
  26. #define RADIO_BUTTON (2)
  27. #define CHECK_BUTTON (3)
  28. #define KEY_ENTER (1)
  29. #define KEY_ESC (2)
  30. #define KEY_UP (3)
  31. #define KEY_DOWN (4)


  32. typedef struct tagITEM {
  33.         int8_t type;
  34.         int8_t is_enable;
  35.         int8_t child;
  36.         int8_t is_checked;
  37.         int8_t* name;
  38.         int8_t (*func_on_click)(int8_t index_in_page);
  39. }ITEM;

  40. ITEM item_pool[ITEM_AMOUNT] = {
  41.         {CHECK_BUTTON, -1,  -1, 0, (int8_t*)"Bit0输出低  ", NULL}, /* page_index = 0, depth = 3 */
  42.         {CHECK_BUTTON, -1,  -1, 0, (int8_t*)"Bit1输出低  ", NULL}, /* page_index = 0, depth = 3 */
  43.         {CHECK_BUTTON, -1,  -1, 0, (int8_t*)"Bit2输出低  ", NULL}, /* page_index = 0, depth = 3 */
  44.         {CHECK_BUTTON, -1,  -1, 0, (int8_t*)"Bit3输出低  ", NULL}, /* page_index = 0, depth = 3 */
  45.         {CHECK_BUTTON, -1,  -1, 0, (int8_t*)"Bit4输出低  ", NULL}, /* page_index = 0, depth = 3 */
  46.         {CHECK_BUTTON, -1,  -1, 0, (int8_t*)"Bit5输出低  ", NULL}, /* page_index = 0, depth = 3 */
  47.         {CHECK_BUTTON, -1,  -1, 0, (int8_t*)"Bit6输出低  ", NULL}, /* page_index = 0, depth = 3 */
  48.         {CHECK_BUTTON, -1,  -1, 0, (int8_t*)"Bit7输出低  ", NULL}, /* page_index = 0, depth = 3 */
  49.         {CHECK_BUTTON, -1,  -1, 0, (int8_t*)"Bit0输出低  ", NULL}, /* page_index = 1, depth = 3 */
  50.         {CHECK_BUTTON, -1,  -1, 0, (int8_t*)"Bit1输出低  ", NULL}, /* page_index = 1, depth = 3 */
  51.         {CHECK_BUTTON, -1,  -1, 0, (int8_t*)"Bit2输出低  ", NULL}, /* page_index = 1, depth = 3 */
  52.         {CHECK_BUTTON, -1,  -1, 0, (int8_t*)"Bit3输出低  ", NULL}, /* page_index = 1, depth = 3 */
  53.         {CHECK_BUTTON, -1,  -1, 0, (int8_t*)"Bit4输出低  ", NULL}, /* page_index = 1, depth = 3 */
  54.         {CHECK_BUTTON, -1,  -1, 0, (int8_t*)"Bit5输出低  ", NULL}, /* page_index = 1, depth = 3 */
  55.         {CHECK_BUTTON, -1,  -1, 0, (int8_t*)"Bit6输出低  ", NULL}, /* page_index = 1, depth = 3 */
  56.         {CHECK_BUTTON, -1,  -1, 0, (int8_t*)"Bit7输出低  ", NULL}, /* page_index = 1, depth = 3 */
  57.         { PUSH_BUTTON, -1,   0, 0, (int8_t*)"端口A设置   ", NULL}, /* page_index = 2, depth = 2 */
  58.         { PUSH_BUTTON, -1,   1, 0, (int8_t*)"端口B设置   ", NULL}, /* page_index = 2, depth = 2 */
  59.         {RADIO_BUTTON, -1,  -1, 0, (int8_t*)"0:PT100电阻 ", NULL}, /* page_index = 3, depth = 3 */
  60.         {RADIO_BUTTON, -1,  -1, 0, (int8_t*)"1:K型热电偶 ", NULL}, /* page_index = 3, depth = 3 */
  61.         {RADIO_BUTTON, -1,  -1, 0, (int8_t*)"2:MBUS变量A ", NULL}, /* page_index = 3, depth = 3 */
  62.         {RADIO_BUTTON, -1,  -1, 0, (int8_t*)"3:MBUS变量B ", NULL}, /* page_index = 3, depth = 3 */
  63.         {RADIO_BUTTON, -1,  -1, 0, (int8_t*)"0:PT100电阻 ", NULL}, /* page_index = 4, depth = 3 */
  64.         {RADIO_BUTTON, -1,  -1, 0, (int8_t*)"1:K型热电偶 ", NULL}, /* page_index = 4, depth = 3 */
  65.         {RADIO_BUTTON, -1,  -1, 0, (int8_t*)"2:MBUS变量A ", NULL}, /* page_index = 4, depth = 3 */
  66.         {RADIO_BUTTON, -1,  -1, 0, (int8_t*)"3:MBUS变量B ", NULL}, /* page_index = 4, depth = 3 */
  67.         { PUSH_BUTTON, -1,   3, 0, (int8_t*)"4-20mA源选择", NULL}, /* page_index = 5, depth = 2 */
  68.         { PUSH_BUTTON, -1,   4, 0, (int8_t*)"0-5V源选择  ", NULL}, /* page_index = 5, depth = 2 */
  69.         {RADIO_BUTTON, -1,  -1, 0, (int8_t*)"-100        ", NULL}, /* page_index = 6, depth = 4 */
  70.         {RADIO_BUTTON, -1,  -1, 0, (int8_t*)"0           ", NULL}, /* page_index = 6, depth = 4 */
  71.         {RADIO_BUTTON, -1,  -1, 0, (int8_t*)"100         ", NULL}, /* page_index = 6, depth = 4 */
  72.         {RADIO_BUTTON, -1,  -1, 0, (int8_t*)"200         ", NULL}, /* page_index = 6, depth = 4 */
  73.         {RADIO_BUTTON, -1,  -1, 0, (int8_t*)"300         ", NULL}, /* page_index = 6, depth = 4 */
  74.         {RADIO_BUTTON, -1,  -1, 0, (int8_t*)"400         ", NULL}, /* page_index = 6, depth = 4 */
  75.         {RADIO_BUTTON, -1,  -1, 0, (int8_t*)"500         ", NULL}, /* page_index = 6, depth = 4 */
  76.         {RADIO_BUTTON, -1,  -1, 0, (int8_t*)"600         ", NULL}, /* page_index = 6, depth = 4 */
  77.         {RADIO_BUTTON, -1,  -1, 0, (int8_t*)"700         ", NULL}, /* page_index = 6, depth = 4 */
  78.         {RADIO_BUTTON, -1,  -1, 0, (int8_t*)"800         ", NULL}, /* page_index = 6, depth = 4 */
  79.         {RADIO_BUTTON, -1,  -1, 0, (int8_t*)"900         ", NULL}, /* page_index = 6, depth = 4 */
  80.         {RADIO_BUTTON, -1,  -1, 0, (int8_t*)"1000        ", NULL}, /* page_index = 6, depth = 4 */
  81.         {RADIO_BUTTON, -1,  -1, 0, (int8_t*)"1100        ", NULL}, /* page_index = 6, depth = 4 */
  82.         {RADIO_BUTTON, -1,  -1, 0, (int8_t*)"1200        ", NULL}, /* page_index = 6, depth = 4 */
  83.         {RADIO_BUTTON, -1,  -1, 0, (int8_t*)"-100        ", NULL}, /* page_index = 7, depth = 4 */
  84.         {RADIO_BUTTON, -1,  -1, 0, (int8_t*)"0           ", NULL}, /* page_index = 7, depth = 4 */
  85.         {RADIO_BUTTON, -1,  -1, 0, (int8_t*)"100         ", NULL}, /* page_index = 7, depth = 4 */
  86.         {RADIO_BUTTON, -1,  -1, 0, (int8_t*)"200         ", NULL}, /* page_index = 7, depth = 4 */
  87.         {RADIO_BUTTON, -1,  -1, 0, (int8_t*)"300         ", NULL}, /* page_index = 7, depth = 4 */
  88.         {RADIO_BUTTON, -1,  -1, 0, (int8_t*)"400         ", NULL}, /* page_index = 7, depth = 4 */
  89.         {RADIO_BUTTON, -1,  -1, 0, (int8_t*)"500         ", NULL}, /* page_index = 7, depth = 4 */
  90.         {RADIO_BUTTON, -1,  -1, 0, (int8_t*)"600         ", NULL}, /* page_index = 7, depth = 4 */
  91.         {RADIO_BUTTON, -1,  -1, 0, (int8_t*)"700         ", NULL}, /* page_index = 7, depth = 4 */
  92.         {RADIO_BUTTON, -1,  -1, 0, (int8_t*)"800         ", NULL}, /* page_index = 7, depth = 4 */
  93.         {RADIO_BUTTON, -1,  -1, 0, (int8_t*)"900         ", NULL}, /* page_index = 7, depth = 4 */
  94.         {RADIO_BUTTON, -1,  -1, 0, (int8_t*)"1000        ", NULL}, /* page_index = 7, depth = 4 */
  95.         {RADIO_BUTTON, -1,  -1, 0, (int8_t*)"1100        ", NULL}, /* page_index = 7, depth = 4 */
  96.         {RADIO_BUTTON, -1,  -1, 0, (int8_t*)"1200        ", NULL}, /* page_index = 7, depth = 4 */
  97.         { PUSH_BUTTON, -1,   6, 0, (int8_t*)"4mA-温度    ", NULL}, /* page_index = 8, depth = 3 */
  98.         { PUSH_BUTTON, -1,   7, 0, (int8_t*)"20mA-温度   ", NULL}, /* page_index = 8, depth = 3 */
  99.         {RADIO_BUTTON, -1,  -1, 0, (int8_t*)"-100        ", NULL}, /* page_index = 9, depth = 4 */
  100.         {RADIO_BUTTON, -1,  -1, 0, (int8_t*)"0           ", NULL}, /* page_index = 9, depth = 4 */
  101.         {RADIO_BUTTON, -1,  -1, 0, (int8_t*)"100         ", NULL}, /* page_index = 9, depth = 4 */
  102.         {RADIO_BUTTON, -1,  -1, 0, (int8_t*)"200         ", NULL}, /* page_index = 9, depth = 4 */
  103.         {RADIO_BUTTON, -1,  -1, 0, (int8_t*)"300         ", NULL}, /* page_index = 9, depth = 4 */
  104.         {RADIO_BUTTON, -1,  -1, 0, (int8_t*)"400         ", NULL}, /* page_index = 9, depth = 4 */
  105.         {RADIO_BUTTON, -1,  -1, 0, (int8_t*)"500         ", NULL}, /* page_index = 9, depth = 4 */
  106.         {RADIO_BUTTON, -1,  -1, 0, (int8_t*)"600         ", NULL}, /* page_index = 9, depth = 4 */
  107.         {RADIO_BUTTON, -1,  -1, 0, (int8_t*)"700         ", NULL}, /* page_index = 9, depth = 4 */
  108.         {RADIO_BUTTON, -1,  -1, 0, (int8_t*)"800         ", NULL}, /* page_index = 9, depth = 4 */
  109.         {RADIO_BUTTON, -1,  -1, 0, (int8_t*)"900         ", NULL}, /* page_index = 9, depth = 4 */
  110.         {RADIO_BUTTON, -1,  -1, 0, (int8_t*)"1000        ", NULL}, /* page_index = 9, depth = 4 */
  111.         {RADIO_BUTTON, -1,  -1, 0, (int8_t*)"1100        ", NULL}, /* page_index = 9, depth = 4 */
  112.         {RADIO_BUTTON, -1,  -1, 0, (int8_t*)"1200        ", NULL}, /* page_index = 9, depth = 4 */
  113.         {RADIO_BUTTON, -1,  -1, 0, (int8_t*)"-100        ", NULL}, /* page_index = 10, depth = 4 */
  114.         {RADIO_BUTTON, -1,  -1, 0, (int8_t*)"0           ", NULL}, /* page_index = 10, depth = 4 */
  115.         {RADIO_BUTTON, -1,  -1, 0, (int8_t*)"100         ", NULL}, /* page_index = 10, depth = 4 */
  116.         {RADIO_BUTTON, -1,  -1, 0, (int8_t*)"200         ", NULL}, /* page_index = 10, depth = 4 */
  117.         {RADIO_BUTTON, -1,  -1, 0, (int8_t*)"300         ", NULL}, /* page_index = 10, depth = 4 */
  118.         {RADIO_BUTTON, -1,  -1, 0, (int8_t*)"400         ", NULL}, /* page_index = 10, depth = 4 */
  119.         {RADIO_BUTTON, -1,  -1, 0, (int8_t*)"500         ", NULL}, /* page_index = 10, depth = 4 */
  120.         {RADIO_BUTTON, -1,  -1, 0, (int8_t*)"600         ", NULL}, /* page_index = 10, depth = 4 */
  121.         {RADIO_BUTTON, -1,  -1, 0, (int8_t*)"700         ", NULL}, /* page_index = 10, depth = 4 */
  122.         {RADIO_BUTTON, -1,  -1, 0, (int8_t*)"800         ", NULL}, /* page_index = 10, depth = 4 */
  123.         {RADIO_BUTTON, -1,  -1, 0, (int8_t*)"900         ", NULL}, /* page_index = 10, depth = 4 */
  124.         {RADIO_BUTTON, -1,  -1, 0, (int8_t*)"1000        ", NULL}, /* page_index = 10, depth = 4 */
  125.         {RADIO_BUTTON, -1,  -1, 0, (int8_t*)"1100        ", NULL}, /* page_index = 10, depth = 4 */
  126.         {RADIO_BUTTON, -1,  -1, 0, (int8_t*)"1200        ", NULL}, /* page_index = 10, depth = 4 */
  127.         { PUSH_BUTTON, -1,   9, 0, (int8_t*)"0V-温度     ", NULL}, /* page_index = 11, depth = 3 */
  128.         { PUSH_BUTTON, -1,  10, 0, (int8_t*)"5V-温度     ", NULL}, /* page_index = 11, depth = 3 */
  129.         { PUSH_BUTTON, -1,   8, 0, (int8_t*)"4-20mA线性化", NULL}, /* page_index = 12, depth = 2 */
  130.         { PUSH_BUTTON, -1,  11, 0, (int8_t*)"0-5V线性化  ", NULL}, /* page_index = 12, depth = 2 */
  131.         { PUSH_BUTTON, -1,   2, 0, (int8_t*)"数字输出端口", NULL}, /* page_index = 13, depth = 1 */
  132.         { PUSH_BUTTON, -1,   5, 0, (int8_t*)"输出源选择  ", NULL}, /* page_index = 13, depth = 1 */
  133.         { PUSH_BUTTON, -1,  12, 0, (int8_t*)"线性化设置  ", NULL}, /* page_index = 13, depth = 1 */
  134. };

  135. typedef struct tagPAGE {
  136.         ITEM* item_p;
  137.         int8_t item_amount;
  138.         int8_t index_focused;
  139.         int8_t index_displayed;
  140. }PAGE;

  141. PAGE page_pool[PAGE_AMOUNT] = {
  142.         {(ITEM*)item_pool + 0, 8, 0, 0},
  143.         {(ITEM*)item_pool + 8, 8, 0, 0},
  144.         {(ITEM*)item_pool + 16, 2, 0, 0},
  145.         {(ITEM*)item_pool + 18, 4, 0, 0},
  146.         {(ITEM*)item_pool + 22, 4, 0, 0},
  147.         {(ITEM*)item_pool + 26, 2, 0, 0},
  148.         {(ITEM*)item_pool + 28, 14, 0, 0},
  149.         {(ITEM*)item_pool + 42, 14, 0, 0},
  150.         {(ITEM*)item_pool + 56, 2, 0, 0},
  151.         {(ITEM*)item_pool + 58, 14, 0, 0},
  152.         {(ITEM*)item_pool + 72, 14, 0, 0},
  153.         {(ITEM*)item_pool + 86, 2, 0, 0},
  154.         {(ITEM*)item_pool + 88, 2, 0, 0},
  155.         {(ITEM*)item_pool + 90, 3, 0, 0},
  156. };

  157. static PAGE* page_stack[MENU_DEPTH] = {(PAGE*)page_pool + (PAGE_AMOUNT - 1)};
  158. static int8_t page_stack_now = 0;
  159. static int8_t screen_buffer[SCREEN_Y_SIZE * SCREEN_X_SIZE] = {'0'};
  160. void update_screen(const int8_t* buffer);

  161. static void screen_buffer_clr(void) {
  162.         int32_t i;
  163.         int8_t* p = (int8_t*)screen_buffer;
  164.         for (i = SCREEN_Y_SIZE * SCREEN_X_SIZE; i != 0; i--) {
  165.                 *p++ = '\0';
  166.         }
  167. }

  168. static void item_display(const ITEM* item, int8_t row, int8_t is_focused) {
  169.         int8_t i;
  170.         int8_t* p_src;
  171.         int8_t* p_dst;
  172.         if (row > SCREEN_Y_SIZE - 1) {
  173.                 return;
  174.         }
  175.         p_src = (int8_t*)item->name;
  176.         p_dst = (int8_t*)screen_buffer + row * SCREEN_X_SIZE;
  177.         *p_dst++ = is_focused;
  178.         for (i = SCREEN_X_SIZE - 4; i != 0; i--) {
  179.                 *p_dst++ = (*p_src)? (*p_src++) : ' ';
  180.         }
  181.         if (0 == item->is_enable) {
  182.                 *p_dst++ = ' ';
  183.                 *p_dst++ = 'X';
  184.                 *p_dst = ' ';
  185.                 return;
  186.         }
  187.         if (-1 != item->child) {
  188.                 *p_dst++ = ' ';
  189.                 *p_dst++ = '>';
  190.                 *p_dst = '>';
  191.                 return;
  192.         }
  193.         if (CHECK_BUTTON == item->type) {
  194.                 *p_dst++ = '[';
  195.                 *p_dst++ = item->is_checked? '@' : ' ';
  196.                 *p_dst = ']';
  197.                 return;
  198.         }
  199.         if (RADIO_BUTTON == item->type) {
  200.                 *p_dst++ = '(';
  201.                 *p_dst++ = item->is_checked? ' : ' ';
  202.                 *p_dst = ')';
  203.                 return;
  204.         }
  205. }

  206. void menu_update(void);

  207. static void key_enter_func(void) {
  208.         int8_t i;
  209.         PAGE* page_this = page_stack[page_stack_now];
  210.         ITEM* item_this = (page_this->item_p) + (page_this->index_focused);
  211.         if (0 == item_this->is_enable) {
  212.                 return;
  213.         }
  214.         if (NULL != item_this->func_on_click) {
  215.                 if (0 == item_this->func_on_click(page_this->index_focused)) {
  216.                         return;
  217.                 }
  218.         }
  219.         if ((item_this->child > -1) && (item_this->child < PAGE_AMOUNT)) {
  220.                 page_stack_now++;
  221.                 page_stack[page_stack_now] = (PAGE*)page_pool + item_this->child;
  222.         }
  223.         if (CHECK_BUTTON == item_this->type) {
  224.                 page_this->item_p[page_this->index_focused].is_checked ^= -1;
  225.                 return;
  226.         }
  227.         if (RADIO_BUTTON == item_this->type) {
  228.                 for (i = 0; i < page_this->item_amount; i++) {
  229.                         if (RADIO_BUTTON == page_this->item_p[i].type) {
  230.                                 page_this->item_p[i].is_checked = 0;
  231.                         }
  232.                 }
  233.                 item_this->is_checked = -1;
  234.                 return;
  235.         }
  236. }

  237. static void key_esc_func(void) {
  238.         PAGE* page_this = page_stack[page_stack_now];
  239.         if (page_stack_now > 0) {
  240.                 page_stack_now--;
  241.         }
  242. }

  243. static void key_up_func(void) {
  244.         PAGE* page_this = page_stack[page_stack_now];
  245.         if (page_this->index_focused > 0) {
  246.                 page_this->index_focused--;
  247.         }
  248.         if (page_this->index_displayed > page_this->index_focused) {
  249.                 page_this->index_displayed = page_this->index_focused;
  250.         }
  251. }

  252. static void key_down_func(void) {
  253.         PAGE* page_this = page_stack[page_stack_now];
  254.         if (page_this->index_focused < page_this->item_amount - 1) {
  255.                 page_this->index_focused++;
  256.         }
  257.         if (page_this->index_displayed < page_this->index_focused - (SCREEN_Y_SIZE - 1)) {
  258.                 page_this->index_displayed = page_this->index_focused - (SCREEN_Y_SIZE - 1);
  259.         }
  260. }

  261. void menu_update(void)
  262. {
  263.         int8_t i = 0, j;
  264.         PAGE* page = page_stack[page_stack_now];
  265.         screen_buffer_clr();
  266.         for (j = page->index_displayed; (i < SCREEN_Y_SIZE) && (j < page->item_amount); i++, j++) {
  267.                 item_display((const ITEM*)page->item_p + j, i, j == page->index_focused? '>' : ' ');
  268.         }
  269.         update_screen((const int8_t*)screen_buffer);
  270. }

  271. void menu_init(void) {
  272.         page_stack_now = 0;
  273.         page_stack[0] = (PAGE*)page_pool + (PAGE_AMOUNT - 1);
  274.         menu_update();
  275. }

  276. ITEM* get_item_index_now(void) {
  277.         PAGE* page_this = page_stack[page_stack_now];
  278.         return page_this->item_p + page_this->index_focused;
  279. }

  280. void menu_item_enable(int32_t index) {
  281.         if ((index < 0) || (index > ITEM_AMOUNT - 1)) {
  282.                 return;
  283.         }
  284.         ITEM* p = (ITEM*)item_pool + index;
  285.         p->is_enable = -1;
  286.         menu_update();
  287. }

  288. void menu_item_disable(int32_t index) {
  289.         if ((index < 0) || (index > ITEM_AMOUNT - 1)) {
  290.                 return;
  291.         }
  292.         ITEM* p = (ITEM*)item_pool + index;
  293.         p->is_enable = 0;
  294.         p->is_checked = 0;
  295.         menu_update();
  296. }

  297. void menu_item_rename(int32_t index, const int8_t* name) {
  298.         int8_t cnt;
  299.         int8_t* p;
  300.         if ((index < 0) || (index > ITEM_AMOUNT - 1)) {
  301.                 return;
  302.         }
  303.         p = (int8_t*)((ITEM*)item_pool + index)->name;
  304.         for (cnt = SCREEN_X_SIZE - 4; cnt != 0; cnt--) {
  305.                 *p++ = (*name)? (*name++) : ' ';
  306.         }
  307.         menu_update();
  308. }

  309. void key_func(int8_t key) {
  310.         switch (key) {
  311.                 case KEY_ENTER:
  312.                         key_enter_func();
  313.                         break;
  314.                 case KEY_ESC:
  315.                         key_esc_func();
  316.                         break;
  317.                 case KEY_UP:
  318.                         key_up_func();
  319.                         break;
  320.                 case KEY_DOWN:
  321.                         key_down_func();
  322.                         break;
  323.                 default:
  324.                         break;
  325.         }
  326.         menu_update();
  327. }

  328. #include <conio.h>
  329. #include <process.h>
  330. #include <windows.h>

  331. int main(int argc, char *argv[]) {
  332.         char ch;
  333.         menu_init();
  334.         for ( ; ; ) {
  335.                 ch = getch();
  336.                 if (77 == ch) { // right
  337.                         Beep(1000, 100);
  338.                         key_func(KEY_ENTER);
  339.                         continue;
  340.                 }
  341.                 if (75 == ch) { // left
  342.                         Beep(1000, 100);
  343.                         key_func(KEY_ESC);
  344.                         continue;
  345.                 }
  346.                 if (72 == ch) { // up
  347.                         Beep(1000, 100);
  348.                         key_func(KEY_UP);
  349.                         continue;
  350.                 }
  351.                 if (80 == ch) { // down
  352.                         Beep(1000, 100);
  353.                         key_func(KEY_DOWN);
  354.                         continue;
  355.                 }
  356.                 if (27 == ch) {
  357.                         break;
  358.                 }
  359.         }
  360.         return 0;
  361. }

  362. void update_screen(const int8_t* buffer) {
  363.         int8_t i, j;
  364.         system("cls");
  365.         for (i = SCREEN_Y_SIZE; i != 0; i--)
  366.         {
  367.                 for (j = SCREEN_X_SIZE; j != 0; j--) {
  368.                         printf((const char*)"%c", *buffer++);
  369.                 }
  370.                 printf((const char*)"\n");
  371.         }
  372. }
复制代码


4)编译main.c得到exe文件,运行效果如下图:










5)当然,最后要上附件咯


6)最后上传一个小巧c/c++开发环境,范例exe文件就是它编译的


编辑补充:V1.0发现一些不足,更新V1.1版:

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?注册

x

出10入23汤圆

 楼主| 发表于 2017-3-9 13:36:52 | 显示全部楼层
沙发自己坐

出20入70汤圆

发表于 2017-3-9 13:41:29 | 显示全部楼层
点赞!                        

出0入0汤圆

发表于 2017-3-9 13:53:05 | 显示全部楼层
顶楼主一下。

出10入23汤圆

 楼主| 发表于 2017-3-9 14:15:54 来自手机 | 显示全部楼层
su33691 发表于 2017-3-9 13:53
顶楼主一下。

谢谢帮顶!

出10入23汤圆

 楼主| 发表于 2017-3-9 14:16:13 来自手机 | 显示全部楼层
techbaby 发表于 2017-3-9 13:41
点赞!

谢谢点赞

出0入0汤圆

发表于 2017-3-9 14:17:58 | 显示全部楼层
方便很多人,虽然暂时用不上,也帮顶了

出0入0汤圆

发表于 2017-3-9 14:18:45 来自手机 | 显示全部楼层
牛B 学习一下

出0入0汤圆

发表于 2017-3-9 14:20:46 | 显示全部楼层
楼主好人,留着以后用!

出0入0汤圆

发表于 2017-3-9 14:28:41 | 显示全部楼层
楼主好人,留着以后用!

出0入0汤圆

发表于 2017-3-9 14:29:10 | 显示全部楼层
感谢分享,这确实方便不少,菜单框架确定了以后,最麻烦的就是改菜单内容了,有这小工具,事半功倍

出10入23汤圆

 楼主| 发表于 2017-3-9 14:30:03 来自手机 | 显示全部楼层
有学会怎么使用的朋友么?

出0入0汤圆

发表于 2017-3-9 14:31:54 | 显示全部楼层
留個爪子

出10入23汤圆

 楼主| 发表于 2017-3-9 14:32:26 来自手机 | 显示全部楼层
落叶随风 发表于 2017-3-9 14:29
感谢分享,这确实方便不少,菜单框架确定了以后,最麻烦的就是改菜单内容了,有这小工具,事半功倍 ...

再也不担心菜单需要改来改去了

出0入0汤圆

发表于 2017-3-9 18:21:52 来自手机 | 显示全部楼层
火钳刘明,论坛大虾都很牛。

出10入23汤圆

 楼主| 发表于 2017-3-9 18:39:27 来自手机 | 显示全部楼层
beeworld 发表于 2017-3-9 18:21
火钳刘明,论坛大虾都很牛。

比较简陋的菜单,只是做了个工具让代码写起来省体力些

出0入0汤圆

发表于 2017-3-9 19:16:05 | 显示全部楼层
顶楼主一下。

出0入0汤圆

发表于 2017-3-9 19:31:20 | 显示全部楼层
真心不错啊,楼主造福我们了

出0入0汤圆

发表于 2017-3-9 19:41:14 | 显示全部楼层
楼主牛人,谢谢分享!

出0入0汤圆

发表于 2017-3-9 19:50:41 | 显示全部楼层
收藏了,谢谢分享!

出0入0汤圆

发表于 2017-3-9 19:51:29 | 显示全部楼层
我顶你!!赞!

出40入42汤圆

发表于 2017-3-9 20:18:16 | 显示全部楼层
报告,楼主码代码不喜欢写注释

出50入4汤圆

发表于 2017-3-9 20:55:18 | 显示全部楼层
不会用,为自己智商捉急

出10入23汤圆

 楼主| 发表于 2017-3-9 21:11:55 | 显示全部楼层
补充:发现一些bug,更新V1.1版本
1)V1.0版本item name edit有错误,V1.1修正此内容
2)BUTTON类型增加一个可EDIT选项,有PUSH_BUTTON  PUSH_BUTTON_EDIT  RADIO_BUTTON  RADIO_BUTTON_EDIT  CHECK_BUTTON  CHECK_BUTTON_EDIT六种
3)功能测试上,BUTTON click响应函数增加测试输出(仅便于测试观察,无实际意义)

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?注册

x

出10入23汤圆

 楼主| 发表于 2017-3-9 21:16:56 | 显示全部楼层
落叶知秋 发表于 2017-3-9 20:18
报告,楼主码代码不喜欢写注释

额,这个。。。。。。。我写代码讲究灵感,灵感来了就来不及写注释了
这个软件从构思到实现lex&yacc解析,菜单树构建以及程序输出也就两天整的时间
再说,一共就那么些行程序,函数/变量命名这么有规律,应该不难读吧

出10入23汤圆

 楼主| 发表于 2017-3-9 21:18:18 | 显示全部楼层
zhuyi25762 发表于 2017-3-9 20:55
不会用,为自己智商捉急

压缩包里有一个样例,慢慢看一下就懂了

出0入0汤圆

发表于 2017-3-9 21:22:09 | 显示全部楼层
是否自动生成菜单代码?能不能搞个详细的说明啊?谢谢

出0入0汤圆

发表于 2017-3-9 21:28:48 | 显示全部楼层
嗯哈  楼主的思路很好 ,很方便

出10入23汤圆

 楼主| 发表于 2017-3-9 21:32:33 | 显示全部楼层
randyzzy 发表于 2017-3-9 21:22
是否自动生成菜单代码?能不能搞个详细的说明啊?谢谢

自动生成菜单的运行代码,包括上下翻,进入下级菜单,回退至上一级菜单,这些都是软件自动生成的

每个菜单选项开放一个可重载消息函数,就是点击菜单选项时,会执行一个功能函数,这个函数需要自己重载或者默认NULL

出10入23汤圆

 楼主| 发表于 2017-3-9 21:33:42 | 显示全部楼层
lansen0815 发表于 2017-3-9 21:28
嗯哈  楼主的思路很好 ,很方便

这个菜单代码功能虽然简陋,但是写起来确实非常快,搭建一个菜单程序也就半小时的事

出0入0汤圆

发表于 2017-3-9 21:33:54 | 显示全部楼层
谢谢楼主分享。学习了

出10入23汤圆

 楼主| 发表于 2017-3-9 21:49:39 | 显示全部楼层
randyzzy 发表于 2017-3-9 21:22
是否自动生成菜单代码?能不能搞个详细的说明啊?谢谢

1)先按照需要的菜单结构编辑“menu_test.xml”文件,具体格式你参照现有的“menu_test.xml”内容估计可以看出来,很简单的;
2)运行“自动生成C代码.bat”,生成一个main.c文件
3)编译main.c,得到一个exe文件,这就是这个菜单的模拟器;
4)main.c重写main函数按键处理部分和void update_screen(const int8_t* buffer) lcd显示函数,就可以移植到单片机上运行

出10入23汤圆

 楼主| 发表于 2017-3-9 21:50:00 | 显示全部楼层
zhuyi25762 发表于 2017-3-9 20:55
不会用,为自己智商捉急

1)先按照需要的菜单结构编辑“menu_test.xml”文件,具体格式你参照现有的“menu_test.xml”内容估计可以看出来,很简单的;
2)运行“自动生成C代码.bat”,生成一个main.c文件
3)编译main.c,得到一个exe文件,这就是这个菜单的模拟器;
4)main.c重写main函数按键处理部分和void update_screen(const int8_t* buffer) lcd显示函数,就可以移植到单片机上运行

出0入8汤圆

发表于 2017-3-9 21:59:39 | 显示全部楼层
楼主分享精神可嘉

出10入23汤圆

 楼主| 发表于 2017-3-9 22:14:09 | 显示全部楼层
V1.1再更新一次,相比上一次可以节省一些ROM空间

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?注册

x

出20入0汤圆

发表于 2017-3-9 22:46:10 | 显示全部楼层
谢谢楼主分享,很有用,以后也开发一些小工具。

出10入23汤圆

 楼主| 发表于 2017-3-9 23:07:11 来自手机 | 显示全部楼层
talkingbeast 发表于 2017-3-9 22:46
谢谢楼主分享,很有用,以后也开发一些小工具。

能用到的就是好东西

出0入0汤圆

发表于 2017-3-9 23:14:08 | 显示全部楼层
牛人,点个赞都不够

出130入0汤圆

发表于 2017-3-9 23:43:16 | 显示全部楼层
怒赞一个...

出0入0汤圆

发表于 2017-3-10 00:05:10 | 显示全部楼层
咱也点个赞,呵呵。

出0入0汤圆

发表于 2017-3-10 00:17:28 来自手机 | 显示全部楼层
赞一个,学习

出0入0汤圆

发表于 2017-3-10 00:23:56 来自手机 | 显示全部楼层
赞一下,好东西

出50入0汤圆

发表于 2017-3-10 00:30:51 来自手机 | 显示全部楼层
标记下,学习中

出0入0汤圆

发表于 2017-3-10 02:28:51 | 显示全部楼层
学习下 谢谢

出5入0汤圆

发表于 2017-3-10 06:07:21 来自手机 | 显示全部楼层
标记一下         

出0入0汤圆

发表于 2017-3-10 06:25:34 来自手机 | 显示全部楼层
学习一下,多谢分享。

出0入0汤圆

发表于 2017-3-10 06:40:01 | 显示全部楼层
顶“zouzhichao”。

出0入0汤圆

发表于 2017-3-10 07:57:13 | 显示全部楼层
赞一下,好东西

出0入0汤圆

发表于 2017-3-10 08:15:00 来自手机 | 显示全部楼层
不错,有时间玩玩

出0入0汤圆

发表于 2017-3-10 08:26:44 | 显示全部楼层
必须要赞啊!

出10入23汤圆

 楼主| 发表于 2017-3-10 08:28:37 来自手机 | 显示全部楼层
上班了,冒个泡

出0入10汤圆

发表于 2017-3-10 08:28:49 | 显示全部楼层
一大早有幸看到,谢谢楼主分享!

出10入23汤圆

 楼主| 发表于 2017-3-10 08:35:43 来自手机 | 显示全部楼层
有哪位兄弟可以帮忙出一个pdf版本的使用教程不?

出0入0汤圆

发表于 2017-3-10 09:08:24 | 显示全部楼层
MARK这样写菜单非常有用

出0入0汤圆

发表于 2017-3-10 09:50:12 | 显示全部楼层
学习一下,多谢分享。

出0入0汤圆

发表于 2017-3-10 10:10:56 | 显示全部楼层
谢谢分享!

出0入0汤圆

发表于 2017-3-10 10:31:55 | 显示全部楼层
这个必须支持打赏

出0入0汤圆

发表于 2017-3-10 10:41:55 | 显示全部楼层
暂时用不到,点赞。。

出0入0汤圆

发表于 2017-3-10 10:46:49 | 显示全部楼层
菜单生成,收藏了

出0入0汤圆

发表于 2017-3-10 11:09:57 | 显示全部楼层
路过,进入顶一下

出0入0汤圆

发表于 2017-3-10 12:04:23 | 显示全部楼层
谢谢楼主分享! 收藏了

出140入158汤圆

发表于 2017-3-10 12:10:28 | 显示全部楼层
也够折腾的,黑白屏菜单实在太简单,前期规划好,封装成结构体,后期维护则非常简单,不用这么折腾。同理,彩屏带图标菜单什么的,也是一样而已。

出0入0汤圆

发表于 2017-3-10 12:11:32 | 显示全部楼层
好东西,收藏

出0入0汤圆

发表于 2017-3-10 12:13:50 | 显示全部楼层
顶楼主一下

出0入0汤圆

发表于 2017-3-10 12:53:03 | 显示全部楼层
收藏了,多谢楼主。看下有机会用的上吗

出0入0汤圆

发表于 2017-3-10 12:55:59 | 显示全部楼层
收藏,谢谢楼主

出100入85汤圆

发表于 2017-3-10 21:39:29 | 显示全部楼层
不如把menucreator 代码一起共享出来给大家玩下

出10入23汤圆

 楼主| 发表于 2017-3-10 21:46:14 | 显示全部楼层
V1.1再更新一个版本吧,再省点ROM,扩大了一下可处理菜单项(最多处理8192个菜单项,最多1024级)

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?注册

x

出10入23汤圆

 楼主| 发表于 2017-3-10 21:48:22 | 显示全部楼层
whatcanitbe 发表于 2017-3-10 21:39
不如把menucreator 代码一起共享出来给大家玩下

menucreator的源码太乱了,可读性比它生产的c文件格式乱太多了

出10入23汤圆

 楼主| 发表于 2017-3-10 21:51:52 | 显示全部楼层
whatcanitbe 发表于 2017-3-10 21:39
不如把menucreator 代码一起共享出来给大家玩下

既然你有意,贴一段flex代码吧

  1. %{
  2. #include <string.h>
  3. #include "menu_create.tab.h"

  4. #define YY_SKIP_YYWRAP

  5. char buffer[1024];
  6. extern char* yylval;
  7. int yylex(void);
  8. %}

  9. menu_beg "<menu>"
  10. menu_end "</menu>"
  11. item_beg "<item>"
  12. item_end "</item>"
  13. item_para "<item_para"
  14. item_type "item_type"
  15. item_name "item_name"
  16. is_item_checked "is_item_checked"
  17. func_onclick "func_onclick"
  18. value """[^"]*"""
  19. ws [ \t\n]+
  20. %%

  21. {menu_beg} {
  22.         return MENU_BEG;
  23. }

  24. {menu_end} {
  25.         return MENU_END;
  26. }

  27. {item_beg} {
  28.         return ITEM_BEG;
  29. }

  30. {item_end} {
  31.         return ITEM_END;
  32. }

  33. {item_para} {
  34.         return ITEM_PARA;
  35. }

  36. {item_type} {
  37.         return ITEM_TYPE;
  38. }

  39. {item_name} {
  40.         return ITEM_NAME;
  41. }

  42. {is_item_checked} {
  43.         return IS_ITEM_CHECKED;
  44. }

  45. {func_onclick} {
  46.         return FUNC_ONCLICK;
  47. }

  48. {value} {
  49.         strcpy((char*)buffer, yytext);
  50.         yylval = (char*)buffer;
  51.         return VALUE;
  52. }

  53. {ws} {
  54.         //printf("space!\n");
  55. }

  56. . {
  57.         //printf("other!\n");
  58. }
  59. %%
复制代码

出0入0汤圆

发表于 2017-3-11 09:50:25 | 显示全部楼层
谢谢,收藏备用

出10入23汤圆

 楼主| 发表于 2017-3-11 15:25:44 来自手机 | 显示全部楼层
落叶随风 发表于 2017-3-9 14:29
感谢分享,这确实方便不少,菜单框架确定了以后,最麻烦的就是改菜单内容了,有这小工具,事半功倍 ...

预告一下,今晚将有重要更新:
1>将支持include,编辑长菜单体验将大幅提升
2>支持菜单自动整理,类似于c语言格式自动整理工具astyle

出0入0汤圆

发表于 2017-3-11 15:33:18 | 显示全部楼层
谢谢,热切关注

出0入0汤圆

发表于 2017-3-11 15:38:12 | 显示全部楼层
very good  继续热切关注

出0入0汤圆

发表于 2017-3-11 22:20:01 | 显示全部楼层
收藏学习

出0入0汤圆

发表于 2017-3-11 22:52:49 | 显示全部楼层
谢谢,收藏备用

出0入0汤圆

发表于 2017-3-12 11:02:05 来自手机 | 显示全部楼层
收藏 学习!

出0入0汤圆

发表于 2017-3-12 21:00:41 | 显示全部楼层
zouzhichao 发表于 2017-3-11 15:25
预告一下,今晚将有重要更新:
1>将支持include,编辑长菜单体验将大幅提升
2>支持菜单自动整理,类似于c ...

赞,楼主一直在升级啊,我得再深入了解一下

出0入0汤圆

发表于 2017-3-12 21:03:03 | 显示全部楼层
赞一个,学习一下

出0入0汤圆

发表于 2017-3-12 21:04:30 | 显示全部楼层
感谢楼主提供的精品,实验了一下很不错。找个时间深究下代码。

出0入0汤圆

发表于 2017-3-12 21:17:09 | 显示全部楼层
谢谢,收藏备用

出10入23汤圆

 楼主| 发表于 2017-3-12 21:25:46 来自手机 | 显示全部楼层
Ray______ 发表于 2017-3-12 21:04
感谢楼主提供的精品,实验了一下很不错。找个时间深究下代码。

用户体验如何?

出10入23汤圆

 楼主| 发表于 2017-3-12 21:35:15 | 显示全部楼层
2017作品系列(一)(续):省力到没有朋友的文本菜单神器

出10入23汤圆

 楼主| 发表于 2017-3-12 21:35:54 | 显示全部楼层
落叶随风 发表于 2017-3-12 21:00
赞,楼主一直在升级啊,我得再深入了解一下

http://www.amobbs.com/thread-5670258-1-1.html

出10入23汤圆

 楼主| 发表于 2017-3-12 21:38:27 | 显示全部楼层

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?注册

x

出10入23汤圆

 楼主| 发表于 2017-3-12 21:49:42 | 显示全部楼层
Ray______ 发表于 2017-3-12 21:04
感谢楼主提供的精品,实验了一下很不错。找个时间深究下代码。

新版本支持#include,用户体验提升很大

出0入0汤圆

发表于 2017-3-13 10:44:14 | 显示全部楼层
楼主威武

出0入0汤圆

发表于 2017-3-13 10:48:35 | 显示全部楼层
。膜拜大神。菜单生成备用

出0入0汤圆

发表于 2017-3-13 23:09:18 | 显示全部楼层

仅在C-FREE上体验了,感觉挺好的。目测应该可以很轻易就做到BOOT的交互上或者是液晶显示上。
菜单的内容也很有参考价值,恰好内容也与公司产品类似。
给赞

出10入23汤圆

 楼主| 发表于 2017-3-14 22:15:17 | 显示全部楼层
Ray______ 发表于 2017-3-13 23:09
仅在C-FREE上体验了,感觉挺好的。目测应该可以很轻易就做到BOOT的交互上或者是液晶显示上。
菜单的内容 ...

移植应该是很简单的,只有两个函数需要重建

出10入23汤圆

 楼主| 发表于 2017-3-14 22:34:34 | 显示全部楼层
Ray______ 发表于 2017-3-13 23:09
仅在C-FREE上体验了,感觉挺好的。目测应该可以很轻易就做到BOOT的交互上或者是液晶显示上。
菜单的内容 ...

2017作品系列(一)(续):省力到没有朋友的文本菜单神器

更新:
支持#include功能
支持代码自动整理

34楼贴出了用户指南

出0入18汤圆

发表于 2017-3-14 22:59:44 来自手机 | 显示全部楼层
好东西  得空试试

出5入4汤圆

发表于 2017-3-15 18:33:00 | 显示全部楼层
收藏下,谢谢楼主

出0入0汤圆

发表于 2017-3-16 00:34:11 | 显示全部楼层
不错,支持一下!

出100入101汤圆

发表于 2017-3-16 05:55:22 | 显示全部楼层
LZ大牛!

出10入23汤圆

 楼主| 发表于 2017-3-16 08:17:28 来自手机 | 显示全部楼层
fengyunyu 发表于 2017-3-16 05:55
LZ大牛!

你起得真早。。。。

出0入0汤圆

发表于 2017-3-16 08:24:18 | 显示全部楼层
谢谢楼主分享,收藏

出0入0汤圆

发表于 2017-3-16 08:42:51 | 显示全部楼层
支持!!!!!!!!!!!!!!!!!!!!!!!!!!

出0入0汤圆

发表于 2017-3-16 11:36:06 | 显示全部楼层
太牛了~支持~~

出0入0汤圆

发表于 2017-3-16 11:47:21 | 显示全部楼层
非常感谢分享,学习。gui是我的短板
回帖提示: 反政府言论将被立即封锁ID 在按“提交”前,请自问一下:我这样表达会给举报吗,会给自己惹麻烦吗? 另外:尽量不要使用Mark、顶等没有意义的回复。不得大量使用大字体和彩色字。【本论坛不允许直接上传手机拍摄图片,浪费大家下载带宽和论坛服务器空间,请压缩后(图片小于1兆)才上传。压缩方法可以在微信里面发给自己(不要勾选“原图),然后下载,就能得到压缩后的图片】。另外,手机版只能上传图片,要上传附件需要切换到电脑版(不需要使用电脑,手机上切换到电脑版就行,页面底部)。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

手机版|Archiver|amobbs.com 阿莫电子技术论坛 ( 粤ICP备2022115958号, 版权所有:东莞阿莫电子贸易商行 创办于2004年 (公安交互式论坛备案:44190002001997 ) )

GMT+8, 2024-4-20 01:48

© Since 2004 www.amobbs.com, 原www.ourdev.cn, 原www.ouravr.com

快速回复 返回顶部 返回列表