/************************************************ * FAST MOVE RIGHT * DESCRIPTION: Move the selected object right by * the number of pixels indicated by the speedFactor. *************************************************/ char brush_fastMoveRight(struct Brush* brush, int16_t speedFactor, char clear_noRedraw) { if (brush->x_pos - speedFactor > 0) { if (clear_noRedraw == 1 && brush->isDrawing == 1) { brush->x_pos-=speedFactor; } else { brush->x_pos-=speedFactor; if (clear_noRedraw == 2 && brush->isDrawing == 1) { display_brush(brush, 0); } else if (brush->isDrawing == 1) { ILI9341_fillRect(brush->y_pos, brush->x_pos, brush->height, speedFactor , brush->color); } } return 0; } //Make sure we hit the wall else if (brush->height != 1) { speedFactor = brush->height - 1; brush->x_pos-=speedFactor; if (brush->isDrawing == 1) { ILI9341_fillRect(brush->y_pos, brush->x_pos, brush->height, speedFactor , brush->color); } } return 1; }
/************************************************ * FAST MOVE LEFT * DESCRIPTION: Move the selected object left by * the number of pixels indicated by the speedFactor. *************************************************/ char brush_fastMoveLeft(struct Brush* brush, int16_t speedFactor, char clear_noRedraw) { if (brush->x_pos + speedFactor + brush->width < ILI9341HEIGHT) { if (clear_noRedraw == 1) { brush->x_pos+=speedFactor; } else { brush->x_pos+=speedFactor; if (clear_noRedraw == 2 && brush->isDrawing == 1) { display_brush(brush, 0); } else if (brush->isDrawing == 1) { ILI9341_fillRect(brush->y_pos, brush->x_pos + brush->width - speedFactor , brush->height, speedFactor , brush->color); } } return 0; } else if (brush->x_pos + brush->width != ILI9341HEIGHT) { speedFactor = ILI9341HEIGHT - (brush->x_pos + brush->width); brush->x_pos+=speedFactor; if (brush->isDrawing == 1) { ILI9341_fillRect(brush->y_pos, brush->x_pos + brush->width - speedFactor , brush->height, speedFactor , brush->color); } } return 1; }
/************************************************ * FAST MOVE UP * DESCRIPTION: Move the selected object up by * the number of pixels indicated by the speedFactor. *************************************************/ char brush_fastMoveUp(struct Brush* brush, int16_t speedFactor, char clear_noRedraw) { if (brush->y_pos - speedFactor > 0 + brush->topMarginOffset) { if (clear_noRedraw == 1) { brush->y_pos-=speedFactor; } else { brush->y_pos-=speedFactor; if (clear_noRedraw == 2 && brush->isDrawing == 1) { display_brush(brush, 0); } else if (brush->isDrawing == 1) { ILI9341_fillRect(brush->y_pos, brush->x_pos, speedFactor, brush->width, brush->color); } } return 0; } else if (brush->y_pos != 1 + brush->topMarginOffset) { speedFactor = brush->y_pos - (brush->topMarginOffset + 1); brush->y_pos-=speedFactor; if (brush->isDrawing == 1) { ILI9341_fillRect(brush->y_pos, brush->x_pos, speedFactor, brush->width, brush->color); } } return 1; }
/************************************************ * FAST MOVE DOWN * DESCRIPTION: Move the selected object down by * the number of pixels indicated by the speedFactor. *************************************************/ char brush_fastMoveDown(struct Brush* brush, int16_t speedFactor, char clear_noRedraw) { if (brush->y_pos + brush->height + speedFactor < ILI9341WIDTH) { if (clear_noRedraw == 1) { brush->y_pos+=speedFactor; } else { brush->y_pos+=speedFactor; if (clear_noRedraw == 2 && brush->isDrawing == 1) { display_brush(brush, 0); } else if (brush->isDrawing == 1) { ILI9341_fillRect(brush->y_pos + brush->height - speedFactor, brush->x_pos, speedFactor, brush->width , brush->color); } } return 0; } else if (brush->y_pos + brush->height != ILI9341WIDTH) { speedFactor = ILI9341WIDTH - (brush->y_pos + brush->height); brush->y_pos+=speedFactor; if (brush->isDrawing == 1) { ILI9341_fillRect(brush->y_pos + brush->height - speedFactor, brush->x_pos, speedFactor, brush->width, brush->color); } } return 1; }
/********************************************** * DISPLAY SOLID * DESCRIPTION: Allows the user to display * or clear the brush object. **********************************************/ void display_brush(struct Brush* brush, char clear) { if (clear == 1) { ILI9341_fillRect(brush->y_pos, brush->x_pos, brush->height, brush->width, GetBgColor()); } else { ILI9341_fillRect(brush->y_pos, brush->x_pos, brush->height, brush->width, brush->color); } }
/************************************************** * DISPLAY * DESCRIPION: Displays the input object unless clear is set * in which case the object is removed from the screen and * the background color is used instead. *************************************************/ void display_bar(struct Bar* bar, char clear) { if (clear == 0) { //Vertical if (bar->orientation == BAR_VERTICAL) { if (bar->remove_from == BAR_TOP) //Remove bar from top { ILI9341_fillRect(bar->y_pos, bar->x_pos, (bar->height - bar->pixels), bar->width , bar->contrast); ILI9341_fillRect(bar->y_pos + (bar->height - bar->pixels), bar->x_pos, bar->pixels, bar->width , bar->color); } else if (bar->remove_from == BAR_BOTTOM) //Remove bar from top { ILI9341_fillRect(bar->y_pos, bar->x_pos, bar->pixels, bar->width , bar->color); ILI9341_fillRect(bar->y_pos + bar->pixels, bar->x_pos, (bar->height - bar->pixels), bar->width , bar->contrast); } } //Horizontal else { if (bar->remove_from == BAR_LEFT) { ILI9341_fillRect(bar->y_pos, bar->x_pos, bar->width, bar->pixels , bar->color); ILI9341_fillRect(bar->y_pos, bar->x_pos + bar->pixels, bar->width, (bar->height - bar->pixels) , bar->contrast); } else if (bar->remove_from == BAR_RIGHT) { ILI9341_fillRect(bar->y_pos, bar->x_pos, bar->width, (bar->height - bar->pixels) , bar->contrast); ILI9341_fillRect(bar->y_pos, bar->x_pos + (bar->height - bar->pixels), bar->width, bar->pixels , bar->color); } } } else { //Vertical if (bar->orientation == 0) { ILI9341_fillRect(bar->y_pos, bar->x_pos, bar->height, bar->width , GetBgColor()); } //Horizontal else { ILI9341_fillRect(bar->y_pos, bar->x_pos, bar->width, bar->pixels, GetBgColor()); } } }
/************************************************** * DISPLAY * DESCRIPION: Displays the input object unless clear is set * in which case the object is removed from the screen and * the background color is used instead. *************************************************/ void display_bar(struct Bar* bar, char clear) { if (clear == 0) { //Vertical if (bar->orientation == OrientVertical) { if (bar->remove_from == BarTop) //Remove bar from top { ILI9341_fillRect(bar->y_pos, bar->x_pos, (bar->height - bar->pixels), bar->width , bar->contrast); ILI9341_fillRect(bar->y_pos + (bar->height - bar->pixels), bar->x_pos, bar->pixels, bar->width , bar->color); } else if (bar->remove_from == BarBottom) //Remove bar from top { ILI9341_fillRect(bar->y_pos, bar->x_pos, bar->pixels, bar->width , bar->color); ILI9341_fillRect(bar->y_pos + bar->pixels, bar->x_pos, (bar->height - bar->pixels), bar->width , bar->contrast); } } //Horizontal else { if (bar->remove_from == BarLeft) { ILI9341_fillRect(bar->y_pos, bar->x_pos, bar->width, bar->pixels , bar->color); ILI9341_fillRect(bar->y_pos, bar->x_pos + bar->pixels, bar->width, (bar->height - bar->pixels) , bar->contrast); } else if (bar->remove_from == BarRight) { ILI9341_fillRect(bar->y_pos, bar->x_pos, bar->width, (bar->height - bar->pixels) , bar->contrast); ILI9341_fillRect(bar->y_pos, bar->x_pos + (bar->height - bar->pixels), bar->width, bar->pixels , bar->color); } } } else { //Vertical if (bar->orientation == OrientVertical) { ILI9341_fillRect(bar->y_pos, bar->x_pos, bar->height, bar->width , GetBgColor()); } //Horizontal else { ILI9341_fillRect(bar->y_pos, bar->x_pos, bar->width, bar->pixels, GetBgColor()); } } }
char decrease_bar(struct Bar* bar, uint16_t removeValue) { if (bar->orientation == BAR_VERTICAL) { if (bar->remove_from == BAR_TOP) //Remove bar from top { if (bar->pixels > removeValue) { ILI9341_fillRect(bar->y_pos + (bar->height - bar->pixels), bar->x_pos, removeValue, bar->width , bar->contrast); //Add contrast color bar->pixels -= removeValue; return 0; } ILI9341_fillRect(bar->y_pos + (bar->height - bar->pixels), bar->x_pos, bar->pixels, bar->width , bar->contrast); bar->pixels = 0; } else if (bar->remove_from == BAR_BOTTOM) //Remove bar from bottom { if (bar->pixels > removeValue) { ILI9341_fillRect(bar->y_pos + bar->pixels - removeValue, bar->x_pos, removeValue, bar->width , bar->contrast); bar->pixels -= removeValue; return 0; } ILI9341_fillRect(bar->y_pos, bar->x_pos, bar->pixels, bar->width , bar->contrast); bar->pixels = 0; } } else { if (bar->remove_from == BAR_LEFT) //Remove bar from top { if (bar->pixels > removeValue) { ILI9341_fillRect(bar->y_pos, bar->x_pos + bar->pixels - removeValue, bar->width, removeValue , bar->contrast); bar->pixels -= removeValue; return 0; } ILI9341_fillRect(bar->y_pos, bar->x_pos, bar->width, bar->pixels , bar->contrast); bar->pixels = 0; } else if (bar->remove_from == BAR_RIGHT) //Remove bar from bottom { if (bar->pixels > removeValue) { ILI9341_fillRect(bar->y_pos, bar->x_pos + (bar->height - bar->pixels), bar->width, removeValue , bar->contrast); //Add contrast color bar->pixels -= removeValue; return 0; } ILI9341_fillRect(bar->y_pos, bar->x_pos + (bar->height - bar->pixels), bar->width, bar->pixels, bar->contrast); bar->pixels = 0; } } return 1; }
//Decrease the bar's health value char decrease_bar(struct Bar* bar, uint16_t removeValue) { if (bar->orientation == OrientVertical) { if (bar->remove_from == BarTop) //Remove bar from top { if (bar->pixels > removeValue) { ILI9341_fillRect(bar->y_pos + (bar->height - bar->pixels), bar->x_pos, removeValue, bar->width , bar->contrast); //Add contrast color bar->pixels -= removeValue; return 0; } ILI9341_fillRect(bar->y_pos + (bar->height - bar->pixels), bar->x_pos, bar->pixels, bar->width , bar->contrast); bar->pixels = 0; } else if (bar->remove_from == BarBottom) //Remove bar from bottom { if (bar->pixels > removeValue) { ILI9341_fillRect(bar->y_pos + bar->pixels - removeValue, bar->x_pos, removeValue, bar->width , bar->contrast); bar->pixels -= removeValue; return 0; } ILI9341_fillRect(bar->y_pos, bar->x_pos, bar->pixels, bar->width , bar->contrast); bar->pixels = 0; } } else { if (bar->remove_from == BarLeft) //Remove bar from top { if (bar->pixels > removeValue) { ILI9341_fillRect(bar->y_pos, bar->x_pos + bar->pixels - removeValue, bar->width, removeValue , bar->contrast); bar->pixels -= removeValue; return 0; } ILI9341_fillRect(bar->y_pos, bar->x_pos, bar->width, bar->pixels , bar->contrast); bar->pixels = 0; } else if (bar->remove_from == BarRight) //Remove bar from bottom { if (bar->pixels > removeValue) { ILI9341_fillRect(bar->y_pos, bar->x_pos + (bar->height - bar->pixels), bar->width, removeValue , bar->contrast); //Add contrast color bar->pixels -= removeValue; return 0; } ILI9341_fillRect(bar->y_pos, bar->x_pos + (bar->height - bar->pixels), bar->width, bar->pixels, bar->contrast); bar->pixels = 0; } } return 1; }
// ----------------------------------------------------------------------------- //! \brief LCD main event processing loop. //! //! \return void // ----------------------------------------------------------------------------- static void LCDTask_process(void) { uint16_t timeout_counter = 0; uint8_t last_motion_state = 0; int8_t last_touch_value = -1; /* Forever loop */ for (;; ) { if (LCDTask_State == LCDTASK_OFF_STATE) { Semaphore_pend(lcdSem, BIOS_WAIT_FOREVER); } // Capture the ISR events flags now within a critical section. // We do this to avoid possible race conditions where the ISR is // modifying the event mask while the task is read/writing it. UInt hwiKey = Hwi_disable(); UInt taskKey = Task_disable(); LCDTask_events = MOTION_ISR_EVENT_FLAGS; MOTION_ISR_EVENT_FLAGS = 0; Task_restore(taskKey); Hwi_restore(hwiKey); // motion_state = PIN_getInputValue(Board_LCD_MOTION); // if (motion_state != last_motion_state) { // if (motion_state) { // LCDTask_events = LCDTASK_MOTION_SENSED_EVENT; // } else { // LCDTask_events = LCDTASK_MOTION_GONE_EVENT; // } // last_motion_state = motion_state; // } if(LCDTask_events & LCDTASK_MOTION_SENSED_EVENT) { if (LCDTask_State == LCDTASK_OFF_STATE) { LCDTask_turnOnLCD(); LCDTask_State = LCDTASK_TURNING_ON_STATE; } // If only a start to motion was detected, // Then we want to disable the timeout timeout_counter = 0; } if (LCDTask_events & LCDTASK_MOTION_GONE_EVENT) { //if (LCDTask_events & LCDTASK_MOTION_SENSED_EVENT) { LCDTask_State = LCDTASK_WAIT_STATE; // Since we've sensed no more motion start timeout // Start/reset count down to power off timeout_counter = 300; } if (LCDTask_State > LCDTASK_OFF_STATE) { // Check for presses int8_t touch = LCDTask_getTouchPoint(); if (touch != last_touch_value) { if (touch>-1) { // Add some sort of feedback ILI9341_fillRect(4+length*20,4,10,10,ILI9341_WHITE); // Check to see if this is a command press if (touch > 9) { // Process command if (touch == 10) { // Lock the door // sendLockRequest(); } else if (touch == 12) { // Process keycode (enter) if (length > 0) { // Send keycode for checking // checkKeyCode(keybuf,length); // Reset buffer ILI9341_fillRect(4,4,20*length + 10,10,ILI9341_BLACK); length = 0; } } } else { // Add touch to buffer if (length < LCD_MAX_KEYLENGTH) { keybuf[length++] = touch; } } } last_touch_value = touch; } } if (LCDTask_State != LCDTASK_OFF_STATE) { // Check for timeout if (timeout_counter > 0) { timeout_counter--; if (timeout_counter==0) { LCDTask_State = LCDTASK_OFF_STATE; LCDTask_turnOffLCD(); length = 0; } } delay_ms(10); } } }