| Line No. | Rev | Author | Line |
|---|---|---|---|
| 1 | 32 | kaklik | /***************************************************************************** |
| 2 | * Module for Microchip Graphics Library |
||
| 3 | * GOL Layer |
||
| 4 | * Round Dial |
||
| 5 | ***************************************************************************** |
||
| 6 | * FileName: RoundDial.h |
||
| 7 | * Dependencies: None |
||
| 8 | * Processor: PIC24F, PIC24H, dsPIC, PIC32 |
||
| 9 | * Compiler: MPLAB C30 V3.00, MPLAB C32 |
||
| 10 | * Linker: MPLAB LINK30, MPLAB LINK32 |
||
| 11 | * Company: Microchip Technology Incorporated |
||
| 12 | * |
||
| 13 | * Software License Agreement |
||
| 14 | * |
||
| 15 | * Copyright © 2008 Microchip Technology Inc. All rights reserved. |
||
| 16 | * Microchip licenses to you the right to use, modify, copy and distribute |
||
| 17 | * Software only when embedded on a Microchip microcontroller or digital |
||
| 18 | * signal controller, which is integrated into your product or third party |
||
| 19 | * product (pursuant to the sublicense terms in the accompanying license |
||
| 20 | * agreement). |
||
| 21 | * |
||
| 22 | * You should refer to the license agreement accompanying this Software |
||
| 23 | * for additional information regarding your rights and obligations. |
||
| 24 | * |
||
| 25 | * SOFTWARE AND DOCUMENTATION ARE PROVIDED AS IS WITHOUT WARRANTY OF ANY |
||
| 26 | * KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION, ANY WARRANTY |
||
| 27 | * OF MERCHANTABILITY, TITLE, NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR |
||
| 28 | * PURPOSE. IN NO EVENT SHALL MICROCHIP OR ITS LICENSORS BE LIABLE OR |
||
| 29 | * OBLIGATED UNDER CONTRACT, NEGLIGENCE, STRICT LIABILITY, CONTRIBUTION, |
||
| 30 | * BREACH OF WARRANTY, OR OTHER LEGAL EQUITABLE THEORY ANY DIRECT OR INDIRECT |
||
| 31 | * DAMAGES OR EXPENSES INCLUDING BUT NOT LIMITED TO ANY INCIDENTAL, SPECIAL, |
||
| 32 | * INDIRECT, PUNITIVE OR CONSEQUENTIAL DAMAGES, LOST PROFITS OR LOST DATA, |
||
| 33 | * COST OF PROCUREMENT OF SUBSTITUTE GOODS, TECHNOLOGY, SERVICES, OR ANY |
||
| 34 | * CLAIMS BY THIRD PARTIES (INCLUDING BUT NOT LIMITED TO ANY DEFENSE THEREOF), |
||
| 35 | * OR OTHER SIMILAR COSTS. |
||
| 36 | * |
||
| 37 | * Author Date Comment |
||
| 38 | *~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
||
| 39 | * PAT 11/12/07 Version 1.0 release |
||
| 40 | * Pradeep Budagutta 03 Dec 2009 Added Object Header for Double Buffering Support |
||
| 41 | *****************************************************************************************/ |
||
| 42 | #ifndef _ROUNDDIAL_H |
||
| 43 | #define _ROUNDDIAL_H |
||
| 44 | |||
| 45 | /********************************************************************* |
||
| 46 | * Object States Definition: |
||
| 47 | *********************************************************************/ |
||
| 48 | #define RDIA_DISABLED 0x0002 // Bit for disabled state. |
||
| 49 | #define RDIA_ROT_CW 0x0004 // Bit for rotate clockwise state. |
||
| 50 | #define RDIA_ROT_CCW 0x0008 // Bit for rotate counter clockwise state. |
||
| 51 | #define RDIA_DRAW 0x4000 // Bit to indicate object must be redrawn. |
||
| 52 | #define RDIA_HIDE 0x8000 // Bit to indicate object must be removed from screen. |
||
| 53 | #ifdef USE_KEYBOARD |
||
| 54 | #define RDIA_QUADRANT_POSITIONS 6 |
||
| 55 | extern SHORT _cosine[RDIA_QUADRANT_POSITIONS]; |
||
| 56 | SHORT RdiaCosine(SHORT v); |
||
| 57 | SHORT RdiaSine(SHORT v); |
||
| 58 | #endif |
||
| 59 | |||
| 60 | /********************************************************************* |
||
| 61 | * Overview: Defines the parameters required for a dial Object. |
||
| 62 | * The curr_xPos, curr_yPos, new_xPos and new_yPos parameters |
||
| 63 | * are internally generated to aid in the redrawing of the |
||
| 64 | * dial. User must avoid modifying these values. |
||
| 65 | * |
||
| 66 | *********************************************************************/ |
||
| 67 | typedef struct |
||
| 68 | { |
||
| 69 | OBJ_HEADER hdr; // Generic header for all Objects (see OBJ_HEADER). |
||
| 70 | SHORT xCenter; // x coordinate center position. |
||
| 71 | SHORT yCenter; // y coordinate center position. |
||
| 72 | SHORT radius; // Radius of the dial. |
||
| 73 | SHORT value; // Initial value of the dial. |
||
| 74 | WORD max; // Maximum value of variable value (maximum = 65535). |
||
| 75 | |||
| 76 | // Minimum is always zero. |
||
| 77 | WORD res; // Resolution of movement. |
||
| 78 | SHORT curr_xPos; // Current x position. |
||
| 79 | SHORT curr_yPos; // Current y position. |
||
| 80 | SHORT new_xPos; // New x position. |
||
| 81 | SHORT new_yPos; // New y position. |
||
| 82 | } ROUNDDIAL; |
||
| 83 | |||
| 84 | /********************************************************************* |
||
| 85 | * Function: ROUNDDIAL *RdiaCreate( WORD ID, SHORT x, SHORT y, SHORT radius, |
||
| 86 | * WORD state, SHORT res, SHORT value, SHORT max, |
||
| 87 | * GOL_SCHEME *pScheme); |
||
| 88 | * |
||
| 89 | * Overview: This function creates a ROUNDDIAL object with the parameters given. |
||
| 90 | * It automatically attaches the new object into a global linked list of |
||
| 91 | * objects and returns the address of the object. |
||
| 92 | * |
||
| 93 | * PreCondition: none |
||
| 94 | * |
||
| 95 | * Input: ID - Unique user defined ID for the object instance. |
||
| 96 | * x - Location of the center of the dial in the x coordinate. |
||
| 97 | * y - Location of the center of the dial in the y coordinate. |
||
| 98 | * radius - Defines the radius of the dial. |
||
| 99 | * state - Sets the initial state of the object. |
||
| 100 | * res - Sets the resolution of the dial when rotating clockwise or |
||
| 101 | * counter clockwise. |
||
| 102 | * value - Sets the initial value of the dial. |
||
| 103 | * max - Sets the maximum value of the dial. |
||
| 104 | * pScheme - Pointer to the style scheme used. |
||
| 105 | * |
||
| 106 | * Output: Returns the pointer to the object created. |
||
| 107 | * |
||
| 108 | * Example: |
||
| 109 | * <CODE> |
||
| 110 | * GOL_SCHEME *pScheme; |
||
| 111 | * ROUNDDIAL *pDial; |
||
| 112 | * WORD state; |
||
| 113 | * |
||
| 114 | * pScheme = GOLCreateScheme(); |
||
| 115 | * state = RDIA_DRAW; |
||
| 116 | * |
||
| 117 | * // creates a dial at (50,50) x,y location, with an initial value |
||
| 118 | * // of 50, a resolution of 2 and maximum value of 100. |
||
| 119 | * pDial = RdiaCreate(1,50,50,25,118,0, state, 2, 50, 100, pScheme); |
||
| 120 | * // check if dial was created |
||
| 121 | * if (pDial == NULL) |
||
| 122 | * return 0; |
||
| 123 | * |
||
| 124 | * return 1; |
||
| 125 | * </CODE> |
||
| 126 | * |
||
| 127 | * Side Effects: none |
||
| 128 | * |
||
| 129 | ********************************************************************/ |
||
| 130 | ROUNDDIAL *RdiaCreate |
||
| 131 | ( |
||
| 132 | WORD ID, |
||
| 133 | SHORT x, |
||
| 134 | SHORT y, |
||
| 135 | SHORT radius, |
||
| 136 | WORD state, |
||
| 137 | SHORT res, |
||
| 138 | SHORT value, |
||
| 139 | SHORT max, |
||
| 140 | GOL_SCHEME *pScheme |
||
| 141 | ); |
||
| 142 | |||
| 143 | /********************************************************************* |
||
| 144 | * Function: RdiaTranslateMsg(ROUNDDIAL *pDia, GOL_MSG *pMsg) |
||
| 145 | * |
||
| 146 | * Overview: This function evaluates the message from a user if the |
||
| 147 | * message will affect the object or not. The table below enumerates the translated |
||
| 148 | * messages for each event of the touch screen inputs. |
||
| 149 | * |
||
| 150 | * <TABLE> |
||
| 151 | * Translated Message Input Source Events Description |
||
| 152 | * ##################### ############ ###### ########### |
||
| 153 | * RD_MSG_CLOCKWISE Touch Screen EVENT_MOVE If events occurs and the x,y position falls in the face of the Dial and moving in the clockwise rotation. |
||
| 154 | * RD_MSG_CTR_CLOCKWISE Touch Screen EVENT_MOVE If events occurs and the x,y position falls in the face of the Dial and moving in the counter clockwise rotation. |
||
| 155 | * OBJ_MSG_INVALID Any Any If the message did not affect the object. |
||
| 156 | * </TABLE> |
||
| 157 | * |
||
| 158 | * PreCondition: none |
||
| 159 | * |
||
| 160 | * Input: pDia - The pointer to the object where the message will be |
||
| 161 | * evaluated to check if the message will affect the object. |
||
| 162 | * pMsg - Pointer to the message struct containing the message from |
||
| 163 | * the user interface. |
||
| 164 | * |
||
| 165 | * Output: Returns the translated message depending on the received GOL message: |
||
| 166 | * - RD_MSG_CLOCKWISE Dial is moved in a clockwise direction. |
||
| 167 | * - RD_MSG_CTR_CLOCKWISE Dial is moved in a counter clockwise direction. |
||
| 168 | * - OBJ_MSG_INVALID Dial is not affected |
||
| 169 | * |
||
| 170 | * Example: |
||
| 171 | * <CODE> |
||
| 172 | * void MyGOLMsg(GOL_MSG *pMsg){ |
||
| 173 | * |
||
| 174 | * OBJ_HEADER *pCurrentObj; |
||
| 175 | * WORD objMsg; |
||
| 176 | * |
||
| 177 | * if(pMsg->event == EVENT_INVALID) |
||
| 178 | * return; |
||
| 179 | * pCurrentObj = GOLGetList(); |
||
| 180 | * |
||
| 181 | * while(pCurrentObj != NULL){ |
||
| 182 | * // Process only ROUNDDIAL |
||
| 183 | * if(!IsObjUpdated(pCurrentObj)){ |
||
| 184 | * switch(pCurrentObj->type){ |
||
| 185 | * case OBJ_ROUNDIAL: |
||
| 186 | * objMsg = RdiaTranslateMsg((ROUNDDIAL*)pCurrentObj, pMsg); |
||
| 187 | * if(objMsg == OBJ_MSG_INVALID) |
||
| 188 | * break; |
||
| 189 | * if(GOLMsgCallback(objMsg,pCurrentObj,pMsg)) |
||
| 190 | * RdiaMsgDefault(objMsg,(ROUNDDIAL*)pCurrentObj); |
||
| 191 | * break; |
||
| 192 | * default: break; |
||
| 193 | * } |
||
| 194 | * } |
||
| 195 | * } |
||
| 196 | * pCurrentObj = pCurrentObj->pNxtObj; |
||
| 197 | * } |
||
| 198 | * </CODE> |
||
| 199 | * |
||
| 200 | * Side Effects: none |
||
| 201 | * |
||
| 202 | ********************************************************************/ |
||
| 203 | WORD RdiaTranslateMsg(ROUNDDIAL *pDia, GOL_MSG *pMsg); |
||
| 204 | |||
| 205 | /********************************************************************* |
||
| 206 | * Function: RdiaMsgDefault(WORD translatedMsg, ROUNDDIAL *pDia, GOL_MSG* pMsg) |
||
| 207 | * |
||
| 208 | * Overview: This function performs the actual state change |
||
| 209 | * based on the translated message given. The following state changes |
||
| 210 | * are supported: |
||
| 211 | * <TABLE> |
||
| 212 | * Translated Message Input Source Set/Clear State Bit Description |
||
| 213 | * ################## ############ ###### ########### |
||
| 214 | * RD_MSG_CLOCKWISE Touch Screen Set RDIA_ROT_CW, Dial will be redrawn with clockwise update. |
||
| 215 | * Set RDIA_DRAW |
||
| 216 | * RD_MSG_CTR_CLOCKWISE Touch Screen Set RDIA_ROT_CCW, Dial will be redrawn with counter clockwise update. |
||
| 217 | * Set RDIA_DRAW |
||
| 218 | * </TABLE> |
||
| 219 | * |
||
| 220 | * PreCondition: none |
||
| 221 | * |
||
| 222 | * Input: translatedMsg - The translated message |
||
| 223 | * pDia - The pointer to the object whose state will be modified |
||
| 224 | * pMsg - The pointer to the GOL message |
||
| 225 | * |
||
| 226 | * Output: none |
||
| 227 | * |
||
| 228 | * Example: |
||
| 229 | * See RdiaTranslateMsg() example. |
||
| 230 | * |
||
| 231 | * Side Effects: none |
||
| 232 | * |
||
| 233 | ********************************************************************/ |
||
| 234 | void RdiaMsgDefault(WORD translatedMsg, ROUNDDIAL *pDia, GOL_MSG *pMsg); |
||
| 235 | |||
| 236 | /********************************************************************* |
||
| 237 | * Macros: RdiaGetVal(pDia) |
||
| 238 | * |
||
| 239 | * Overview: Returns the current dial value. Value is always |
||
| 240 | * in the 0-max range inclusive. |
||
| 241 | * |
||
| 242 | * PreCondition: none |
||
| 243 | * |
||
| 244 | * Input: pDia - Pointer to the object. |
||
| 245 | * |
||
| 246 | * Output: Returns the current value of the dial. |
||
| 247 | * |
||
| 248 | * Example: |
||
| 249 | * <CODE> |
||
| 250 | * WORD currVal; |
||
| 251 | * ROUNDDIAL *pDia; |
||
| 252 | * |
||
| 253 | * // assuming pDia is initialized to an existing dial Object |
||
| 254 | * currVal = RdiaGetVal(pDia); |
||
| 255 | * </CODE> |
||
| 256 | * |
||
| 257 | * Side Effects: none |
||
| 258 | * |
||
| 259 | ********************************************************************/ |
||
| 260 | #define RdiaGetVal(pDia) (pDia)->value |
||
| 261 | |||
| 262 | /********************************************************************* |
||
| 263 | * Macros: RdiaSetVal(pDia, newVal) |
||
| 264 | * |
||
| 265 | * Overview: Sets the value to the given new value. Value set must be in 0-max |
||
| 266 | * range inclusive. |
||
| 267 | * |
||
| 268 | * PreCondition: none |
||
| 269 | * |
||
| 270 | * Input: pDia - Pointer to the object. |
||
| 271 | * newVal - New dial value. |
||
| 272 | * |
||
| 273 | * Output: none |
||
| 274 | * |
||
| 275 | * Example: |
||
| 276 | * <CODE> |
||
| 277 | * WORD updatedVal; |
||
| 278 | * ROUNDDIAL *pDia; |
||
| 279 | * |
||
| 280 | * // assuming pDia is initialized to an existing dial Object |
||
| 281 | * // assume GetInput() is a function that retrieves source data |
||
| 282 | * updatedVal = GetInput(); |
||
| 283 | * RdiaSetVal(pDia, updatedVal); |
||
| 284 | * </CODE> |
||
| 285 | * |
||
| 286 | * Side Effects: none |
||
| 287 | * |
||
| 288 | ********************************************************************/ |
||
| 289 | #define RdiaSetVal(pDia, newVal) (pDia)->value = newVal |
||
| 290 | |||
| 291 | /********************************************************************* |
||
| 292 | * Macros: RdiaIncVal(pDia) |
||
| 293 | * |
||
| 294 | * Overview: Used to directly increment the value. The delta |
||
| 295 | * change used is the resolution setting (res). |
||
| 296 | * |
||
| 297 | * PreCondition: none |
||
| 298 | * |
||
| 299 | * Input: pDia - Pointer to the object. |
||
| 300 | * |
||
| 301 | * Output: none |
||
| 302 | * |
||
| 303 | * Example: |
||
| 304 | * <CODE> |
||
| 305 | * WORD updatedVal, prevVal; |
||
| 306 | * ROUNDDIAL *pDia; |
||
| 307 | * |
||
| 308 | * // assuming pDia is initialized to an existing dial Object |
||
| 309 | * // assume GetInput() is a function that retrieves source data |
||
| 310 | * prevVal = RdiaGetVal(pDia); |
||
| 311 | * updatedVal = GetInput(); |
||
| 312 | * if (updatedVal > prevVal) |
||
| 313 | * RdiaIncVal(pDia); |
||
| 314 | * if (updatedVal < prevVal) |
||
| 315 | * RdiaDecVal(pDia); |
||
| 316 | * </CODE> |
||
| 317 | * |
||
| 318 | * Side Effects: none |
||
| 319 | * |
||
| 320 | ********************************************************************/ |
||
| 321 | #define RdiaIncVal(pDia) RdiaSetVal(pDia, (pDia->val + pDia->res)) |
||
| 322 | |||
| 323 | /********************************************************************* |
||
| 324 | * Macros: RdiaDecVal(pDia) |
||
| 325 | * |
||
| 326 | * Overview: Used to directly decrement the value. The delta |
||
| 327 | * change used is the resolution setting (res). |
||
| 328 | * |
||
| 329 | * PreCondition: none |
||
| 330 | * |
||
| 331 | * Input: pDia - Pointer to the object. |
||
| 332 | * |
||
| 333 | * Output: none |
||
| 334 | * |
||
| 335 | * Example: |
||
| 336 | * Refer to RdiaIncVal() example. |
||
| 337 | * |
||
| 338 | * Side Effects: none |
||
| 339 | * |
||
| 340 | ********************************************************************/ |
||
| 341 | #define RdiaDecVal(pDia) RdiaSetVal(pDia, (pDia->pos - pDia->res)) |
||
| 342 | |||
| 343 | /********************************************************************* |
||
| 344 | * Function: RdiaDraw(ROUNDDIAL *pDia) |
||
| 345 | * |
||
| 346 | * Overview: This function renders the object on the screen using |
||
| 347 | * the current parameter settings. Location of the object is |
||
| 348 | * determined by the center (x,y) postion and the radius parameters. |
||
| 349 | * The colors used are dependent on the state of the object. |
||
| 350 | * |
||
| 351 | * When rendering objects of the same type, each object |
||
| 352 | * must be rendered completely before the rendering of the |
||
| 353 | * next object is started. This is to avoid incomplete |
||
| 354 | * object rendering. |
||
| 355 | * |
||
| 356 | * PreCondition: Object must be created before this function is called. |
||
| 357 | * |
||
| 358 | * Input: pDia - Pointer to the object |
||
| 359 | * |
||
| 360 | * Output: Returns the status of the drawing |
||
| 361 | * - 1 - If the rendering was completed and |
||
| 362 | * - 0 - If the rendering is not yet finished. |
||
| 363 | * |
||
| 364 | * Side Effects: none |
||
| 365 | * |
||
| 366 | ********************************************************************/ |
||
| 367 | WORD RdiaDraw(ROUNDDIAL * pDia); |
||
| 368 | #endif // _ROUNDDIAL_H |
Powered by WebSVN v2.8.3