Working on adding a display.

This commit is contained in:
Kyle Isom 2023-10-07 02:29:08 -07:00
parent 802a6f6f52
commit 63faf519c1
10 changed files with 244 additions and 11 deletions

34
include/Display.h Normal file
View File

@ -0,0 +1,34 @@
#ifndef KIMODEM_DISPLAY_H
#define KIMODEM_DISPLAY_H
#include <Arduino.h>
#define ANSI_CLEAR_SCREEN "\33[2J"
/*
class Display {
public:
Display();
void Clear();
void Draw();
bool HasDisplay();
void Print(const char *);
void Println(const char *);
void SetCursor(int16_t x, int16_t y);
};
*/
#if defined(ADAFRUIT_OLED)
#include "internal/DisplayAdafruitOLED.h"
#else
#include "internal/DisplayNone.h"
#endif
static Display display;
#endif

View File

@ -0,0 +1,26 @@
#ifndef KIMODEM_ADAFRUIT_OLED_H
#define KIMODEM_ADAFRUIT_OLED_H
#include <Arduino.h>
#include <SPI.h>
#include <Wire.h>
#include <Adafruit_SSD1306.h>
class Display {
public:
Display();
void Clear();
void Draw();
bool HasDisplay();
void Print(const char *);
void Println(const char *);
void SetCursor(int16_t x, int16_t y);
private:
Adafruit_SSD1306 oled;
};
#endif

View File

@ -0,0 +1,20 @@
#ifndef KIMODEM_DISPLAY_SERIAL
#define KIMODEM_DISPLAY_SERIAL
#include <Arduino.h>
class Display {
public:
Display() {};
void Clear();
void Draw();
bool HasDisplay();
void Print(const char *);
void Println(const char *);
void SetCursor(int16_t x, int16_t y);
};
#endif

View File

@ -6,8 +6,8 @@ namespace config {
// Networking // Networking
size_t LastSSID(char *ssid); size_t LastSSID(char *ssid, size_t ssidlen);
void SetLastSSID(const char *ssid, size_t ssidlen); void SetLastSSID(const char *ssid);
bool StartTryConnecting(); bool StartTryConnecting();
void SetStartTryConnecting(bool opt); void SetStartTryConnecting(bool opt);

View File

@ -8,11 +8,34 @@
; Please visit documentation for the other options and examples ; Please visit documentation for the other options and examples
; https://docs.platformio.org/page/projectconf.html ; https://docs.platformio.org/page/projectconf.html
[platformio] [env]
[env:sparkfun_esp32micromod]
platform = espressif32
board = sparkfun_esp32micromod
framework = arduino framework = arduino
platform = espressif32
monitor_speed = 115200 monitor_speed = 115200
extra_scripts = scripts/download_fs.py extra_scripts = scripts/download_fs.py
[env:featheresp32]
board = featheresp32
build_flags =
; -DDISPLAY_NONE
-DADAFRUIT_OLED
lib_deps =
adafruit/Adafruit GFX Library@^1.11.8
adafruit/Adafruit SSD1306@^2.5.7
[env:sparkfun_esp32micromod]
board = sparkfun_esp32micromod
build_flags =
-DSPARKFUN_HYPERDISPLAY
-DDISPLAY_NONE
[env:d1mini]
board = wemos_d1_mini32
build_flags =
-DDISPLAY_NONE
[env:huzzah]
platform = espressif8266
board = huzzah
build_flags =
-DDISPLAY_NONE

View File

@ -0,0 +1,68 @@
#if defined(ADAFRUIT_OLED)
#include <Arduino.h>
#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include "internal/DisplayAdafruitOLED.h"
static Adafruit_SSD1306 oled(SSD1306_SWITCHCAPVCC, 0x3C);
Display::Display()
: oled(oled)
{
Serial.println("initialized display");
oled.setTextSize(1);
oled.setTextColor(SSD1306_WHITE);
}
void
Display::Clear()
{
this->oled.clearDisplay();
this->SetCursor(0, 0);
this->Draw();
}
void
Display::Draw()
{
this->oled.display();
}
bool
Display::HasDisplay()
{
return true;
}
void
Display::Print(const char *s)
{
this->oled.print(s);
}
void
Display::Println(const char *s)
{
this->oled.println(s);
}
void
Display::SetCursor(int16_t x, int16_t y)
{
this->oled.setCursor(x, y);
}
#endif

22
src/DisplayNone.cc Normal file
View File

@ -0,0 +1,22 @@
#if defined(NO_DISPLAY)
#include "Display.h"
#include "internal/DisplayNone.h"
void
Display::Clear()
{
Serial.println("\33[2J");
}
void Display::Draw() {}
bool Display::HasDisplay() { return false; }
void Display::Print(const char *s) {};
void Display::Println(const char *) {};
void Display::SetCursor(int16_t x, int16_t y) {};
#endif

View File

@ -3,9 +3,13 @@
#include <string.h> #include <string.h>
#include "Dictionary.h" #include "Dictionary.h"
#include "Display.h"
#include "TLV.h" #include "TLV.h"
#include "prefs.h"
#include "WiFiMgr.h" #include "WiFiMgr.h"
#define MAX_WAIT 10000 #define MAX_WAIT 10000
#define CONN_WAIT 250 #define CONN_WAIT 250
@ -37,6 +41,14 @@ tryConnect(const char *ssid, const char *wpakey)
if (WiFi.status() == WL_CONNECTED) { if (WiFi.status() == WL_CONNECTED) {
Serial.print("MODEM ADDR "); Serial.print("MODEM ADDR ");
Serial.println(WiFi.localIP()); Serial.println(WiFi.localIP());
display.Clear();
display.Print("SSID: ");
display.Println(ssid);
display.Print("IP: ");
display.Println(WiFi.localIP().toString().c_str());
display.Draw();
return true; return true;
} }
@ -52,6 +64,18 @@ TryConnect(Dictionary &pb)
TLV::Record wpakey; TLV::Record wpakey;
uint8_t *cursor; uint8_t *cursor;
if ((ssid.Len = config::LastSSID(ssid.Val, 32)) != 0) {
Serial.print("LAST SSID: ");
Serial.println(ssid.Val);
if (pb.Lookup(ssid.Val, ssid.Len, wpakey)) {
if (tryConnect((const char *)ssid.Val, (const char *)wpakey.Val)) {
return true;
}
} else {
Serial.println("WPAKEY NOT FOUND");
}
}
while ((cursor != NULL) && (cursor[0] != TAG_EMPTY)) { while ((cursor != NULL) && (cursor[0] != TAG_EMPTY)) {
TLV::ReadFromMemory(ssid, cursor); TLV::ReadFromMemory(ssid, cursor);
TLV::SkipRecord(ssid, cursor); TLV::SkipRecord(ssid, cursor);
@ -80,13 +104,15 @@ tryConnect(Dictionary &pb, int network)
} }
Serial.print("MODEM: CHECK "); Serial.print("MODEM: CHECK ");
Serial.println(ssid); Serial.print(ssid);
Serial.print(": ");
if (!pb.Lookup(ssid, uint8_t(ssidLen), password)) { if (!pb.Lookup(ssid, uint8_t(ssidLen), password)) {
Serial.println("SSID NOT IN PHONEBOOK"); Serial.println("NOT FOUND");
return false; return false;
} }
Serial.println("CONNECTING");
return tryConnect(ssid, password.Val); return tryConnect(ssid, password.Val);
} }

