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