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.

117 lines
2.5 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. lcd_redrawBuffer(lcd);
  25. printf("...waiting 1 second...");
  26. sleep(1);
  27. printf("black...");
  28. lcd_fillScreen(lcd, 0, 0, 0);
  29. lcd_redrawBuffer(lcd);
  30. printf("DONE\n");
  31. printf("...waiting 1 second...\n");
  32. sleep(1);
  33. printf("Points...");
  34. for (int i = 1; i < 2000; i++) {
  35. int r = rand();
  36. lcd_drawPixel(lcd, r % 128, i % 160,
  37. random_color_r(i),
  38. random_color_g(i),
  39. random_color_b(i));
  40. }
  41. lcd_redrawBuffer(lcd);
  42. printf("DONE\n");
  43. printf("...waiting 1 second...\n");
  44. sleep(1);
  45. printf("Regions...");
  46. int w = 15;
  47. int h = 20;
  48. for (int i = 1; i < 200; i++) {
  49. int x = rand() % (128 - w);
  50. int y = rand() % (160 - h);
  51. lcd_setWindow(lcd, x, y, x + w - 1, y + h - 1);
  52. uint8 r = rand();
  53. uint8 g = rand();
  54. uint8 b = rand();
  55. for (int p = 0; p < w*h; p++) {
  56. lcd_pushPixel(lcd, r * p / (w*h), g * (w*h-p) / (w*h), b);
  57. }
  58. lcd_redrawBuffer(lcd);
  59. }
  60. printf("DONE\n");
  61. return 0;
  62. printf("...waiting 1 second...\n");
  63. sleep(1);
  64. printf("Rectangles...");
  65. lcd_fillScreen(lcd, 0, 0, 0);
  66. lcd_fillRect(lcd, 30, 10, 10, 10, 0, 255, 255);
  67. lcd_fillRect(lcd, 30, 30, 10, 10, 255, 255, 0);
  68. lcd_redrawBuffer(lcd);
  69. printf("DONE\n");
  70. printf("...waiting 1 second...\n");
  71. sleep(1);
  72. printf("Text...");
  73. lcd_fillScreen(lcd, 0, 0, 0);
  74. lcd_drawChar(lcd, 10, 90, 'A', 255, 0, 0);
  75. lcd_drawText(lcd, 10, 50, "Hello, world!", 0, 255, 0);
  76. lcd_drawChar(lcd, 10, 100, 'Z', 0, 0, 255);
  77. lcd_redrawBuffer(lcd);
  78. printf("DONE\n");
  79. printf("...waiting 2 seconds...\n");
  80. sleep(2);
  81. printf("Pulsing color...");
  82. for (int i = 0; i < 256; i++) {
  83. lcd_fillScreen(lcd,
  84. random_color_r(i),
  85. random_color_g(i),
  86. random_color_b(i));
  87. lcd_redrawBuffer(lcd);
  88. }
  89. printf("DONE\n");
  90. printf("...waiting 2 seconds before shutdown...\n");
  91. sleep(2);
  92. printf("Terminating...\n");
  93. lcd_fillScreen(lcd, 0, 0, 0);
  94. lcd_deinit(lcd);
  95. printf("DONE\n");
  96. return 0;
  97. }