/*****************************************************************************
* © 2008 PicManía By RedRaven
* http://picmania.garcia-cuervo.net
*
* FileName: Test2.c
* Dependencies: Test2.h
* Processor: PIC24FJ128GA010
* Compiler: MPLAB C30 V3.00
* Linker: MPLAB LINK30
*
* Matriz de botones numericos + función.
* Area de Textos fijos
* Area de Mensajes con lo pulsado en el KEYPAD
*****************************************************************************/
#include "Test2.h"
#include <stdio.h>
// Configuration bits
_CONFIG2(FNOSC_PRIPLL & POSCMOD_XT) // Primary XT OSC with PLL
_CONFIG1(JTAGEN_OFF & FWDTEN_OFF) // JTAG off, watchdog timer off
///////////////////////////////// FONTS ///////////////////////////////////////
extern FONT_FLASH Font25;
extern FONT_FLASH Font35;
/////////////////////////////////////////////////////////////////////////////
// OBJECT'S IDs & DIMENSIONS
/////////////////////////////////////////////////////////////////////////////
#define KEYPAD_BTN 10
#define NUMVERSPC 1
#define NUMHORBTN 4
#define NUMVERBTN 3
/////////////////////////////////////////////////////////////////////////////
// LOCAL PROTOTYPES
/////////////////////////////////////////////////////////////////////////////
void Create_Objects(void);
void CheckCalibration(void); // check if calibration is needed
/////////////////////////////////////////////////////////////////////////////
// MAIN
/////////////////////////////////////////////////////////////////////////////
GOL_SCHEME *altScheme; // alternative style scheme
WORD update = 0; // variable to update customized graphics
static char MyText[32] = "\0";
WORD nextChar = 0;
static const char BtnTexts[12][3] = {"1","2","3","Si","4","5","6","0","7","8","9","No"};
int main(void){
GOL_MSG msg; // GOL message structure to interact with GOL
EEPROMInit(); // initialize EEPROM
TouchInit(); // initialize touch screen
BeepInit(); // Initialize beeper
GOLInit(); // initialize graphics library &
// create default style scheme for GOL
SetColor(BLACK);
ClearDevice();
Create_Objects();
while(1){
if(GOLDraw()) { // Draw GOL object
TouchGetMsg(&msg); // Get message from touch screen
GOLMsg(&msg); // Process message
}
}
}
void Create_Objects(void){
static const char text[] = "Touch KEYPAD by RedPic";
unsigned int nbuttons,VerDiv,HorDiv;
unsigned int i,PosX,PosY,nHor;
SetFont(&FONTDEFAULT);
SetColor(WHITE);
MoveTo(0,0);
while(!OutText((char*) text));
altScheme = GOLCreateScheme(); // create alternative style scheme
altScheme->TextColor0 = BLACK;
altScheme->TextColor1 = WHITE;
VerDiv = (unsigned int) GetMaxY() / (NUMVERBTN + NUMVERSPC);
HorDiv = (unsigned int) GetMaxX() / NUMHORBTN;
nbuttons = NUMHORBTN * NUMVERBTN;
PosX = 0; PosY = VerDiv;
nHor = 0;
SetFont(&Font35);
for(i=0;i<nbuttons;i++){
BtnCreate(KEYPAD_BTN+i, // object’s ID
PosX, PosY, // object’s Top Left Corner
PosX+HorDiv,PosY+VerDiv,// object’s Bottom Right Corner
0, // radius of the rounded edge
BTN_DRAW, // draw the object after creation
NULL, // no bitmap used
(char*) BtnTexts[i], // use this text
altScheme); // use alternative style scheme
PosX += HorDiv;
if(++nHor==NUMHORBTN){
nHor = 0;
PosX = 0;
PosY += VerDiv;
}
}
update = 1; // to initialize the user graphics
}
/////////////////////////////////////////////////////////////////////////////
// Function: WORD GOLMsgCallback(WORD objMsg, OBJ_HEADER* pObj, GOL_MSG* pMsg)
// Input: objMsg - translated message for the object,
// pObj - pointer to the object,
// pMsg - pointer to the non-translated, raw GOL message
// Output: if the function returns non-zero the message will be processed by default
// Overview: it's a user defined function. GOLMsg() function calls it each
// time the valid message for the object received
/////////////////////////////////////////////////////////////////////////////
WORD GOLMsgCallback(WORD objMsg, OBJ_HEADER* pObj, GOL_MSG* pMsg){
WORD objectID;
unsigned int nbuttons;
objectID = GetObjID(pObj);
nbuttons = NUMHORBTN * NUMVERBTN;
if((objectID > (KEYPAD_BTN - 1)) && (objectID < (KEYPAD_BTN + nbuttons))){
if (objMsg == BTN_MSG_PRESSED) { // check if button is pressed
MyText[nextChar++]=BtnTexts[objectID-KEYPAD_BTN][0];
MyText[nextChar] ='\0';
Beep();
}
update = 1;
}
return 1;
}
/////////////////////////////////////////////////////////////////////////////
// Function: WORD GOLDrawCallback()
// Output: if the function returns non-zero the draw control will be passed to GOL
// Overview: it's a user defined function. GOLDraw() function calls it each
// time when GOL objects drawing is completed. User drawing should be done here.
// GOL will not change color, line type and clipping region settings while
// this function returns zero.
/////////////////////////////////////////////////////////////////////////////
WORD GOLDrawCallback(){
if(update){
MoveTo(0,GetTextHeight(&FONTDEFAULT));
OutText(MyText);
update = 0;
}
return 1;
}
// End //////////////////////////////////////////////////////////////////////