linux-st7735/main.c

117 lines
2.5 KiB
C
Raw Normal View History

2020-08-01 19:49:42 +00:00
#include <stdio.h>
2020-08-02 13:51:47 +00:00
#include <stdlib.h>
#include <time.h>
#include <unistd.h>
2020-08-01 19:49:42 +00:00
#include <wiringPi.h>
2020-08-02 13:51:47 +00:00
#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; }
2020-08-01 19:49:42 +00:00
int main(int argc, char *argv[])
{
setbuf(stdout, NULL);
2020-08-02 13:51:47 +00:00
srand(time(NULL));
2020-08-01 19:49:42 +00:00
wiringPiSetup();
2020-08-02 13:51:47 +00:00
lcd_t* lcd = lcd_init(40000000, 1, 10, 7, 8);
2020-08-01 19:49:42 +00:00
printf("Fill display...");
printf("blue...");
2020-08-02 13:51:47 +00:00
lcd_fillScreen(lcd, 0, 70, 160);
2020-08-02 17:38:03 +00:00
lcd_redrawBuffer(lcd);
2020-08-02 13:51:47 +00:00
printf("...waiting 1 second...");
sleep(1);
2020-08-01 19:49:42 +00:00
printf("black...");
2020-08-02 13:51:47 +00:00
lcd_fillScreen(lcd, 0, 0, 0);
2020-08-02 17:38:03 +00:00
lcd_redrawBuffer(lcd);
2020-08-01 19:49:42 +00:00
printf("DONE\n");
2020-08-02 13:51:47 +00:00
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));
2020-08-01 19:49:42 +00:00
}
2020-08-02 17:38:03 +00:00
lcd_redrawBuffer(lcd);
2020-08-01 19:49:42 +00:00
printf("DONE\n");
2020-08-02 13:51:47 +00:00
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);
}
2020-08-02 17:38:03 +00:00
lcd_redrawBuffer(lcd);
2020-08-01 19:49:42 +00:00
}
2020-08-02 13:51:47 +00:00
printf("DONE\n");
2020-08-02 17:38:03 +00:00
return 0;
2020-08-02 13:51:47 +00:00
printf("...waiting 1 second...\n");
sleep(1);
2020-08-01 19:49:42 +00:00
printf("Rectangles...");
2020-08-02 13:51:47 +00:00
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);
2020-08-02 17:38:03 +00:00
lcd_redrawBuffer(lcd);
2020-08-01 19:49:42 +00:00
printf("DONE\n");
2020-08-02 13:51:47 +00:00
printf("...waiting 1 second...\n");
sleep(1);
2020-08-01 19:49:42 +00:00
printf("Text...");
2020-08-02 13:51:47 +00:00
lcd_fillScreen(lcd, 0, 0, 0);
2020-08-02 15:57:45 +00:00
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);
2020-08-02 17:38:03 +00:00
lcd_redrawBuffer(lcd);
2020-08-01 19:49:42 +00:00
printf("DONE\n");
2020-08-02 13:51:47 +00:00
printf("...waiting 2 seconds...\n");
sleep(2);
2020-08-01 19:49:42 +00:00
2020-08-02 13:51:47 +00:00
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));
2020-08-02 17:38:03 +00:00
lcd_redrawBuffer(lcd);
2020-08-02 13:51:47 +00:00
}
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");
2020-08-01 19:49:42 +00:00
return 0;
}