Working on adding a display.
This commit is contained in:
68
src/DisplayAdafruitOLED.cc
Normal file
68
src/DisplayAdafruitOLED.cc
Normal 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
22
src/DisplayNone.cc
Normal 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
|
||||
@@ -3,9 +3,13 @@
|
||||
#include <string.h>
|
||||
|
||||
#include "Dictionary.h"
|
||||
#include "Display.h"
|
||||
#include "TLV.h"
|
||||
#include "prefs.h"
|
||||
|
||||
#include "WiFiMgr.h"
|
||||
|
||||
|
||||
#define MAX_WAIT 10000
|
||||
#define CONN_WAIT 250
|
||||
|
||||
@@ -37,6 +41,14 @@ tryConnect(const char *ssid, const char *wpakey)
|
||||
if (WiFi.status() == WL_CONNECTED) {
|
||||
Serial.print("MODEM ADDR ");
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -52,6 +64,18 @@ TryConnect(Dictionary &pb)
|
||||
TLV::Record wpakey;
|
||||
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)) {
|
||||
TLV::ReadFromMemory(ssid, cursor);
|
||||
TLV::SkipRecord(ssid, cursor);
|
||||
@@ -80,13 +104,15 @@ tryConnect(Dictionary &pb, int network)
|
||||
}
|
||||
|
||||
Serial.print("MODEM: CHECK ");
|
||||
Serial.println(ssid);
|
||||
Serial.print(ssid);
|
||||
Serial.print(": ");
|
||||
|
||||
if (!pb.Lookup(ssid, uint8_t(ssidLen), password)) {
|
||||
Serial.println("SSID NOT IN PHONEBOOK");
|
||||
Serial.println("NOT FOUND");
|
||||
return false;
|
||||
}
|
||||
|
||||
Serial.println("CONNECTING");
|
||||
return tryConnect(ssid, password.Val);
|
||||
}
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
|
||||
#include "Arena.h"
|
||||
#include "Dictionary.h"
|
||||
#include "Display.h"
|
||||
#include "WiFiMgr.h"
|
||||
#include "prefs.h"
|
||||
#include "homenet.h"
|
||||
@@ -33,6 +34,8 @@ setupPhonebook()
|
||||
}
|
||||
|
||||
pbFile.close();
|
||||
config::SetLastSSID(HOME_SSID);
|
||||
|
||||
return ok;
|
||||
}
|
||||
fileSize = fileSize > PHONEBOOK_SIZE ? PHONEBOOK_SIZE : fileSize;
|
||||
@@ -55,10 +58,14 @@ void setup() {
|
||||
Serial.begin(115200);
|
||||
while (!Serial) ;
|
||||
|
||||
display.Clear();
|
||||
|
||||
Serial.println("MODEM BOOT");
|
||||
InitializeArena(arena);
|
||||
NewStaticArena(arena, phonebookBuffer, PHONEBOOK_SIZE);
|
||||
|
||||
while (true);
|
||||
|
||||
if (!SPIFFS.begin(true) && !SPIFFS.begin(false)) {
|
||||
Serial.println("SPIFFS BEGIN FAIL");
|
||||
while (true) ;
|
||||
@@ -71,7 +78,6 @@ void setup() {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Serial.println("MODEM READY");
|
||||
}
|
||||
|
||||
|
||||
10
src/prefs.cc
10
src/prefs.cc
@@ -24,8 +24,16 @@ checkReady()
|
||||
size_t
|
||||
LastSSID(char *ssid, size_t ssidlen)
|
||||
{
|
||||
size_t len;
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user