Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //SDManager.h
- #ifndef _sdm
- #define _sdm
- #include <SdFat.h>
- #include <SPI.h>
- #include <Adafruit_ImageReader.h>
- #define SDFAT 1
- #define SDCSpin 4
- #define SDMISOpin 19
- #define SDMOSIpin 23
- #define SDSCLKpin 18
- SdFat32 SD;
- class sdStorage{
- public:
- sdStorage();
- File32 getFile(const char* path, bool write=false);
- };
- #endif
- //SDManager.cpp
- #include <SdFat.h>
- #include <SPI.h>
- #include <Adafruit_ImageReader.h>
- #include "SDManager.h"
- sdStorage::sdStorage(){
- if (!SD.begin(SDCSpin, SD_SCK_MHZ(4))){
- Serial.println("SD card couldn't initialize!");
- exit(1);
- }
- if (SD.vol()->fatType() == 1){
- Serial.println("No FAT32 partion found!");
- exit(1);
- }
- }
- File32 sdStorage::getFile(const char* path, bool write){
- File32 fetched;
- fetched.open(path, (write) ? FILE_WRITE : FILE_READ);
- return fetched;
- };
- //Render.h
- #ifndef _render
- #define _render
- #include <Adafruit_ST7789.h>
- #include <Adafruit_GFX.h>
- #include <Adafruit_ImageReader.h>
- #include "SDManager.h"
- #define screenWidth 320
- #define screenHeight 240
- #define CSpin 14
- #define DCpin 27
- #define MISOpin 19
- #define MOSIpin 23
- #define SCLKpin 18
- #define RSTpin 33
- Adafruit_ST7789 display(CSpin, DCpin, MOSIpin, SCLKpin, RSTpin);
- Adafruit_ImageReader reader(SD);
- class Render{
- public:
- Render();
- void drawPixel(uint16_t x, uint16_t y, uint16_t c);
- void drawLine(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, uint16_t c);
- void drawRect(uint16_t x, uint16_t y, uint16_t w, uint16_t h, uint16_t );
- void drawRRect(uint16_t x, uint16_t y, uint16_t w, uint16_t h, uint16_t r, uint16_t c);
- void drawTri(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, uint16_t c);
- void drawCircle(uint16_t x, uint16_t y, uint16_t r, uint16_t c);
- void drawBitmap(uint16_t x, uint16_t y, uint8_t *map, uint16_t w, uint16_t h, uint16_t c);
- void drawImage(const char* path, uint16_t x, uint16_t y);
- };
- #endif
- //Render.cpp
- #include <Adafruit_GFX.h>
- #include <Adafruit_ST7789.h>
- #include <Adafruit_ImageReader.h>
- #include "Render.h"
- Render::Render(){
- display.init(screenWidth, screenHeight);
- }
- void Render::drawPixel(uint16_t x, uint16_t y, uint16_t c) {
- display.drawPixel(x, y, c);
- };
- void Render::drawLine(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, uint16_t c) {
- display.drawLine(x0, y0, x1, y1, c);
- };
- void Render::drawRect(uint16_t x, uint16_t y, uint16_t w, uint16_t h, uint16_t c) {
- display.drawRect(x, y, w, h, c);
- };
- void Render::drawRRect(uint16_t x, uint16_t y, uint16_t w, uint16_t h, uint16_t r, uint16_t c) {
- display.drawRoundRect(x, y, w, h, r, c);
- };
- void Render::drawTri(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, uint16_t c) {
- display.drawTriangle(x0, y0, x1, y1, x2, y2, c);
- };
- void Render::drawCircle(uint16_t x, uint16_t y, uint16_t r, uint16_t c) {
- display.drawCircle(x, y, r, c);
- };
- void Render::drawBitmap(uint16_t x, uint16_t y, uint8_t *map, uint16_t w, uint16_t h, uint16_t c) {
- display.drawBitmap(x, y, map, w, h, c);
- };
- void Render::drawImage(const char* path, uint16_t x, uint16_t y){
- reader.drawBMP(path, display, x, y, true);
- };
- //main.cpp
- #include <Arduino.h>
- #include <Adafruit_GFX.h>
- #include <Adafruit_ST7789.h>
- #include "SDManager.h"
- #include "Render.h"
- sdStorage Storage;
- Render render;
- void setup(){
- Serial.begin(9600);
- }
- void loop(){
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement