C language design learning, teach you how to objectize the LCD menu

This is a small series in the series of articles "C Language Embedded System Programming Practice" written by me when I was a graduate student 13 years ago. It is an example of object-oriented, object-oriented LCD menu. The original source of the article:

Http://soft.yesky.com/lesson/188/2023188.shtml

  The menu operation has been the result of numerous brainstorming problems. In this section, we will see that even in the C language, even with a little bit of object-oriented thinking, the software structure will change! I used to be an idiot, and I was fainted by the menu, giving a system like this:

It is required to switch the menu focus with the "← →" key on the keyboard . When the user is in focus on a certain menu, if the OK and CANCEL keys on the keyboard are hit, the processing function corresponding to the focus menu is called. I used to do this stupidly:

/* Press the OK button */void onOkKey(){ /* to determine which focus menu to press the Ok button, call the corresponding handler function */ Switch(currentFocus) { case MENU1: menu1OnOk(); break; case MENU2: menu2OnOk (); break; ... }}/* Press the Cancel button */void onCancelKey(){ /* to determine which focus menu to press the Cancel button, call the corresponding handler function */ Switch(currentFocus) { case MENU1: menu1OnCancel( ); break; case MENU2: menu2OnCancel(); break; ... }}

Finally one day, I did this:

/* "package" the menu's properties and operations together */typedef struct tagSysMenu{ char *text; /* menu text */ BYTE xPos; /* menu x coordinate on LCD */ BYTE yPos; /* menu y coordinate on the LCD*/ void (*onOkFun)(); /* Press the ok function pointer on the menu */ void (*onCancelFun)(); /* Press the cancel button on the menu Processing function pointer */}SysMenu, *LPSysMenu;

When I define a menu, I only need this:

Static SysMenu menu[MENU_NUM] ={ { "menu1", 0, 48, menu1OnOk, menu1OnCancel } , { " menu2", 7, 48, menu2OnOk, menu2OnCancel } , { " menu3", 7, 48, menu3OnOk, menu3OnCancel } , { " menu4", 7, 48, menu4OnOk, menu4OnCancel } ...};

The processing of the OK button and the CANCEL button becomes:

/* Press OK*/void onOkKey(){ menu[currentFocusMenu].onOkFun(); }/* Press Cancel*/void onCancelKey(){ menu[currentFocusMenu].onCancelFun();

The program has been greatly simplified, and it has begun to have good scalability! We only use the encapsulation idea in object-oriented, so that the program structure is clear, the result is that almost more menus can be added to the system without modifying the program, and the system's key processing functions remain unchanged.
Object-oriented, true God!


USB Cables

USB cables come in different shapes and sizes despite the fact a lot of them do the same things. In this short and handy guide, we`ll take a look at all the different types of USB cables available on the market and give you some examples of where you might find them in use.

USB Type-A, USB Type-B, Mini-USB, Micro-USB, USB-C

USB Cable,usb cable types,usb cable extension

ETOP WIREHARNESS LIMITED , https://www.oemmoldedcables.com