Skip to content

Commit

Permalink
Add initial SD support
Browse files Browse the repository at this point in the history
  • Loading branch information
justcallmekoko committed Mar 5, 2020
1 parent eccbaae commit 5b24257
Show file tree
Hide file tree
Showing 8 changed files with 123 additions and 4 deletions.
9 changes: 8 additions & 1 deletion esp32_marauder/Display.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 3 additions & 1 deletion esp32_marauder/Display.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@

#include <TFT_eSPI.h>

#define TFT_SHIELD
//#define TFT_DIY

#define SCREEN_WIDTH 240
#define SCREEN_HEIGHT 320
Expand Down Expand Up @@ -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;
Expand Down
11 changes: 10 additions & 1 deletion esp32_marauder/MenuFunctions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
32 changes: 32 additions & 0 deletions esp32_marauder/SDInterface.cpp
Original file line number Diff line number Diff line change
@@ -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 changes: 24 additions & 0 deletions esp32_marauder/SDInterface.h
Original file line number Diff line number Diff line change
@@ -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
31 changes: 30 additions & 1 deletion esp32_marauder/WiFiScan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}


}

Expand All @@ -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);
Expand Down
3 changes: 3 additions & 0 deletions esp32_marauder/WiFiScan.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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);

Expand Down
13 changes: 13 additions & 0 deletions esp32_marauder/esp32_marauder.ino
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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");
Expand All @@ -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();

Expand Down

0 comments on commit 5b24257

Please sign in to comment.