1 /* 2 * A demonstration of area filling using different orientations. 3 * 4 * Copyright (C) 2013 Paul Boddie 5 * 6 * This program is free software; you can redistribute it and/or modify 7 * it under the terms of the GNU General Public License as published by 8 * the Free Software Foundation; either version 2 of the License, or 9 * (at your option) any later version. 10 */ 11 12 #include "pcf8833.h" 13 #include <stdio.h> 14 #include <unistd.h> 15 #include <signal.h> 16 #include <stdlib.h> 17 18 /** 19 * Handle termination of the process. 20 */ 21 void shutdown(int signum) 22 { 23 printf("Closing...\n"); 24 ubb_close(0); 25 exit(1); 26 } 27 28 void lcd_shutdown(int signum) 29 { 30 LCD_off(); 31 shutdown(signum); 32 } 33 34 /** 35 * Show a pattern on the screen. 36 */ 37 void pattern() 38 { 39 LCD_area(0, 0, 131, 131, 0x000); 40 LCD_area(21, 21, 35, 65, 0xf800); LCD_area(21, 66, 35, 110, 0xfbe0); 41 LCD_area(36, 21, 50, 65, 0xffe0); LCD_area(36, 66, 50, 110, 0x7fe0); 42 LCD_area(51, 21, 65, 65, 0x07e0); LCD_area(51, 66, 65, 110, 0x07ef); 43 LCD_area(66, 21, 80, 65, 0x07ff); LCD_area(66, 66, 80, 110, 0x0bff); 44 LCD_area(81, 21, 95, 65, 0x001f); LCD_area(81, 66, 95, 110, 0x781f); 45 LCD_area(96, 21, 110, 65, 0xf81f); LCD_area(96, 66, 110, 110, 0xf80f); 46 } 47 48 uint8_t states[] = {LCD_MADCTL_MY_MX, LCD_MADCTL_MY_V, 0, LCD_MADCTL_MX_V}; 49 50 int main(int argc, char *argv[]) 51 { 52 uint8_t state = 1, times = 10; 53 54 signal(SIGINT, shutdown); 55 56 /* Access the 8:10 port. */ 57 58 if (ubb_open(0) < 0) { 59 perror("ubb_open"); 60 return 1; 61 } 62 63 ubb_power(1); 64 printf("Power on.\n"); 65 66 spi_init(); 67 LCD_init(); 68 69 signal(SIGINT, lcd_shutdown); 70 71 printf("Updating...\n"); 72 pattern(); 73 74 while (times--) 75 { 76 sleep(1); 77 printf("Updating...\n"); 78 79 LCD_send(LCD_COMMAND, LCD_MADCTL); 80 LCD_send(LCD_DATA, states[state]); 81 pattern(); 82 83 state = (state + 1) % 4; 84 } 85 86 LCD_off(); 87 88 printf("Closing...\n"); 89 ubb_close(0); 90 return 0; 91 } 92 93 /* vim: tabstop=4 expandtab shiftwidth=4 94 */