Skip to content

Commit

Permalink
Added more comments
Browse files Browse the repository at this point in the history
  • Loading branch information
msraynsford committed Aug 12, 2018
1 parent 9029e53 commit 5b077f3
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 4 deletions.
3 changes: 3 additions & 0 deletions Source/APConfig/APConfig.ino
@@ -1,6 +1,9 @@
#include <ESP8266WiFi.h>
#include <ESP8266WebServer.h>

#define USESERIAL
#define USELED

#include "Config.h"
#include "FirmwareReset.h"
#include "AdminPage.h"
Expand Down
4 changes: 4 additions & 0 deletions Source/APConfig/AdminPage.h
@@ -1,6 +1,10 @@
// Creates an admin page on a webserver which allows the user to update the SSID and Password
// Performs basic checks to ensure that the input values are valid

#ifndef AdminPage_h
#define AdminPage_h

//Holds the admin webpage in the program memory
const char adminPage[] PROGMEM =
"<html>"
"<head>"
Expand Down
14 changes: 13 additions & 1 deletion Source/APConfig/Config.h
@@ -1,3 +1,6 @@
// Handles a class of data for storing variables, and the reading/writing of those variables to EEPROM
// It is able to detect invalid data being read from EEPROM and restore some basic values in those circumstances

#ifndef Config_H
#define Config_H

Expand All @@ -9,27 +12,33 @@
#define SSID_DEFAULT "APConfig"
#define PASS_DEFAULT "password"

// Define a structure to hold all the variables that are going to be stored in EEPROM
struct config_t{
char ssid[MAX_STR_LEN] = SSID_DEFAULT;
char pass[MAX_STR_LEN] = PASS_DEFAULT;
} config;

// Declare an area of EEPROM where the variables are stored
void InitConfig() {
// Declare an area of eeprom where the variables are stored
EEPROM.begin(sizeof(config));
}

// Writes the config values back to EEPROM
void SaveConfig() {
#ifdef USESERIAL
Serial.printf("Save Config\n");
#endif

// Store the new settings to EEPROM
EEPROM_writeAnything(0, config);
EEPROM.commit();
}

// Restores the values of SSID and Password if the EEPROM has been corrupted
void ResetConfig() {
#ifdef USESERIAL
Serial.printf("Reset Config\n");
#endif

// If the EEROM isn't valid then create a unique name for the wifi
sprintf(config.ssid, "%s %06X", SSID_DEFAULT, ESP.getChipId());
Expand All @@ -38,6 +47,7 @@ void ResetConfig() {
SaveConfig();
}

// Checks all of the bytes in the string array to make sure they are valid characters
bool ValidateString(char* value) {
bool valid = true;

Expand Down Expand Up @@ -82,8 +92,10 @@ void LoadConfig() {

// Sends a copy of the config values out to the serial port
void PrintConfig() {
#ifdef USESERIAL
Serial.printf("SSID: '%s'\n", config.ssid);
Serial.printf("Pass: '%s'\n", config.pass);
#endif
}

#endif
2 changes: 2 additions & 0 deletions Source/APConfig/EEPROMAnything.h
Expand Up @@ -4,6 +4,7 @@
#include <EEPROM.h>
#include <Arduino.h> // for type definitions

// Converts any class to a byte array for writing to EEPROM
template <class T> int EEPROM_writeAnything(int ee, const T& value)
{
const byte* p = (const byte*)(const void*)&value;
Expand All @@ -14,6 +15,7 @@ template <class T> int EEPROM_writeAnything(int ee, const T& value)
return i;
}

// Converts any class from a byte array for reading from EEPROM
template <class T> int EEPROM_readAnything(int ee, T& value)
{
byte* p = (byte*)(void*)&value;
Expand Down
3 changes: 0 additions & 3 deletions Source/APConfig/FirmwareReset.h
Expand Up @@ -6,9 +6,6 @@

#include <Ticker.h>

#define USESERIAL
#define USELED

#define FLAGSET 0x55555555
#define FLAGCLEAR 0xAAAAAAAA
#define FLAGADDRESS 00
Expand Down

0 comments on commit 5b077f3

Please sign in to comment.