Skip to content
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
12 changes: 0 additions & 12 deletions .github/workflows/arduino-report.yml

This file was deleted.

54 changes: 0 additions & 54 deletions .github/workflows/arduino.yml

This file was deleted.

43 changes: 0 additions & 43 deletions .github/workflows/release.yml

This file was deleted.

54 changes: 0 additions & 54 deletions .github/workflows/static.yml

This file was deleted.

3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,6 @@ installer/firmware
dist
build
firmware.zip
bitcoinSwitch/config-*.h
bitcoinSwitch/bitcoinSwitch.ino.cpp
.github
134 changes: 134 additions & 0 deletions bitcoinSwitch/100_config.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
#include "100_config.h"

String config_ssid;
String config_password;
String config_device_string;

#ifdef HARDCODED
void setupConfig()
{
Serial.println("Setting hardcoded values...");
config_ssid = CONFIG_SSID;
Serial.println("SSID: " + config_ssid);
config_password = CONFIG_PASSWORD;
Serial.println("SSID password: " + config_password);
config_device_string = CONFIG_DEVICE_STRING;
Serial.println("Device string: " + config_device_string);

showWelcomeScreen();
}
#else
void setupConfig()
{
// first give the installer a chance to delete configuration file
executeConfigBoot();

showWelcomeScreen();

if (!readConfig())
{
// file does not exist, so we will enter endless config mode
Serial.println("Config file does not exist.");
executeSerialConfigForever();
}
}

bool readConfig()
{
Preferences preferences;
preferences.begin(CONFIG_NAME, true);

if (!preferences.isKey("ssid"))
{
config_ssid = CONFIG_SSID;
config_password = CONFIG_PASSWORD;
config_device_string = CONFIG_DEVICE_STRING;

preferences.end();
return false;
}

config_ssid = preferences.getString("ssid", CONFIG_SSID);
config_password = preferences.getString("password", CONFIG_PASSWORD);
config_device_string = preferences.getString("device_string", CONFIG_DEVICE_STRING);

preferences.end();
return true;
}

void executeConfigBoot()
{
Serial.println("Entering boot mode. Waiting for " + String(BOOTUP_TIMEOUT) + " seconds.");
clearTFT();
printTFT("BOOT MODE", 21, 21);

int counter = (BOOTUP_TIMEOUT + 1) * 10;
while (counter-- > 0)
{
#ifdef TOUCH_PIN
int val = touchRead(TOUCH_PIN);
Serial.println("Touch read value: " + String(val));
if (val < 60)
{
Serial.println("Touch detected");
executePortalConfig();
return;
}
#endif

#ifdef BT1_PIN
pinMode(BT1_PIN, INPUT_PULLUP);
if (digitalRead(BT1_PIN) == LOW)
{
Serial.println("Button pressed");
executePortalConfig();
return;
}
#endif

if (Serial.available() == 0)
{
delay(100);
continue;
}
Serial.println();
// if we get serial data in the first seconds, we will enter config mode
counter = 0;
executeSerialConfigForever();
return;
}

Serial.println("Exiting boot mode.");
}

void clearConfig()
{
Preferences preferences;
preferences.begin(CONFIG_NAME, false);
preferences.clear();
preferences.end();

readConfig();
}

void saveConfig()
{
Preferences preferences;
preferences.begin(CONFIG_NAME, false);

preferences.putString("ssid", config_ssid);
preferences.putString("password", config_password);
preferences.putString("device_string", config_device_string);

preferences.end();
}
#endif

void showWelcomeScreen()
{
Serial.print("Welcome to BitcoinSwitch!");
Serial.println(" (" + String(VERSION) + ")");
clearTFT();
printTFT("BitcoinSwitch", 21, 21);
printTFT(String(VERSION), 21, 42);
}
37 changes: 37 additions & 0 deletions bitcoinSwitch/100_config.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#pragma once

#define VERSION "v1.0.1"

#define BOOTUP_TIMEOUT 2 // seconds
#define CONFIG_NAME "config"

// uncomment if you dont want to use the configuration file
// #define HARDCODED

// device specific configuration / defaults
#define CONFIG_SSID "mywifi"
#define CONFIG_PASSWORD "mypw"
#define CONFIG_DEVICE_STRING ""

#include <Arduino.h>

#include "300_tft.h"
#ifndef HARDCODED
#include <Preferences.h>
#include "101_serial_config.h"
#include "102_portal_config.h"
#endif

extern String config_ssid;
extern String config_password;
extern String config_device_string;

void showWelcomeScreen();
void setupConfig();

#ifndef HARDCODED
bool readConfig();
void executeConfigBoot();
void clearConfig();
void saveConfig();
#endif
Loading