1 /* 2 * A demonstration of bitmap plotting. 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 #include "bitmaps.h" 18 19 /** 20 * Handle termination of the process. 21 */ 22 void shutdown(int signum) 23 { 24 printf("Closing...\n"); 25 ubb_close(0); 26 exit(1); 27 } 28 29 void lcd_shutdown(int signum) 30 { 31 LCD_off(); 32 shutdown(signum); 33 } 34 35 void bitmap(uint8_t image) 36 { 37 LCD_image(0, 0, image_data[image], IMAGE_WIDTH, IMAGE_HEIGHT); 38 } 39 40 uint8_t states[] = {LCD_MADCTL_MY_MX, LCD_MADCTL_MY_V, 0, LCD_MADCTL_MX_V}; 41 42 int main(int argc, char *argv[]) 43 { 44 uint8_t state = 1; 45 uint8_t times; 46 uint8_t current_image = 0; 47 48 signal(SIGINT, shutdown); 49 50 /* Access the 8:10 port. */ 51 52 if (ubb_open(0) < 0) { 53 perror("ubb_open"); 54 return 1; 55 } 56 57 ubb_power(1); 58 printf("Power on.\n"); 59 60 spi_init(); 61 LCD_init(); 62 63 signal(SIGINT, lcd_shutdown); 64 65 bitmap(current_image); 66 67 while (times--) 68 { 69 sleep(1); 70 printf("Updating...\n"); 71 72 LCD_send(LCD_COMMAND, LCD_MADCTL); 73 LCD_send(LCD_DATA, states[state]); 74 bitmap(current_image); 75 76 state = (state + 1) % 4; 77 current_image = (current_image + 1) % NUMBER_OF_IMAGES; 78 } 79 80 LCD_off(); 81 82 printf("Closing...\n"); 83 ubb_close(0); 84 return 0; 85 } 86 87 /* vim: tabstop=4 expandtab shiftwidth=4 88 */