Skip to content

Commit 3636802

Browse files
committed
headless update
1 parent 5b9ca6a commit 3636802

2 files changed

Lines changed: 39 additions & 5 deletions

File tree

src/headless.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,8 @@ void Headless_Thread(void *pvParameters)
1919
}
2020
}
2121

22-
void Headless_Setup(bool on)
22+
void Headless_Setup()
2323
{
24-
if (!on) return;
25-
2624
WiFi.mode(WIFI_AP_STA);
2725
WiFi.softAP("Pocket Puter", "deveclipse");
2826
MDNS.begin("pocketputer");

src/main.cpp

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include "rf/send.hpp"
2525

2626
#include "headless.h"
27+
#include "settings.h"
2728

2829
#include <LittleFS.h>
2930

@@ -48,8 +49,10 @@ Menu* active_menu = nullptr;
4849
void setup() {
4950
Serial.begin(115200);
5051

52+
bool display_found = true;
5153
if(!display.begin(SSD1306_SWITCHCAPVCC, 0X3C)) {
5254
Serial.println("SSD1306 allocation failed, force starting headless...");
55+
display_found = false;
5356
}
5457

5558
pinMode(BUZZER_PIN, OUTPUT);
@@ -102,13 +105,31 @@ void setup() {
102105
}
103106
}
104107

105-
Headless_Setup(true);
108+
if (!display_found)
109+
{
110+
Headless_Setup();
111+
}
112+
else
113+
{
114+
auto config = ReadConfig("/config.cfg");
115+
116+
if (config.find("headless") == config.end())
117+
config["headless"] = "0";
118+
119+
bool headless = config["headless"] == "1";
120+
121+
if (headless)
122+
{
123+
Headless_Setup();
124+
}
125+
}
106126

107127
menu.AddItem(MenuItem("WiFi", &menu_wifi));
108128
menu.AddItem(MenuItem("Bluetooth", &menu_bluetooth));
109129
menu.AddItem(MenuItem("Infrared", &menu_infrared));
110130
menu.AddItem(MenuItem("Radio", &menu_rf));
111131
menu.AddItem(MenuItem("Sound", &menu_sound));
132+
menu.AddItem(MenuItem("Settings", &menu_settings));
112133

113134
menu_wifi.AddItem(MenuItem("Scan", WiFi_Scan));
114135
menu_wifi.AddItem(MenuItem("Beacon Spam", WiFi_BeaconSpam));
@@ -136,6 +157,21 @@ void setup() {
136157
menu_sound.AddItem(MenuItem("Music", Music_Callback));
137158
menu_sound.AddItem(MenuItem("Piano", Piano_Callback));
138159

160+
menu_settings.AddItem(MenuItem("Headless", [](){
161+
auto config = ReadConfig("/config.cfg");
162+
bool current = config["headless"] == "1";
163+
bool next = !current;
164+
config["headless"] = next ? "1" : "0";
165+
WriteConfig("/config.cfg", config);
166+
167+
display.clearDisplay();
168+
Display_PrintCentered("Headless:\n%s", next ? "ON" : "OFF");
169+
display.display();
170+
171+
delay(500);
172+
ESP.restart();
173+
}));
174+
139175
menu.Revive(nullptr);
140176
active_menu = &menu;
141177
}
@@ -149,4 +185,4 @@ void loop() {
149185
if (next) active_menu = next;
150186

151187
active_menu->Render();
152-
}
188+
}

0 commit comments

Comments
 (0)