| The Datasheet Archive - 100 Million Datasheets from 7500 Manufacturers. |
Using Keyboard with Microchip Graphics Library Author: Anton Alkh
Top Searches for this datasheetAN1227 Using Keyboard with Microchip Graphics Library Author: Anton Alkhimenok Microchip Technology Inc. format graphics library message structure shown Example EXAMPLE INTRODUCTION Graphics displays widely used many applications number products with displays grows every day. primary reason that Graphical User Interface (GUI) greatly simplify device. interface display with variety input devices, such keyboards, touch screens mice. Keyboards range from devices with several side buttons those enabling text entry. cost ability quickly enter data resulting frequent keyboards. Microchip Graphics Library simplifies design keyboard-based GUI, this application note will demonstrate. more information library, AN1136, "How Widgets Microchip Graphics Library". MESSAGE STRUCTURE FORMAT type, uiEvent, param1, param2 typedef struct BYTE BYTE SHORT SHORT GOL_MSG; keyboard related definitions preceding example's fields given Table TABLE Field type MESSAGE STRUCTURE FIELDS' DEFINITIONS Description Bytes type input device. keyboard, this value must TYPE_KEYBOARD. MESSAGE INTERFACE Microchip Graphics Library supports several kinds input devices, achieving that flexibility through message interface. interface structure containing information about input device events. input device firmware part library must implemented application. application must provide event information prescribed format pass data library's message manager. rest work done library with on-screen widgets displaying state automatically. code structure message manager function shown Example uiEvent input event. keyboard kinds events: EVENT_KEYSCAN When param2 field contains scan code EVENT_KEYCODE When param2 field contains character code. param1 widget receiving message. This unique assigned application when object created. param2 scan code character code, depending value uiEvent field. EXAMPLE void MESSAGE MANAGER FUNCTION PROTOTYPE GOLMsg(GOL_MSG *pMsg) Keyboard messages standard keyboard scan codes. Most Significant scan code defines state pressed released. Frequently used scan codes graphics library widgets listed Table constants definitions codes ScanCodes.h file included graphics library. pMsg parameter pointer message structure filled input device. 2008 Microchip Technology Inc. DS01227A-page AN1227 TABLE Description Carriage Return Delete Back Space Tabulation Home Page Page Down Arrow Arrow Down Arrow Left Arrow Right Space KEYBOARD SCAN CODES Press Name Defined ScanCodes.h SCAN_CR_PRESSED SCAN_DEL_PRESSED SCAN_BS_PRESSED SCAN_TAB_PRESSED SCAN_HOME_PRESSED SCAN_END_PRESSED SCAN_PGUP_PRESSED SCAN_PGDOWN_PRESSED SCAN_UP_PRESSED SCAN_DOWN_PRESSED SCAN_LEFT_PRESSED SCAN_RIGHT_PRESSED SCAN_SPACE_PRESSED Code 0x1C 0x53 0x0E 0x0F 0x47 0x4F 0x49 0x51 0x48 0x50 0x4B 0x4D 0x39 Release Name Defined ScanCodes.h SCAN_CR_RELEASED SCAN_DEL_RELEASED SCAN_BS_RELEASED SCAN_TAB_RELEASED SCAN_HOME_RELEASED SCAN_END_RELEASED SCAN_PGUP_RELEASED SCAN_PGDOWN_RELEASED SCAN_UP_RELEASED SCAN_DOWN_RELEASED SCAN_LEFT_RELEASED SCAN_RIGHT_RELEASED SCAN_SPACE_RELEASED Code 0x9C 0xD3 0x8E 0x8F 0xC7 0xCF 0xC9 0xD1 0xC8 0xD0 0xCB 0xCD 0xB9 code keyboard message have different encoding. application must ensure that message's encoding matches used font widget receiving message. example, Edit widget ASCII encoded font, code keyboard message also must ASCII. WIDGETS KEYBOARD MESSAGES Each widget valid keyboard messages. Invalid messages result action. Some widgets such Window, Static Text, Picture, Progress Group cannot accept keyboard input. widget disabled state, ignores messages. Table summarizes keyboard messages different widgets. DS01227A-page 2008 Microchip Technology Inc. 2008 Microchip Technology Inc. DS01227A-page TABLE Widget MICROCHIP GRAPHICS LIBRARY KEYBOARD MESSAGES WIDGETS Parameter Description (param2 field message structure) Carriage return pressed scan code (SCAN_CR_PRESSED constant) Space pressed scan code (SCAN_SPACE_PRESSED constant) Carriage return released scan code (SCAN_CR_RELEASED constant) Space released scan code (SCAN_SPACE_RELEASED constant) Carriage return pressed scan code (SCAN_CR_PRESSED constant) Space pressed scan code (SCAN_SPACE_PRESSED constant) Carriage return pressed scan code (SCAN_CR_PRESSED constant) Space pressed scan code (SCAN_SPACE_PRESSED constant) Character code edit assigned application when edit created. Message from Input Device Translated Message Type Input Device Event Description Parameter Description Message Callback (the Type field message (the uiEvent field (param1 field message Function structure) message structure) structure) button pressed. (BTN_MSG_PRESSED constant) scan code event. (EVENT_KEYSCAN constant) button assigned application when button created. Button button released. (BTN_MSG_RELEASED constant) Keyboard (TYPE_KEYBOARD constant) Check check checked. (BTN_MSG_CHECKED constant) check unchecked. (BTN_MSG_ Keyboard (TYPE_KEYBOARD constant) scan code event. (EVENT_KEYSCAN constant) check assigned application when check created. UNCHECKED constant) same radio button group checked. (RB_MSG_CHECKED Keyboard constant) (TYPE_KEYBOARD constant) Radio Button scan code event. (EVENT_KEYSCAN constant) radio button group assigned application when radio button created. Edit character added edit box. (EB_MSG_CHAR constant) Keyboard (TYPE_KEYBOARD constant) last character removed from edit box. (EB_MSG_DEL constant) Character code event. (EVENT_KEYCODE constant) scan code event. (EVENT_KEYSCAN constant) AN1227 Back space pressed scan code (SCAN_BS_PRESSED constant) TABLE Widget MICROCHIP GRAPHICS LIBRARY KEYBOARD MESSAGES WIDGETS (CONTINUED) Parameter Description (param2 field message structure) DS01227A-page 2008 Microchip Technology Inc. AN1227 Message from Input Device Translated Message Type Input Device Event Description Parameter Description Message Callback (the Type field message (the uiEvent field (param1 field message Function structure) message structure) structure) Slider position incremented. (SLD_MSG_INC constant) Keyboard (TYPE_KEYBOARD constant) scan code event. (EVENT_KEYSCAN constant) Slider Slider position decremented. (SLD_MSG_DEC constant) Arrow down pressed scan code (SCAN_UP_PRESSED constant) Arrow right pressed scan code slider assigned application (SCAN_LEFT_PRESSED constant) when slider created. Arrow pressed scan code (SCAN_DOWN_PRESSED constant) Arrow left pressed scan code (SCAN_RIGHT_PRESSED constant) Arrow pressed scan code (SCAN_UP_PRESSED constant) Arrow down pressed scan code (SCAN_DOWN_PRESSED constant) Carriage return pressed scan code (SCAN_CR_PRESSED constant) Space pressed scan code (SCAN_SPACE_PRESSED constant) Current item mark moved next item. (LB_MSG_MOVE constant) scan code event. (EVENT_KEYSCAN constant) list assigned application when list created. List Current item selected. (LB_MSG_SEL constant) Keyboard (TYPE_KEYBOARD constant) Dial Group Meter Picture Progress Static Text Window Keyboard messages supported these objects. AN1227 Example shows pass button's "press" "release" events library. keyboard key, switch connected port used. switch pressed, presented this port. released state, read from this port. EXAMPLE main(void) GOL_MSG msg; PASSING BUTTON EVENTS GRAPHICS LIBRARY 1111 button unique #define BUTTON1_ID message interface structure, should filled keyboard driver passed message manager previous state BYTE previousKey1State; initialize keyboard TRISDbits.TRISD6 previousKey1State PORTDbits.RD6; GOLInit(); BtnCreate( BUTTON1_ID, 0,40, 100,90, BTN_DRAW, NULL, "Released", NULL while(1) port input previous state equals current state initialize graphics library create button widget button unique left, corner coordinates right, bottom corner corner radius zero, it's square button will dislayed after creation bitmap text released state default color scheme used if(GOLDraw()) drawing manager display widgets Keyboard driver if(PORTDbits.RD6 previousKey1State) check button changed state if(previousKey1State) equals zero means pressed msg.type TYPE_KEYBOARD; msg.uiEvent EVENT_KEYSCAN; msg.param1 BUTTON1_ID; msg.param2 SCAN_CR_PRESSED; }else{ equals means released msg.type TYPE_KEYBOARD; msg.uiEvent EVENT_KEYSCAN; msg.param1 BUTTON1_ID; msg.param2 SCAN_CR_RELEASED; else state changed previousKey1State previousKey1State; pass message graphics library GOLMsg(&msg); while return main WORD GOLMsgCallback(WORD objMsg, OBJ_HEADER* pObj, GOL_MSG* pMsg) Application should process messages here return process message default GOLMessageCallback 2008 Microchip Technology Inc. DS01227A-page AN1227 MESSAGE CALLBACK FUNCTION After library's message manager, GOLMsg(.), received message from input device, graphics library finds widgets affected active link list uses special callback function program reacts event. This function must implemented application. Example shows this function's prototype. EXAMPLE MESSAGE CALLBACK FUNCTION PROTOTYPE WORD GOLMsgCallback(WORD objMsg, OBJ_HEADER* pObj, GOL_MSG* pMsg); first parameter objMsg translated message. graphics library parses message from input device translates into form particular widget. example, keyboard sends button carriage return pressed code, library returns translated message, BUTTON PRESSED (BTN_MSG_PRESSED constant), message callback function objMsg parameter. second parameter, pObj, pointer widget affected message. third parameter, pMsg, pointer original message from input device. This information enough application perform action event. graphics library default action events each widget. (For button, library display pressed released state). callback function returns non-zero, message object will processed default. returned, library will perform default action. Example adds application code previous example processing messages button with BUTTON1_ID. This example shows code changing text face button "pressed" "released" events. GOLMsgCallback() returns enable default action button which change state from released pressed pressed released. EXAMPLE CHANGING BUTTON TEXT PRESSED RELEASED EVENTS WORD GOLMsgCallback(WORD objMsg, OBJ_HEADER* pObj, GOL_MSG* pMsg) Application should process messages here if(GetobjID(pObj) BUTTON1_ID) if(objMsg BTN_MSG_PRESSED) BtnSetText(pObj,"Pressed"); if(objMsg BTN_MSG_RELEASED) BtnSetText(pObj,"Released"); return process message default GOLMessageCallback button with BUTTON_ID receiving message text pressed state text released state DS01227A-page 2008 Microchip Technology Inc. AN1227 KEYBOARD FOCUS keyboard focus determines which widget receives information typed keyboard. Microchip Graphics Library shows which widget focus putting dashed rectangle around Focus especially useful when number widgets greater than number keyboard keys. such cases, some keys assigned navigate between controls screen. Widgets supporting keyboard cannot accept focus. allow focus, USE_FOCUS compile-time option must defined GraphicsConfig.h file. another type input device, such touch screen, used simultaneously with keyboard, second device will move keyboard focus automatically active widget. following functions available control focus. OBJ_HEADER *GOLGetFocusNext() This function returns pointer next object active list that capable receiving keyboard input. there such object, NULL returned. void GOLSetFocus (OBJ_HEADER* object) This function sets keyboard input focus object. object cannot accept keyboard messages, focus will changed. This function resets focused state object that previously focus, sets focused state required object marks objects redrawn. OBJ_HEADER *GOLGetFocus(void) This macro returns pointer object receiving keyboard input. there object focus, NULL returned. Example illustrates focus adding second third button widgets. initial state third button widget disabled such that will accept keyboard focus. second keyboard key, connected port RD13, also added move input focus between widgets current screen. WORD GOLCanBeFocused (OBJ_HEADER* object) This function returns non-zero object focused. Only button, check box, radio button, slider, edit list accept focus. object disabled, cannot focused state. EXAMPLE USING FOCUS WITH THREE BUTTON WIDGETS 1111 2222 3333 button unique button unique button unique #define BUTTON1_ID #define BUTTON2_ID #define BUTTON3_ID main(void) GOL_MSG msg; OBJ_HEADER* pFocusedObj; BYTE BYTE previousKey1State; previousKey2State; initialize keyboard's keys TRISDbits.TRISD6 previousKey1State PORTDbits.RD6; TRISDbits.TRISD13 previousKey2State PORTDbits.RD13; GOLInit(); message interface structure, should filled keyboard driver passed message manager temporary variable widget receiving keyboard focus previous state button previous state button port previous port previous input state equals current state RD13 input state equals current state initialize graphics library 2008 Microchip Technology Inc. DS01227A-page AN1227 EXAMPLE USING FOCUS WITH THREE BUTTON WIDGETS (CONTINUED) button unique left, corner coordinates right, bottom corner corner radius zero, it's square button will dislayed after creation bitmap text released state default color scheme used create button widgets BtnCreate( BUTTON1_ID, 10,40, 110,90, BTN_DRAW, NULL, "Released", NULL BtnCreate( BUTTON2_ID, 10,100, 110,150, BTN_DRAW, NULL, "Button NULL BtnCreate( BUTTON3_ID, 10,160, 110,210, BTN_DRAW|BTN_DISABLED, NULL, "Disabled", NULL pFocusedObj NULL; while(1) if(GOLDraw()) Keyboard driver if(GOLGetFocus() NULL) check button changed state if(PORTDbits.RD6 previousKey1State) if(previousKey1State) equals zero means button pressed msg.type TYPE_KEYBOARD; msg.uiEvent EVENT_KEYSCAN; focused button will receive message msg.param1 GetObjID(GOLGetFocus()); msg.param2 SCAN_CR_PRESSED; }else{ equals means button released msg.type TYPE_KEYBOARD; msg.uiEvent EVENT_KEYSCAN; focused button will receive message msg.param1 GetObjID(GOLGetFocus()); msg.param2 SCAN_CR_RELEASED; else drawing manager display widgets button unique left, corner coordinates right, bottom corner corner radius zero, it's square button will dislayed after creation bitmap text default color scheme used button unique left, corner coordinates right, bottom corner corner radius zero, it's square button will dislayed disabled after creation bitmap text default color scheme used there widgets focus there's widget focus send message DS01227A-page 2008 Microchip Technology Inc. AN1227 EXAMPLE USING FOCUS WITH THREE BUTTON WIDGETS (CONTINUED) state button changed previousKey1State previousKey1State; pass message graphics ibrary GOLMsg(&msg); continue; check button changed state if(PORTDbits.RD13 previousKey2State) if(previousKey2State) RD13 equals zero means button pressed object focused next pFocusedObj GOLGetFocusNext(); move focus GOLSetFocus(pFocusedObj); }else{ RD13 equals means button released else state button changed previousKey2State previousKey2State; pass message graphics library GOLMsg(&msg); while return main WORD GOLMsgCallback(WORD objMsg, OBJ_HEADER* pObj, GOL_MSG* pMsg) Application should process messages here if(GetobjID(pObj) BUTTON1_ID) if(objMsg BTN_MSG_PRESSED) BtnSetText(pObj,"Pressed"); if(objMsg BTN_MSG_RELEASED) BtnSetText(pObj,"Released"); return process message default GOLMessageCallback button with BUTTON_ID receiving message text pressed state text released state 2008 Microchip Technology Inc. DS01227A-page AN1227 CONCLUSION type keyboard easily integrated into application using Microchip Graphics Library. This done with message interface, widgets messages, message processing keyboard focus control. DS01227A-page 2008 Microchip Technology Inc. Note following details code protection feature Microchip devices: Microchip products meet specification contained their particular Microchip Data Sheet. Microchip believes that family products most secure families kind market today, when used intended manner under normal conditions. There dishonest possibly illegal methods used breach code protection feature. these methods, knowledge, require using Microchip products manner outside operating specifications contained Microchip's Data Sheets. Most likely, person doing engaged theft intellectual property. Microchip willing work with customer concerned about integrity their code. Neither Microchip other semiconductor manufacturer guarantee security their code. Code protection does mean that guaranteeing product "unbreakable." Code protection constantly evolving. Microchip committed continuously improving code protection features products. Attempts break Microchip's code protection feature violation Digital Millennium Copyright Act. such acts allow unauthorized access your software other copyrighted work, have right relief under that Act. Information contained this publication regarding device applications like provided only your convenience superseded updates. your responsibility ensure that your application meets with your specifications. MICROCHIP MAKES REPRESENTATIONS WARRANTIES KIND WHETHER EXPRESS IMPLIED, WRITTEN ORAL, STATUTORY OTHERWISE, RELATED INFORMATION, INCLUDING LIMITED CONDITION, QUALITY, PERFORMANCE, MERCHANTABILITY FITNESS PURPOSE. Microchip disclaims liability arising from this information use. Microchip devices life support and/or safety applications entirely buyer's risk, buyer agrees defend, indemnify hold harmless Microchip from damages, claims, suits, expenses resulting from such use. licenses conveyed, implicitly otherwise, under Microchip intellectual property rights. Trademarks Microchip name logo, Microchip logo, Accuron, dsPIC, KEELOQ, KEELOQ logo, MPLAB, PIC, PICmicro, PICSTART, rfPIC SmartShunt registered trademarks Microchip Technology Incorporated U.S.A. other countries. FilterLab, Linear Active Thermistor, MXDEV, MXLAB, SEEVAL, SmartSensor Embedded Control Solutions Company registered trademarks Microchip Technology Incorporated U.S.A. Analog-for-the-Digital Age, Application Maestro, CodeGuard, dsPICDEM, dsPICDEM.net, dsPICworks, dsSPEAK, ECAN, ECONOMONITOR, FanSense, In-Circuit Serial Programming, ICSP, ICEPIC, Mindi, MiWi, MPASM, MPLAB Certified logo, MPLIB, MPLINK, mTouch, PICkit, PICDEM, PICDEM.net, PICtail, PIC32 logo, PowerCal, PowerInfo, PowerMate, PowerTool, REAL ICE, rfLAB, Select Mode, Total Endurance, UNI/O, WiperLock ZENA trademarks Microchip Technology Incorporated U.S.A. other countries. SQTP service mark Microchip Technology Incorporated U.S.A. other trademarks mentioned herein property their respective companies. 2008, Microchip Technology Incorporated, Printed U.S.A., Rights Reserved. Printed recycled paper. Microchip received ISO/TS-16949:2002 certification worldwide headquarters, design wafer fabrication facilities Chandler Tempe, Arizona; Gresham, Oregon design centers California India. Company's quality system processes procedures PIC® MCUs dsPIC® DSCs, KEELOQ® code hopping devices, Serial EEPROMs, microperipherals, nonvolatile memory analog products. addition, Microchip's quality system design manufacture development systems 9001:2000 certified. 2008 Microchip Technology Inc. DS01227A-page WORLDWIDE SALES SERVICE AMERICAS Corporate Office 2355 West Chandler Blvd. Chandler, 85224-6199 Tel: 480-792-7200 Fax: 480-792-7277 Technical Support: http://support.microchip.com Address: www.microchip.com Atlanta Duluth, Tel: 678-957-9614 Fax: 678-957-1455 Boston Westborough, Tel: 774-760-0087 Fax: 774-760-0088 Chicago Itasca, Tel: 630-285-0071 Fax: 630-285-0075 Dallas Addison, Tel: 972-818-7423 Fax: 972-818-2924 Detroit Farmington Hills, Tel: 248-538-2250 Fax: 248-538-2260 Kokomo Kokomo, Tel: 765-864-8360 Fax: 765-864-8387 Angeles Mission Viejo, Tel: 949-462-9523 Fax: 949-462-9608 Santa Clara Santa Clara, Tel: 408-961-6444 Fax: 408-961-6445 Toronto Mississauga, Ontario, Canada Tel: 905-673-0699 Fax: 905-673-6509 ASIA/PACIFIC Asia Pacific Office Suites 3707-14, 37th Floor Tower Gateway Harbour City, Kowloon Hong Kong Tel: 852-2401-1200 Fax: 852-2401-3431 Australia Sydney Tel: 61-2-9868-6733 Fax: 61-2-9868-6755 China Beijing Tel: 86-10-8528-2100 Fax: 86-10-8528-2104 China Chengdu Tel: 86-28-8665-5511 Fax: 86-28-8665-7889 China Hong Kong Tel: 852-2401-1200 Fax: 852-2401-3431 China Nanjing Tel: 86-25-8473-2460 Fax: 86-25-8473-2470 China Qingdao Tel: 86-532-8502-7355 Fax: 86-532-8502-7205 China Shanghai Tel: 86-21-5407-5533 Fax: 86-21-5407-5066 China Shenyang Tel: 86-24-2334-2829 Fax: 86-24-2334-2393 China Shenzhen Tel: 86-755-8203-2660 Fax: 86-755-8203-1760 China Wuhan Tel: 86-27-5980-5300 Fax: 86-27-5980-5118 China Xiamen Tel: 86-592-2388138 Fax: 86-592-2388130 China Xian Tel: 86-29-8833-7252 Fax: 86-29-8833-7256 China Zhuhai Tel: 86-756-3210040 Fax: 86-756-3210049 ASIA/PACIFIC India Bangalore Tel: 91-80-4182-8400 Fax: 91-80-4182-8422 India Delhi Tel: 91-11-4160-8631 Fax: 91-11-4160-8632 India Pune Tel: 91-20-2566-1512 Fax: 91-20-2566-1513 Japan Yokohama Tel: 81-45-471- 6166 Fax: 81-45-471-6122 Korea Daegu Tel: 82-53-744-4301 Fax: 82-53-744-4302 Korea Seoul Tel: 82-2-554-7200 Fax: 82-2-558-5932 82-2-558-5934 Malaysia Kuala Lumpur Tel: 60-3-6201-9857 Fax: 60-3-6201-9859 Malaysia Penang Tel: 60-4-227-8870 Fax: 60-4-227-4068 Philippines Manila Tel: 63-2-634-9065 Fax: 63-2-634-9069 Singapore Tel: 65-6334-8870 Fax: 65-6334-8850 Taiwan Hsin Tel: 886-3-572-9526 Fax: 886-3-572-6459 Taiwan Kaohsiung Tel: 886-7-536-4818 Fax: 886-7-536-4803 Taiwan Taipei Tel: 886-2-2500-6610 Fax: 886-2-2508-0102 Thailand Bangkok Tel: 66-2-694-1351 Fax: 66-2-694-1350 EUROPE Austria Wels Tel: 43-7242-2244-39 Fax: 43-7242-2244-393 Denmark Copenhagen Tel: 45-4450-2828 Fax: 45-4485-2829 France Paris Tel: 33-1-69-53-63-20 Fax: 33-1-69-30-90-79 Germany Munich Tel: 49-89-627-144-0 Fax: 49-89-627-144-44 Italy Milan Tel: 39-0331-742611 Fax: 39-0331-466781 Netherlands Drunen Tel: 31-416-690399 Fax: 31-416-690340 Spain Madrid Tel: 34-91-708-08-90 Fax: 34-91-708-08-91 Wokingham Tel: 44-118-921-5869 Fax: 44-118-921-5820 01/02/08 DS01227A-page 2008 Microchip Technology Inc. Other recent searchesMPSA28 - MPSA28 MPSA28 Datasheet KGL4201 - KGL4201 KGL4201 Datasheet KGL4201C - KGL4201C KGL4201C Datasheet JC-13 - JC-13 JC-13 Datasheet G-12 - G-12 G-12 Datasheet IRHMS57163SE - IRHMS57163SE IRHMS57163SE Datasheet BSS79 - BSS79 BSS79 Datasheet BSS81 - BSS81 BSS81 Datasheet BSS80 - BSS80 BSS80 Datasheet BSS82 - BSS82 BSS82 Datasheet BL-FL7615xx - BL-FL7615xx BL-FL7615xx Datasheet BL-FL7615URC - BL-FL7615URC BL-FL7615URC Datasheet BL-FL7615UEC - BL-FL7615UEC BL-FL7615UEC Datasheet BL-FL7615UYC - BL-FL7615UYC BL-FL7615UYC Datasheet BL-FL7615UGC - BL-FL7615UGC BL-FL7615UGC Datasheet BL-FL7615PGC - BL-FL7615PGC BL-FL7615PGC Datasheet BL-FL7615BGC - BL-FL7615BGC BL-FL7615BGC Datasheet BL-FL7615UBC - BL-FL7615UBC BL-FL7615UBC Datasheet BL-FL7615UWC - BL-FL7615UWC BL-FL7615UWC Datasheet
Privacy Policy | Disclaimer |