/*lint -save -e970 Disable MISRA rule (6.3) checking. */ int main(void) /*lint -restore Enable MISRA rule (6.3) checking. */ { /* Write your local variable definition here */ enum logics{false, true}; uint16_t rotation = 0; /*** Processor Expert internal initialization. DON'T REMOVE THIS CODE!!! ***/ PE_low_level_init(); /*** End of Processor Expert internal initialization. ***/ /* Write your code here */ lcd_init(Background); add2display((unsigned char *)"University of Nairobi",0); add2display((unsigned char *)" Physics Department ",0); add2display((unsigned char *)" another string for ",0); add2display((unsigned char *)" another string menu ",0); selected=0; while(1){ if(rotation>3) rotation = 0; if(selected>3) selected=0; lcd_setOrientation(rotation); lcd_clear(Background); display(); //lcd_invert(rotation); lcd_fillrect(10,50,40,60, blue); lcd_drawrect(10,50,40,60, red); lcd_drawline(11,51,39,59, green); lcd_drawcircle(30, 100,10, red); lcd_fillcircle(30, 100,10, crimson); WAIT1_Waitms(1000); selected++; rotation++; } /*** Don't write any code pass this line, or it will be deleted during code generation. ***/ /*** RTOS startup code. Macro PEX_RTOS_START is defined by the RTOS component. DON'T MODIFY THIS CODE!!! ***/ #ifdef PEX_RTOS_START PEX_RTOS_START(); /* Startup of the selected RTOS. Macro is defined by the RTOS component. */ #endif /*** End of RTOS startup code. ***/ /*** Processor Expert end of main routine. DON'T MODIFY THIS CODE!!! ***/ for(;;){} /*** Processor Expert end of main routine. DON'T WRITE CODE BELOW!!! ***/ } /*** End of main routine. DO NOT MODIFY THIS TEXT!!! ***/
void cmd_lcd_test(uint_least16_t fgcolor, uint_least16_t bgcolor) { uint_least8_t c=1, f_save=features; char tmp[32]; #ifdef TP_SUPPORT uint_least16_t x, y, z, last_x=0, last_y=0; uint_least32_t ms=0; tp_init(); ldr_init(); features = FEATURE_TP | FEATURE_LDR; //FEATURE_TP | FEATURE_LDR #else uint_least8_t sw; int_least8_t pos=0, hpos=0, vpos=0; enc_init(); features = FEATURE_ENC; #endif lcd_fillrect(0, 0, (LCD_WIDTH-1)/3, LCD_HEIGHT-1, RGB(255,0,0)); lcd_fillrect((LCD_WIDTH-1)/3, 0, ((LCD_WIDTH-1)/3)*2, LCD_HEIGHT-1, RGB(0,255,0)); lcd_fillrect(((LCD_WIDTH-1)/3)*2, 0, LCD_WIDTH-1, LCD_HEIGHT-1, RGB(0,0,255)); /* delay_ms(1500); lcd_clear(bgcolor); lcd_setorientation( 0); lcd_drawrect(10, 20, 40, 40, RGB(200, 0, 0)); lcd_drawtext(15, 25, "0 ", 0, RGB(200, 0, 0), 0, 0); lcd_setorientation( 90); lcd_drawrect(10, 20, 40, 40, RGB( 0,200, 0)); lcd_drawtext(15, 25, "90 ", 0, RGB( 0,200, 0), 0, 0); lcd_setorientation(180); lcd_drawrect(10, 20, 40, 40, RGB( 0, 0,200)); lcd_drawtext(15, 25, "180", 0, RGB( 0, 0,200), 0, 0); lcd_setorientation(270); lcd_drawrect(10, 20, 40, 40, RGB(200, 0,200)); lcd_drawtext(15, 25, "270", 0, RGB(200, 0,200), 0, 0); lcd_setorientation(0); lcd_drawline(0, LCD_WIDTH/4*1, LCD_WIDTH-1, LCD_WIDTH/4*1, RGB(120,120,120)); lcd_drawline(0, LCD_WIDTH/4*2, LCD_WIDTH-1, LCD_WIDTH/4*2, RGB(120,120,120)); lcd_drawline(0, LCD_WIDTH/4*3, LCD_WIDTH-1, LCD_WIDTH/4*3, RGB(120,120,120)); lcd_drawline(LCD_WIDTH/4*1, 0, LCD_WIDTH/4*1, LCD_HEIGHT-1, RGB(120,120,120)); lcd_drawline(LCD_WIDTH/4*2, 0, LCD_WIDTH/4*2, LCD_HEIGHT-1, RGB(120,120,120)); lcd_drawline(LCD_WIDTH/4*3, 0, LCD_WIDTH/4*3, LCD_HEIGHT-1, RGB(120,120,120)); lcd_drawcircle(LCD_WIDTH/2, LCD_HEIGHT/2, 40, RGB(120,120,120)); */ lcd_drawtext(LCD_CENTER, LCD_HEIGHT/2-5, "v"VERSION, 0, 0, 0, 0); lcd_drawtext(LCD_CENTER, LCD_HEIGHT/2+5, "("__DATE__")", 0, 0, 0, 0); lcd_drawtext(LCD_CENTER, LCD_HEIGHT-10, "watterott.com", 1, 0, 0, 0); do { #ifdef TP_SUPPORT tp_read(); z = tp_getz(); if(z) { x = tp_getx(); y = tp_gety(); if((x!=last_x) || (y!=last_y)) { last_x = x; last_y = y; lcd_fillcircle(x, y, 4, fgcolor); //lcd_drawpixel(x, y); sprintf(tmp, "X%03i Y%03i Z%03i", x, x, z); lcd_drawtext(5, 5, tmp, 0, fgcolor, bgcolor, 1); } GPIO_SETPIN(LED_PORT, LED_PIN); //LED on } else { GPIO_CLRPIN(LED_PORT, LED_PIN); //LED off } if(features & FEATURE_LDR) { if((get_ms() - ms) >= 100) { ms = get_ms(); x = ldr_service(100); sprintf(tmp, "LDR %03i", x); lcd_drawtext(5, 15, tmp, 0, fgcolor, bgcolor, 1); } } #else //TP_SUPPORT pos += enc_getdelta(); hpos += nav_gethdelta(); vpos += nav_getvdelta(); sprintf(tmp, "P%03i H%03i V%03i", pos, hpos, vpos); lcd_drawtext(5, 5, tmp, 0, fgcolor, bgcolor, 1); sw = enc_getsw(); sw |= nav_getsw(); if(sw) { GPIO_SETPIN(LED_PORT, LED_PIN); //LED on if(sw & 0x02) { if(features == FEATURE_ENC) { sprintf(tmp, "NAV"); nav_init(); features = FEATURE_NAV; } else //if(features == FEATURE_NAV) { sprintf(tmp, "ENC"); enc_init(); features = FEATURE_ENC; } lcd_drawtext(5, 25, tmp, 0, fgcolor, bgcolor, 1); delay_ms(500); while(enc_getsw() || nav_getsw()); } else if(sw & 0x01) { lcd_drawtext(5, 15, "press", 0, fgcolor, bgcolor, 1); } } else { GPIO_CLRPIN(LED_PORT, LED_PIN); //LED off } #endif if(if_available()) { c = if_read8(); } }while(c != 0); GPIO_CLRPIN(LED_PORT, LED_PIN); //LED off lcd_clear(bgcolor); features = f_save; return; }
void cmd_tp_calibrate(uint_least16_t fgcolor, uint_least16_t bgcolor) { uint_least8_t i; CAL_POINT lcd_points[3] = {CAL_POINT1, CAL_POINT2, CAL_POINT3}; //calibration point postions CAL_POINT tp_points[3]; tp_init(); //enable/reset touch tp_read(); if(tp_rawz()) { lcd_clear(bgcolor); lcd_drawtext(10, 10, "Release Touchpanel.", 1, fgcolor, 0, 0); while(tp_rawz() > MIN_PRESSURE){ tp_read(); }; } do { //clear screen and wait for touch release lcd_clear(bgcolor); lcd_setorientation(180); lcd_drawtext(LCD_CENTER, (LCD_HEIGHT/2)+10, "Calibration", 2, RGB(128,128,128), 0, 0); lcd_setorientation(0); lcd_drawtext(LCD_CENTER, (LCD_HEIGHT/2)+10, "Calibration", 2, RGB(128,128,128), 0, 0); for(i=0; i<3; ) { //draw point lcd_drawcircle(lcd_points[i].x, lcd_points[i].y, 15, fgcolor); lcd_drawline(lcd_points[i].x-10, lcd_points[i].y, lcd_points[i].x-3, lcd_points[i].y, fgcolor); lcd_drawline(lcd_points[i].x+3, lcd_points[i].y, lcd_points[i].x+10, lcd_points[i].y, fgcolor); lcd_drawline(lcd_points[i].x, lcd_points[i].y-10, lcd_points[i].x, lcd_points[i].y-3, fgcolor); lcd_drawline(lcd_points[i].x, lcd_points[i].y+3, lcd_points[i].x, lcd_points[i].y+10, fgcolor); //touch detected? -> save point tp_read(); if(tp_getz() > (MIN_PRESSURE*1.5)) { //mark point lcd_fillcircle(lcd_points[i].x, lcd_points[i].y, 4, RGB(255,0,0)); //wait and clear point delay_ms(400); lcd_fillcircle(lcd_points[i].x, lcd_points[i].y, 15, bgcolor); //save point tp_points[i].x = tp_rawx(); tp_points[i].y = tp_rawy(); i++; //wait till press is over while(tp_rawz() > MIN_PRESSURE){ tp_read(); }; } //data available if(if_available()) { if(if_read8() == 0) { i = 0xFF; break; } } } } while((i!=0xFF) && (tp_calmatrix(lcd_points, tp_points)!=0)); //calculate calibration matrix tp_init(); //reset touch lcd_clear(bgcolor); return; }