You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

108 lines
2.3 KiB

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <time.h>
  4. #include <unistd.h>
  5. #include <wiringPi.h>
  6. #include "spilcd.h"
  7. #include "spilcd_gfx.h"
  8. #include "spilcd_font.h"
  9. uint8 random_color_r(int seed);
  10. uint8 random_color_g(int seed);
  11. uint8 random_color_b(int seed);
  12. inline uint8 random_color_r(int seed) { return seed % (256 / 7) * 7; }
  13. inline uint8 random_color_g(int seed) { return seed % (256 / 13) * 13; }
  14. inline uint8 random_color_b(int seed) { return seed % (256 / 23) * 23; }
  15. int main(int argc, char *argv[])
  16. {
  17. setbuf(stdout, NULL);
  18. srand(time(NULL));
  19. wiringPiSetup();
  20. lcd_t* lcd = lcd_init(40000000, 1, 10, 7, 8);
  21. printf("Fill display...");
  22. printf("blue...");
  23. lcd_fillScreen(lcd, 0, 70, 160);
  24. printf("...waiting 1 second...");
  25. sleep(1);
  26. printf("black...");
  27. lcd_fillScreen(lcd, 0, 0, 0);
  28. printf("DONE\n");
  29. printf("...waiting 1 second...\n");
  30. sleep(1);
  31. printf("Points...");
  32. for (int i = 1; i < 2000; i++) {
  33. int r = rand();
  34. lcd_drawPixel(lcd, r % 128, i % 160,
  35. random_color_r(i),
  36. random_color_g(i),
  37. random_color_b(i));
  38. }
  39. printf("DONE\n");
  40. printf("...waiting 1 second...\n");
  41. sleep(1);
  42. printf("Regions...");
  43. int w = 15;
  44. int h = 20;
  45. for (int i = 1; i < 200; i++) {
  46. int x = rand() % (128 - w);
  47. int y = rand() % (160 - h);
  48. lcd_setWindow(lcd, x, y, x + w - 1, y + h - 1);
  49. uint8 r = rand();
  50. uint8 g = rand();
  51. uint8 b = rand();
  52. for (int p = 0; p < w*h; p++) {
  53. lcd_pushPixel(lcd, r * p / (w*h), g * (w*h-p) / (w*h), b);
  54. }
  55. }
  56. printf("DONE\n");
  57. printf("...waiting 1 second...\n");
  58. sleep(1);
  59. printf("Rectangles...");
  60. lcd_fillScreen(lcd, 0, 0, 0);
  61. lcd_fillRect(lcd, 30, 10, 10, 10, 0, 255, 255);
  62. lcd_fillRect(lcd, 30, 30, 10, 10, 255, 255, 0);
  63. printf("DONE\n");
  64. printf("...waiting 1 second...\n");
  65. sleep(1);
  66. printf("Text...");
  67. lcd_fillScreen(lcd, 0, 0, 0);
  68. lcd_drawChar(lcd, 10, 90, 'A', 255, 0, 0);
  69. lcd_drawText(lcd, 10, 50, "Hello, world!", 0, 255, 0);
  70. lcd_drawChar(lcd, 10, 100, 'Z', 0, 0, 255);
  71. printf("DONE\n");
  72. printf("...waiting 2 seconds...\n");
  73. sleep(2);
  74. printf("Pulsing color...");
  75. for (int i = 0; i < 256; i++) {
  76. lcd_fillScreen(lcd,
  77. random_color_r(i),
  78. random_color_g(i),
  79. random_color_b(i));
  80. }
  81. printf("DONE\n");
  82. printf("...waiting 2 seconds before shutdown...\n");
  83. sleep(2);
  84. printf("Terminating...\n");
  85. lcd_fillScreen(lcd, 0, 0, 0);
  86. lcd_deinit(lcd);
  87. printf("DONE\n");
  88. return 0;
  89. }