View File

@ -3,6 +3,7 @@
#include "Arena.h" #include "Arena.h"
#include "Dictionary.h" #include "Dictionary.h"
#include "Display.h"
#include "WiFiMgr.h" #include "WiFiMgr.h"
#include "prefs.h" #include "prefs.h"
#include "homenet.h" #include "homenet.h"
@ -33,6 +34,8 @@ setupPhonebook()
} }
pbFile.close(); pbFile.close();
config::SetLastSSID(HOME_SSID);
return ok; return ok;
} }
fileSize = fileSize > PHONEBOOK_SIZE ? PHONEBOOK_SIZE : fileSize; fileSize = fileSize > PHONEBOOK_SIZE ? PHONEBOOK_SIZE : fileSize;
@ -55,10 +58,14 @@ void setup() {
Serial.begin(115200); Serial.begin(115200);
while (!Serial) ; while (!Serial) ;
display.Clear();
Serial.println("MODEM BOOT"); Serial.println("MODEM BOOT");
InitializeArena(arena); InitializeArena(arena);
NewStaticArena(arena, phonebookBuffer, PHONEBOOK_SIZE); NewStaticArena(arena, phonebookBuffer, PHONEBOOK_SIZE);
while (true);
if (!SPIFFS.begin(true) && !SPIFFS.begin(false)) { if (!SPIFFS.begin(true) && !SPIFFS.begin(false)) {
Serial.println("SPIFFS BEGIN FAIL"); Serial.println("SPIFFS BEGIN FAIL");
while (true) ; while (true) ;
@ -71,7 +78,6 @@ void setup() {
} }
} }
Serial.println("MODEM READY"); Serial.println("MODEM READY");
} }

View File

@ -24,8 +24,16 @@ checkReady()
size_t size_t
LastSSID(char *ssid, size_t ssidlen) LastSSID(char *ssid, size_t ssidlen)
{ {
size_t len;
checkReady(); checkReady();
return preferences.getString("SSID", ssid, ssidlen); len = preferences.getString("SSID", ssid, ssidlen);
if (len > 0) {
// preferences.getString includes the null byte in
// the result. c.f. DQTNA.
len--;
}
return len;
} }