Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PixelCount and OLED Display #48

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
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
6 changes: 5 additions & 1 deletion ESPixelStick.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ const char BUILD_DATE[] = __DATE__;
#endif

#include "EffectEngine.h"
#include "OLEDEngine.h"

#define HTTP_PORT 80 /* Default web server port */
#define MQTT_PORT 1883 /* Default MQTT port */
Expand Down Expand Up @@ -80,7 +81,8 @@ enum class DataSource : uint8_t {
E131,
MQTT,
WEB,
IDLEWEB
IDLEWEB,
CP
};

// Configuration structure
Expand All @@ -89,6 +91,7 @@ typedef struct {
String id; /* Device ID */
DevCap devmode; /* Used for reporting device mode, not stored */
DataSource ds; /* Used to track current data source, not stored */
DataSource prevds; /* Previous ds in case of Pixel Count */


/* Network */
Expand Down Expand Up @@ -178,6 +181,7 @@ void dsDeviceConfig(JsonObject &json);
void dsEffectConfig(JsonObject &json);
void saveConfig();
void dsGammaConfig(JsonObject &json);
void dsPixelCount(JsonObject &json);

void connectWifi();
void onWifiConnect(const WiFiEventStationModeGotIP &event);
Expand Down
78 changes: 72 additions & 6 deletions ESPixelStick.ino
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ const char passphrase[] = "ENTER_PASSPHRASE_HERE";
#include <SPI.h>
#include "ESPixelStick.h"
#include "EFUpdate.h"
#include "OLEDDisplay.h"
#include "wshandler.h"
#include "gamma.h"
#include "udpraw.h"
Expand Down Expand Up @@ -109,6 +110,7 @@ EffectEngine effects; // Effects Engine
Ticker sendTimer;
UdpRaw udpraw;


// Output Drivers
#if defined(ESPS_MODE_PIXEL)
PixelDriver pixels; // Pixel object
Expand Down Expand Up @@ -138,6 +140,13 @@ RF_PRE_INIT() {
}

void setup() {
// Enable SPIFFS
SPIFFS.begin();
#if defined(ESPS_SUPPORT_OLED)
initDisplay();
showDisplay("dee_boot","Starting up...");
#endif //ESPS_SUPPORT_OLED

// Configure SDK params
wifi_set_sleep_type(NONE_SLEEP_T);
setupWebGpio();
Expand All @@ -153,9 +162,9 @@ void setup() {
ets_install_putc1((void *) &_u0_putc);
system_set_os_print(1);
#endif

// Enable SPIFFS
SPIFFS.begin();
#if defined(ESPS_SUPPORT_OLED)
showDisplay("dee_boot","Loading configuration...");
#endif //ESPS_SUPPORT_OLED

// Set default data source to E131
config.ds = DataSource::E131;
Expand Down Expand Up @@ -232,6 +241,9 @@ void setup() {
// If we fail again, go SoftAP or reboot
if (WiFi.status() != WL_CONNECTED) {
if (config.ap_fallback) {
#if defined(ESPS_SUPPORT_OLED)
showDisplay("dee_boot","Starting SoftAP...");
#endif //ESPS_SUPPORT_OLED
LOG_PORT.println(F("*** FAILED TO ASSOCIATE WITH AP, GOING SOFTAP ***"));
WiFi.mode(WIFI_AP);
String ssid = "ESPixelBoard " + String(config.hostname);
Expand Down Expand Up @@ -276,7 +288,6 @@ void setup() {
#if defined(ESPS_ENABLE_BUTTONS)
setupButtons();
#endif

}

/////////////////////////////////////////////////////////
Expand Down Expand Up @@ -315,7 +326,13 @@ void connectWifi() {
WiFi.begin(config.ssid.c_str(), config.passphrase.c_str());
if (config.dhcp) {
LOG_PORT.print(F("Connecting with DHCP"));
#if defined(ESPS_SUPPORT_OLED)
showDisplay("dee_boot","Connecting to " + config.ssid + " with DHCP");
#endif //ESPS_SUPPORT_OLED
} else {
#if defined(ESPS_SUPPORT_OLED)
showDisplay("dee_boot","Connecting to " + config.ssid + " with Static IP");
#endif //ESPS_SUPPORT_OLED
// We don't use DNS, so just set it to our gateway
WiFi.config(IPAddress(config.ip[0], config.ip[1], config.ip[2], config.ip[3]),
IPAddress(config.gateway[0], config.gateway[1], config.gateway[2], config.gateway[3]),
Expand All @@ -330,7 +347,7 @@ void onWifiConnect(__attribute__ ((unused)) const WiFiEventStationModeGotIP &eve
LOG_PORT.println("");
LOG_PORT.print(F("Connected with IP: "));
LOG_PORT.println(WiFi.localIP());

// showDisplay("dee_boot","Connected to " + config.ssid + " with IP" + WiFi.localIP());
// Setup MQTT connection if enabled
if (config.mqtt)
connectToMqtt();
Expand Down Expand Up @@ -676,6 +693,9 @@ void initWeb() {

// Raw config file Handler - but only on station
// web.serveStatic("/config.json", SPIFFS, "/config.json").setFilter(ON_STA_FILTER);
// Raw config file Handler
web.serveStatic("/config.json", SPIFFS, "/config.json");
web.serveStatic("/display.json", SPIFFS, "/display.json");

web.onNotFound([](AsyncWebServerRequest *request) {
if (request->method() == HTTP_OPTIONS) {
Expand Down Expand Up @@ -1215,6 +1235,43 @@ void dsGammaConfig(JsonObject &json) {
}
#endif

void dsPixelCount(JsonObject &json) {
if (json.containsKey("pixelcount")) {
JsonObject& pcjson = json["pixelcount"];
uint16_t ptcount = pcjson["count"];
int cmdtype = pcjson["commandtype"].as<int>();
int channelLength = (ptcount * 3);
switch (cmdtype)
{
case 0: {/* init pixel count by setting pixelc count to max */
config.prevds = config.ds;
config.ds = DataSource::CP;
pixels.begin(config.pixel_type, config.pixel_color, 680); // set pixels to max
// break;
}
case 1: {/* render pixels per UI */

// effects.clearAll(); does not work for max length, manually clear all
for (int i = channelLength; i < 2040; i++) {
pixels.setValue(i, 0);
}
for (int i = 0; i < channelLength; i++) {
pixels.setValue(i, 255);
}
break;
}
case 2: {/* closed the pixel count UI hence reset pixel config.
/* code */
for (int i = channelLength; i < 2040; i++) {
pixels.setValue(i, 0);
}
config.ds = config.prevds;
pixels.begin(config.pixel_type, config.pixel_color, config.channel_count / 3); // reset pixels count per current config
break;
}
}
}
}
// Save configuration JSON file
void saveConfig() {
// Update Config
Expand Down Expand Up @@ -1254,7 +1311,6 @@ void idleTimeout() {
//
/////////////////////////////////////////////////////////
void loop() {

/* check for rotary encoder and buttons */
#if defined(ESPS_ENABLE_BUTTONS)
handleButtons();
Expand Down Expand Up @@ -1375,6 +1431,16 @@ void loop() {
}

MDNS.update();
//Show Display
#if defined(ESPS_SUPPORT_OLED)
if (config.ds == DataSource::WEB || config.ds == DataSource::IDLEWEB){
showDisplay("dee_idle","");
} else if (config.ds == DataSource::MQTT) {
showDisplay("dee_mqtt","");
} else if (config.ds == DataSource::E131) {
showDisplay("dee_e131","");
}
#endif //ESPS_SUPPORT_OLED
}

void resolveHosts() {
Expand Down
2 changes: 1 addition & 1 deletion EffectEngine.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ struct dCHSV {
*/
typedef uint16_t (EffectEngine::*EffectFunc)(void);
struct EffectDesc {
String name;
String name;
EffectFunc func;
const char* htmlid;
bool hasColor;
Expand Down
3 changes: 3 additions & 0 deletions Mode.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,7 @@
/* Enable support for udpraw packets on port 2801 */
#define ESPS_ENABLE_UDPRAW

/* Enable OLED Display */
#define ESPS_SUPPORT_OLED

#endif // MODE_H_
Loading