Advertisement
Guest User

Untitled

a guest
Nov 13th, 2024
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.52 KB | Source Code | 0 0
  1. //SDManager.h
  2. #ifndef _sdm
  3. #define _sdm
  4.  
  5. #include <SdFat.h>
  6. #include <SPI.h>
  7. #include <Adafruit_ImageReader.h>
  8.  
  9. #define SDFAT 1
  10.  
  11. #define SDCSpin 4
  12. #define SDMISOpin 19
  13. #define SDMOSIpin 23
  14. #define SDSCLKpin 18
  15.  
  16. SdFat32 SD;
  17.  
  18. class sdStorage{
  19. public:
  20.     sdStorage();
  21.  
  22.     File32 getFile(const char* path, bool write=false);
  23. };
  24.  
  25. #endif
  26.  
  27. //SDManager.cpp
  28. #include <SdFat.h>
  29. #include <SPI.h>
  30. #include <Adafruit_ImageReader.h>
  31.  
  32. #include "SDManager.h"
  33.  
  34. sdStorage::sdStorage(){
  35.     if (!SD.begin(SDCSpin, SD_SCK_MHZ(4))){
  36.         Serial.println("SD card couldn't initialize!");
  37.         exit(1);
  38.     }
  39.     if (SD.vol()->fatType() == 1){
  40.         Serial.println("No FAT32 partion found!");
  41.         exit(1);
  42.     }
  43. }
  44.  
  45. File32 sdStorage::getFile(const char* path, bool write){
  46.     File32 fetched;
  47.     fetched.open(path, (write) ? FILE_WRITE : FILE_READ);
  48.  
  49.     return fetched;
  50. };
  51.  
  52. //Render.h
  53. #ifndef _render
  54. #define _render
  55.  
  56. #include <Adafruit_ST7789.h>
  57. #include <Adafruit_GFX.h>
  58. #include <Adafruit_ImageReader.h>
  59.  
  60. #include "SDManager.h"
  61.  
  62. #define screenWidth 320
  63. #define screenHeight 240
  64. #define CSpin 14
  65. #define DCpin 27
  66. #define MISOpin 19
  67. #define MOSIpin 23
  68. #define SCLKpin 18
  69. #define RSTpin 33
  70.  
  71. Adafruit_ST7789 display(CSpin, DCpin, MOSIpin, SCLKpin, RSTpin);
  72. Adafruit_ImageReader reader(SD);
  73.  
  74. class Render{
  75. public:
  76.  
  77.     Render();
  78.  
  79.     void drawPixel(uint16_t x, uint16_t y, uint16_t c);
  80.  
  81.     void drawLine(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, uint16_t c);
  82.  
  83.     void drawRect(uint16_t x, uint16_t y, uint16_t w, uint16_t h, uint16_t );
  84.  
  85.     void drawRRect(uint16_t x, uint16_t y, uint16_t w, uint16_t h, uint16_t r, uint16_t c);
  86.  
  87.     void drawTri(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, uint16_t c);
  88.  
  89.     void drawCircle(uint16_t x, uint16_t y, uint16_t r, uint16_t c);
  90.  
  91.     void drawBitmap(uint16_t x, uint16_t y, uint8_t *map, uint16_t w, uint16_t h, uint16_t c);
  92.  
  93.     void drawImage(const char* path, uint16_t x, uint16_t y);
  94. };
  95.  
  96. #endif
  97.  
  98. //Render.cpp
  99. #include <Adafruit_GFX.h>
  100. #include <Adafruit_ST7789.h>
  101. #include <Adafruit_ImageReader.h>
  102.  
  103. #include "Render.h"
  104.  
  105. Render::Render(){
  106.     display.init(screenWidth, screenHeight);
  107. }
  108.  
  109. void Render::drawPixel(uint16_t x, uint16_t y, uint16_t c) {
  110.     display.drawPixel(x, y, c);
  111. };
  112.  
  113. void Render::drawLine(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, uint16_t c) {
  114.     display.drawLine(x0, y0, x1, y1, c);
  115. };
  116.  
  117. void Render::drawRect(uint16_t x, uint16_t y, uint16_t w, uint16_t h, uint16_t c) {
  118.     display.drawRect(x, y, w, h, c);
  119. };
  120.  
  121. void Render::drawRRect(uint16_t x, uint16_t y, uint16_t w, uint16_t h, uint16_t r, uint16_t c) {
  122.     display.drawRoundRect(x, y, w, h, r, c);
  123. };
  124.  
  125. void Render::drawTri(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, uint16_t c) {
  126.     display.drawTriangle(x0, y0, x1, y1, x2, y2, c);
  127. };
  128.  
  129. void Render::drawCircle(uint16_t x, uint16_t y, uint16_t r, uint16_t c) {
  130.     display.drawCircle(x, y, r, c);
  131. };
  132.  
  133. void Render::drawBitmap(uint16_t x, uint16_t y, uint8_t *map, uint16_t w, uint16_t h, uint16_t c) {
  134.     display.drawBitmap(x, y, map, w, h, c);
  135. };
  136.  
  137. void Render::drawImage(const char* path, uint16_t x, uint16_t y){
  138.     reader.drawBMP(path, display, x, y, true);
  139. };
  140.  
  141.  
  142. //main.cpp
  143. #include <Arduino.h>
  144. #include <Adafruit_GFX.h>
  145. #include <Adafruit_ST7789.h>
  146.  
  147. #include "SDManager.h"
  148. #include "Render.h"
  149.  
  150. sdStorage Storage;
  151. Render render;
  152.  
  153. void setup(){
  154.     Serial.begin(9600);
  155. }
  156.  
  157. void loop(){
  158.  
  159. }
Tags: help
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement