Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable easier inclusion in other projects #583

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions esp32_marauder/CommandLine.h
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,9 @@ class CommandLine {
LinkedList<String> parseCommand(String input, char* delim);
String toLowerCase(String str);
void filterAccessPoints(String filter);
#ifndef ENABLE_NONSERIAL_COMMAND_EXECUTION
void runCommand(String input);
#endif
bool checkValueExists(LinkedList<String>* cmd_args_list, int index);
bool inRange(int max, int index);
bool apSelected();
Expand Down Expand Up @@ -191,6 +193,9 @@ class CommandLine {

void RunSetup();
void main(uint32_t currentTime);
#ifdef ENABLE_NONSERIAL_COMMAND_EXECUTION
void runCommand(String input);
#endif
};

#endif
2 changes: 2 additions & 0 deletions esp32_marauder/GpsInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#ifndef GpsInterface_h
#define GpsInterface_h

#ifdef HAS_GPS
#include <MicroNMEA.h>
#include <SoftwareSerial.h>
#include <LinkedList.h>
Expand Down Expand Up @@ -120,3 +121,4 @@ class GpsInterface {
};

#endif
#endif
10 changes: 9 additions & 1 deletion esp32_marauder/LedInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ LedInterface::LedInterface() {

void LedInterface::RunSetup() {
//Serial.println("Setting neopixel to black...");
#ifndef DISABLE_STATUS_LED
strip.setBrightness(0);
strip.begin();
strip.setPixelColor(0, strip.Color(0, 0, 0));
Expand All @@ -15,6 +16,7 @@ void LedInterface::RunSetup() {
strip.setPixelColor(0, strip.Color(0, 0, 0));
strip.show();
this->initTime = millis();
#endif
}

void LedInterface::main(uint32_t currentTime) {
Expand Down Expand Up @@ -50,8 +52,10 @@ uint8_t LedInterface::getMode() {
}

void LedInterface::setColor(int r, int g, int b) {
#ifndef DISABLE_STATUS_LED
strip.setPixelColor(0, strip.Color(r, g, b));
strip.show();
strip.show();
#endif
}

void LedInterface::sniffLed() {
Expand All @@ -67,6 +71,7 @@ void LedInterface::ledOff() {
}

void LedInterface::rainbow() {
#ifndef DISABLE_STATUS_LED
strip.setPixelColor(0, this->Wheel((0 * 256 / 100 + this->wheel_pos) % 256));
strip.show();

Expand All @@ -75,9 +80,11 @@ void LedInterface::rainbow() {
this->wheel_pos = this->wheel_pos - this->wheel_speed;
if (this->wheel_pos < 0)
this->wheel_pos = 255;
#endif
}

uint32_t LedInterface::Wheel(byte WheelPos) {
#ifndef DISABLE_STATUS_LED
WheelPos = 255 - WheelPos;
if(WheelPos < 85) {
return strip.Color(255 - WheelPos * 3, 0, WheelPos * 3);
Expand All @@ -88,4 +95,5 @@ uint32_t LedInterface::Wheel(byte WheelPos) {
}
WheelPos -= 170;
return strip.Color(WheelPos * 3, 255 - WheelPos * 3, 0);
#endif
}
6 changes: 6 additions & 0 deletions esp32_marauder/LedInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@
#include "configs.h"
#include "settings.h"
#include <Arduino.h>

#ifndef DISABLE_STATUS_LED
#include <Adafruit_NeoPixel.h>
#endif

#define Pixels 1

Expand All @@ -17,7 +20,10 @@
#define MODE_CUSTOM 4

extern Settings settings_obj;

#ifndef DISABLE_STATUS_LED
extern Adafruit_NeoPixel strip;
#endif

class LedInterface {

Expand Down
3 changes: 1 addition & 2 deletions esp32_marauder/SDInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@


bool SDInterface::initSD() {
#ifdef HAS_SD
#if defined HAS_SD && !defined USE_SD_MMC_INTERFACE
String display_string = "";

#ifdef KIT
Expand Down Expand Up @@ -86,7 +86,6 @@ bool SDInterface::initSD() {

return true;
}

#else
Serial.println("SD support disabled, skipping init");
return false;
Expand Down
8 changes: 7 additions & 1 deletion esp32_marauder/SDInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,13 @@
#include "configs.h"

#include "settings.h"
#include "SD.h"
#ifdef USE_SD_MMC_INTERFACE
#include "SD_MMC.h"
#define SD SD_MMC
#else
#include "SD.h"
#endif

#include "Buffer.h"
#ifdef HAS_SCREEN
#include "Display.h"
Expand Down
1 change: 1 addition & 0 deletions esp32_marauder/WiFiScan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ extern "C" int ieee80211_raw_frame_sanity_check(int32_t arg, int32_t arg2, int32
extern "C" {
uint8_t esp_base_mac_addr[6];
esp_err_t esp_ble_gap_set_rand_addr(const uint8_t *rand_addr);
esp_err_t esp_base_mac_addr_set(const uint8_t *addr);
}

#ifdef HAS_BT
Expand Down
2 changes: 0 additions & 2 deletions esp32_marauder/WiFiScan.h
Original file line number Diff line number Diff line change
Expand Up @@ -208,8 +208,6 @@ class WiFiScan
"08 and hurt you"
};

char* prefix = "G";

typedef struct
{
int16_t fctl;
Expand Down
46 changes: 42 additions & 4 deletions esp32_marauder/settings.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,43 @@
#include "settings.h"

#define DEFAULT_SETTING_FILE "/settings.json"

String Settings::getSettingsString() {
return this->json_settings_string;
}

bool Settings::begin(fs::FS fs, String filename) {
Serial.println("in maurader setting");
if (!fs.exists(filename))
{
Serial.println("not exist creating default");
if (!this->createDefaultSettings(fs, filename))
{
return false;
}
}

Serial.println("opening file setting");
File settingsFile = fs.open(filename, FILE_READ);
if (!settingsFile)
{
Serial.println("file bad");
return false;
}

Serial.println("deserialising setting");

String json_string;
DynamicJsonDocument jsonBuffer(1024);
DeserializationError error = deserializeJson(jsonBuffer, settingsFile);
serializeJson(jsonBuffer, json_string);
this->json_settings_string = json_string;

Serial.println("finish maurader setting");

return true;
}

bool Settings::begin() {
if(!SPIFFS.begin(FORMAT_SPIFFS_IF_FAILED)){
Serial.println("Settings SPIFFS Mount Failed");
Expand All @@ -12,10 +46,10 @@ bool Settings::begin() {

File settingsFile;

//SPIFFS.remove("/settings.json"); // NEED TO REMOVE THIS LINE
//SPIFFS.remove(DEFAULT_SETTING_FILE); // NEED TO REMOVE THIS LINE

if (SPIFFS.exists("/settings.json")) {
settingsFile = SPIFFS.open("/settings.json", FILE_READ);
if (SPIFFS.exists(DEFAULT_SETTING_FILE)) {
settingsFile = SPIFFS.open(DEFAULT_SETTING_FILE, FILE_READ);

if (!settingsFile) {
settingsFile.close();
Expand Down Expand Up @@ -240,9 +274,13 @@ void Settings::printJsonSettings(String json_string) {
}

bool Settings::createDefaultSettings(fs::FS &fs) {
createDefaultSettings(fs, DEFAULT_SETTING_FILE);
}

bool Settings::createDefaultSettings(fs::FS &fs, String filename) {
Serial.println(F("Creating default settings file: settings.json"));

File settingsFile = fs.open("/settings.json", FILE_WRITE);
File settingsFile = fs.open(filename, FILE_WRITE);

if (!settingsFile) {
Serial.println(F("Failed to create settings file"));
Expand Down
2 changes: 2 additions & 0 deletions esp32_marauder/settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class Settings {

public:
bool begin();
bool begin(fs::FS fs, String filename);

template <typename T>
T loadSetting(String name);
Expand All @@ -50,6 +51,7 @@ class Settings {

String getSettingsString();
bool createDefaultSettings(fs::FS &fs);
bool createDefaultSettings(fs::FS &fs, String filename);
void printJsonSettings(String json_string);
void main(uint32_t currentTime);
};
Expand Down
Loading