|
- #include <stdio.h>
- #include <stdlib.h>
- #include <time.h>
- #include <unistd.h>
- #include <wiringPi.h>
- #include "spilcd.h"
- #include "spilcd_gfx.h"
- #include "spilcd_font.h"
-
- uint8 random_color_r(int seed);
- uint8 random_color_g(int seed);
- uint8 random_color_b(int seed);
- inline uint8 random_color_r(int seed) { return seed % (256 / 7) * 7; }
- inline uint8 random_color_g(int seed) { return seed % (256 / 13) * 13; }
- inline uint8 random_color_b(int seed) { return seed % (256 / 23) * 23; }
-
- int main(int argc, char *argv[])
- {
- setbuf(stdout, NULL);
- srand(time(NULL));
-
- wiringPiSetup();
-
- lcd_t* lcd = lcd_init(40000000, 1, 10, 7, 8);
-
- printf("Fill display...");
- printf("blue...");
- lcd_fillScreen(lcd, 0, 70, 160);
- lcd_redrawBuffer(lcd);
- printf("...waiting 1 second...");
- sleep(1);
- printf("black...");
- lcd_fillScreen(lcd, 0, 0, 0);
- lcd_redrawBuffer(lcd);
- printf("DONE\n");
-
- printf("...waiting 1 second...\n");
- sleep(1);
-
- printf("Points...");
- for (int i = 1; i < 2000; i++) {
- int r = rand();
- lcd_drawPixel(lcd, r % 128, i % 160,
- random_color_r(i),
- random_color_g(i),
- random_color_b(i));
- }
- lcd_redrawBuffer(lcd);
- printf("DONE\n");
-
- printf("...waiting 1 second...\n");
- sleep(1);
-
- printf("Regions...");
- int w = 15;
- int h = 20;
- for (int i = 1; i < 200; i++) {
- int x = rand() % (128 - w);
- int y = rand() % (160 - h);
- lcd_setWindow(lcd, x, y, x + w - 1, y + h - 1);
- uint8 r = rand();
- uint8 g = rand();
- uint8 b = rand();
- for (int p = 0; p < w*h; p++) {
- lcd_pushPixel(lcd, r * p / (w*h), g * (w*h-p) / (w*h), b);
- }
- lcd_redrawBuffer(lcd);
- }
- printf("DONE\n");
-
- return 0;
-
- printf("...waiting 1 second...\n");
- sleep(1);
-
- printf("Rectangles...");
- lcd_fillScreen(lcd, 0, 0, 0);
- lcd_fillRect(lcd, 30, 10, 10, 10, 0, 255, 255);
- lcd_fillRect(lcd, 30, 30, 10, 10, 255, 255, 0);
- lcd_redrawBuffer(lcd);
- printf("DONE\n");
-
- printf("...waiting 1 second...\n");
- sleep(1);
-
- printf("Text...");
- lcd_fillScreen(lcd, 0, 0, 0);
- lcd_drawChar(lcd, 10, 90, 'A', 255, 0, 0);
- lcd_drawText(lcd, 10, 50, "Hello, world!", 0, 255, 0);
- lcd_drawChar(lcd, 10, 100, 'Z', 0, 0, 255);
- lcd_redrawBuffer(lcd);
- printf("DONE\n");
-
- printf("...waiting 2 seconds...\n");
- sleep(2);
-
- printf("Pulsing color...");
- for (int i = 0; i < 256; i++) {
- lcd_fillScreen(lcd,
- random_color_r(i),
- random_color_g(i),
- random_color_b(i));
- lcd_redrawBuffer(lcd);
- }
- printf("DONE\n");
-
- printf("...waiting 2 seconds before shutdown...\n");
- sleep(2);
- printf("Terminating...\n");
- lcd_fillScreen(lcd, 0, 0, 0);
- lcd_deinit(lcd);
- printf("DONE\n");
-
- return 0;
- }
|