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