mirror of
https://github.com/justcallmekoko/ESP32Marauder.git
synced 2025-12-12 15:50:36 -08:00
Add initial SD support
This commit is contained in:
@@ -27,7 +27,14 @@ void Display::RunSetup()
|
||||
|
||||
// Calibration data
|
||||
//uint16_t calData[5] = { 390, 3516, 253, 3520, 7 }; tft.setRotation(1); // Portrait
|
||||
uint16_t calData[5] = { 275, 3494, 361, 3528, 4 }; // tft.setRotation(0); // Portrait
|
||||
|
||||
#ifdef TFT_SHIELD
|
||||
uint16_t calData[5] = { 275, 3494, 361, 3528, 4 }; // tft.setRotation(0); // Portrait with TFT Shield
|
||||
Serial.println("Using TFT Shield");
|
||||
#else if defined(TFT_DIY)
|
||||
uint16_t calData[5] = { 339, 3470, 237, 3438, 2 }; // tft.setRotation(0); // Portrait with DIY TFT
|
||||
Serial.println("Using TFT DIY");
|
||||
#endif
|
||||
tft.setTouch(calData);
|
||||
|
||||
//tft.fillScreen(TFT_BLACK);
|
||||
|
||||
@@ -13,6 +13,8 @@
|
||||
|
||||
#include <TFT_eSPI.h>
|
||||
|
||||
#define TFT_SHIELD
|
||||
//#define TFT_DIY
|
||||
|
||||
#define SCREEN_WIDTH 240
|
||||
#define SCREEN_HEIGHT 320
|
||||
@@ -54,7 +56,7 @@ class Display
|
||||
TFT_eSPI tft = TFT_eSPI();
|
||||
TFT_eSprite img = TFT_eSprite(&tft);
|
||||
TFT_eSPI_Button key[BUTTON_ARRAY_LEN];
|
||||
String version_number = "v0.4.5";
|
||||
String version_number = "v0.4.6";
|
||||
|
||||
bool printing = false;
|
||||
bool loading = false;
|
||||
|
||||
@@ -129,7 +129,16 @@ void MenuFunctions::orientDisplay()
|
||||
|
||||
display_obj.tft.setCursor(0, 0);
|
||||
|
||||
uint16_t calData[5] = { 275, 3494, 361, 3528, 4 }; // tft.setRotation(0); // Portrait
|
||||
//uint16_t calData[5] = { 275, 3494, 361, 3528, 4 }; // tft.setRotation(0); // Portrait
|
||||
//uint16_t calData[5] = { 339, 3470, 237, 3438, 2 }; // tft.setRotation(0); // Portrait with DIY TFT
|
||||
|
||||
#ifdef TFT_SHIELD
|
||||
uint16_t calData[5] = { 275, 3494, 361, 3528, 4 }; // tft.setRotation(0); // Portrait with TFT Shield
|
||||
Serial.println("Using TFT Shield");
|
||||
#else if defined(TFT_DIY)
|
||||
uint16_t calData[5] = { 339, 3470, 237, 3438, 2 }; // tft.setRotation(0); // Portrait with DIY TFT
|
||||
Serial.println("Using TFT DIY");
|
||||
#endif
|
||||
|
||||
display_obj.tft.setTouch(calData);
|
||||
|
||||
|
||||
32
esp32_marauder/SDInterface.cpp
Normal file
32
esp32_marauder/SDInterface.cpp
Normal file
@@ -0,0 +1,32 @@
|
||||
#include "SDInterface.h"
|
||||
|
||||
bool SDInterface::initSD() {
|
||||
if (!SD.begin(SD_CS)) {
|
||||
Serial.println("Failed to mount SD Card");
|
||||
this->supported = false;
|
||||
return false;
|
||||
}
|
||||
else {
|
||||
this->supported = true;
|
||||
this->cardType = SD.cardType();
|
||||
if (cardType == CARD_MMC)
|
||||
Serial.println("SD: MMC Mounted");
|
||||
else if(cardType == CARD_SD)
|
||||
Serial.println("SD: SDSC Mounted");
|
||||
else if(cardType == CARD_SDHC)
|
||||
Serial.println("SD: SDHC Mounted");
|
||||
else
|
||||
Serial.println("SD: UNKNOWN Card Mounted");
|
||||
|
||||
this->cardSizeBT = SD.cardSize();
|
||||
this->cardSizeKB = SD.cardSize() / 1024;
|
||||
this->cardSizeMB = SD.cardSize() / (1024 * 1024);
|
||||
this->cardSizeGB = SD.cardSize() / (1024 * 1024 * 1024);
|
||||
|
||||
Serial.printf("SD Card Size: %llu Bytes\n", this->cardSizeBT);
|
||||
Serial.printf("SD Card Size: %lluKB\n", this->cardSizeKB);
|
||||
Serial.printf("SD Card Size: %lluMB\n", this->cardSizeMB);
|
||||
Serial.printf("SD Card Size: %lluGB\n", this->cardSizeGB);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
24
esp32_marauder/SDInterface.h
Normal file
24
esp32_marauder/SDInterface.h
Normal file
@@ -0,0 +1,24 @@
|
||||
#ifndef SDInterface_h
|
||||
#define SDInterface_h
|
||||
|
||||
#include "SD.h"
|
||||
|
||||
#define SD_CS 12
|
||||
|
||||
class SDInterface {
|
||||
|
||||
private:
|
||||
|
||||
public:
|
||||
uint8_t cardType;
|
||||
uint64_t cardSizeBT;
|
||||
uint64_t cardSizeKB;
|
||||
uint64_t cardSizeMB;
|
||||
uint64_t cardSizeGB;
|
||||
bool supported = false;
|
||||
|
||||
bool initSD();
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -245,6 +245,29 @@ void WiFiScan::RunInfo()
|
||||
display_obj.tft.println(" AP MAC: " + ap_mac);
|
||||
display_obj.tft.println(" " + free_ram);
|
||||
|
||||
if (sd_obj.supported) {
|
||||
display_obj.tft.println(" SD Card: Connected");
|
||||
display_obj.tft.print("SD Card Size: ");
|
||||
//display_obj.tft.println((byte)(sd_obj.cardSizeMB % 10));
|
||||
const int NUM_DIGITS = log10(sd_obj.cardSizeMB) + 1;
|
||||
|
||||
char sz[NUM_DIGITS + 1];
|
||||
|
||||
sz[NUM_DIGITS] = 0;
|
||||
for ( size_t i = NUM_DIGITS; i--; sd_obj.cardSizeMB /= 10)
|
||||
{
|
||||
sz[i] = '0' + (sd_obj.cardSizeMB % 10);
|
||||
}
|
||||
|
||||
display_obj.tft.print(sz);
|
||||
display_obj.tft.println("MB");
|
||||
|
||||
}
|
||||
else {
|
||||
display_obj.tft.println(" SD Card: Not Connected");
|
||||
display_obj.tft.print("SD Card Size: 0");
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -253,7 +276,13 @@ void WiFiScan::RunPacketMonitor(uint8_t scan_mode, uint16_t color)
|
||||
display_obj.tft.init();
|
||||
display_obj.tft.setRotation(1);
|
||||
display_obj.tft.fillScreen(TFT_BLACK);
|
||||
uint16_t calData[5] = { 391, 3491, 266, 3505, 7 };
|
||||
#ifdef TFT_SHIELD
|
||||
uint16_t calData[5] = { 391, 3491, 266, 3505, 7 }; // Landscape TFT Shield
|
||||
Serial.println("Using TFT Shield");
|
||||
#else if defined(TFT_DIY)
|
||||
uint16_t calData[5] = { 213, 3469, 320, 3446, 1 }; // Landscape TFT DIY
|
||||
Serial.println("Using TFT DIY");
|
||||
#endif
|
||||
display_obj.tft.setTouch(calData);
|
||||
|
||||
//display_obj.tft.setFreeFont(1);
|
||||
|
||||
@@ -7,9 +7,11 @@
|
||||
#include <BLEAdvertisedDevice.h>
|
||||
|
||||
#include <WiFi.h>
|
||||
#include <math.h>
|
||||
#include "esp_wifi.h"
|
||||
#include "esp_wifi_types.h"
|
||||
#include "Display.h"
|
||||
#include "SDInterface.h"
|
||||
//#include "MenuFunctions.h"
|
||||
|
||||
#define bad_list_length 3
|
||||
@@ -31,6 +33,7 @@
|
||||
#define MAX_CHANNEL 14
|
||||
|
||||
extern Display display_obj;
|
||||
extern SDInterface sd_obj;
|
||||
|
||||
esp_err_t esp_wifi_80211_tx(wifi_interface_t ifx, const void *buffer, int len, bool en_sys_seq);
|
||||
|
||||
|
||||
@@ -15,16 +15,19 @@ https://www.online-utility.org/image/convert/to/XBM
|
||||
#include "esp_system.h"
|
||||
#include <Arduino.h>
|
||||
|
||||
|
||||
#include "Assets.h"
|
||||
#include "Display.h"
|
||||
#include "WiFiScan.h"
|
||||
#include "MenuFunctions.h"
|
||||
#include "SDInterface.h"
|
||||
#include "Web.h"
|
||||
//#include "icons.h"
|
||||
|
||||
Display display_obj;
|
||||
WiFiScan wifi_scan_obj;
|
||||
MenuFunctions menu_function_obj;
|
||||
SDInterface sd_obj;
|
||||
Web web_obj;
|
||||
|
||||
uint32_t currentTime = 0;
|
||||
@@ -35,6 +38,10 @@ void setup()
|
||||
pinMode(FLASH_BUTTON, INPUT);
|
||||
pinMode(TFT_BL, OUTPUT);
|
||||
digitalWrite(TFT_BL, LOW);
|
||||
|
||||
// Preset SPI CS pins to avoid bus conflicts
|
||||
digitalWrite(TFT_CS, HIGH);
|
||||
digitalWrite(SD_CS, HIGH);
|
||||
|
||||
Serial.begin(115200);
|
||||
Serial.println("\n\n--------------------------------\n");
|
||||
@@ -43,6 +50,12 @@ void setup()
|
||||
Serial.println(" By: justcallmekoko\n");
|
||||
Serial.println("--------------------------------\n\n");
|
||||
|
||||
// Do some SD stuff
|
||||
if(sd_obj.initSD())
|
||||
Serial.println("SD Card supported");
|
||||
else
|
||||
Serial.println("SD Card NOT Supported");
|
||||
|
||||
// Run display setup
|
||||
display_obj.RunSetup();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user