2023-01-22 21:47:03 +00:00
|
|
|
#include <Arduino.h>
|
|
|
|
|
2023-11-23 07:02:12 +00:00
|
|
|
#include <Homie.h>
|
2023-02-08 19:17:58 +00:00
|
|
|
|
2023-11-23 07:02:12 +00:00
|
|
|
HomieNode flipdotNode("display", "Display", "display");
|
|
|
|
HomieNode resultNode("result", "Result", "result");
|
2023-02-08 19:17:58 +00:00
|
|
|
|
2023-01-31 21:50:25 +00:00
|
|
|
#include "flipdot.h"
|
2023-02-08 19:17:58 +00:00
|
|
|
#include "image.h"
|
2023-01-22 21:47:03 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2023-02-08 19:17:58 +00:00
|
|
|
Image flip;
|
2023-01-31 20:28:49 +00:00
|
|
|
|
2023-01-22 21:47:03 +00:00
|
|
|
unsigned long loopmillis=0;
|
|
|
|
unsigned long last_update=0;
|
2023-01-24 22:46:52 +00:00
|
|
|
|
2023-02-08 19:17:58 +00:00
|
|
|
|
2023-11-23 07:02:12 +00:00
|
|
|
bool presetHandler(const HomieRange& range, const String& value);
|
|
|
|
|
|
|
|
/*bool globalInputHandler(const HomieNode& node, const HomieRange& range, const String& property, const String& value) {
|
|
|
|
Homie.getLogger() << "Global input handler. Received on node " << node.getId() << ": " << property << " = " << value << endl;
|
|
|
|
return false;
|
|
|
|
}*/
|
|
|
|
|
|
|
|
|
2023-01-22 21:47:03 +00:00
|
|
|
|
|
|
|
void setup() {
|
2023-02-08 19:17:58 +00:00
|
|
|
flip.init();
|
2023-01-22 21:47:03 +00:00
|
|
|
|
|
|
|
Serial.begin(115200);
|
2023-09-20 17:22:59 +00:00
|
|
|
flip.setBuffer_solid(0);
|
|
|
|
|
2023-11-23 07:02:12 +00:00
|
|
|
//Setup Homie
|
|
|
|
Homie_setFirmware("flipdot", "0.1.0");
|
|
|
|
flipdotNode.advertise("preset").settable(presetHandler);
|
|
|
|
//Homie.setGlobalInputHandler(globalInputHandler);
|
|
|
|
Homie.setup();
|
|
|
|
|
2023-01-22 21:47:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void loop() {
|
2023-11-23 07:02:12 +00:00
|
|
|
Homie.loop();
|
2023-01-22 21:47:03 +00:00
|
|
|
loopmillis = millis();
|
2023-01-31 20:28:49 +00:00
|
|
|
|
2023-02-08 20:00:15 +00:00
|
|
|
static unsigned long last_change=0;
|
2023-11-23 07:02:12 +00:00
|
|
|
//static bool color=0;
|
2023-09-20 17:22:59 +00:00
|
|
|
|
2023-11-23 07:02:12 +00:00
|
|
|
if (loopmillis-last_change >= 1000*10)
|
|
|
|
{
|
|
|
|
flipdotNode.setProperty("preset").send("asdf");
|
|
|
|
last_change=loopmillis;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2023-09-20 17:22:59 +00:00
|
|
|
static uint8_t image=0;
|
|
|
|
if (loopmillis-last_change >= 1000*10)
|
2023-02-08 20:00:15 +00:00
|
|
|
{
|
2023-09-20 17:22:59 +00:00
|
|
|
|
2023-11-23 07:02:12 +00:00
|
|
|
//Serial.print("Change to Solid color ="); Serial.println(color);
|
|
|
|
|
|
|
|
//flip.setBuffer_solid(color);
|
|
|
|
//color=1-color;
|
|
|
|
|
2023-09-20 17:22:59 +00:00
|
|
|
|
|
|
|
|
2023-11-22 18:32:33 +00:00
|
|
|
|
2023-09-20 17:22:59 +00:00
|
|
|
switch (image){
|
|
|
|
case 0:
|
|
|
|
flip.setBuffer_Image1();
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
flip.setBuffer_Image2();
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
flip.setBuffer_Image3();
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
flip.setBuffer_Image4();
|
|
|
|
break;
|
|
|
|
|
2023-11-22 18:32:33 +00:00
|
|
|
case 4:
|
|
|
|
flip.setBuffer_Image5();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 5:
|
|
|
|
flip.setBuffer_Image6();
|
|
|
|
break;
|
|
|
|
case 6:
|
|
|
|
flip.setBuffer_Image7();
|
|
|
|
break;
|
|
|
|
case 7:
|
|
|
|
flip.setBuffer_Image8();
|
|
|
|
break;
|
|
|
|
|
2023-09-20 17:22:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
image++;
|
2023-11-22 18:32:33 +00:00
|
|
|
//image+=1+random(8-2);
|
|
|
|
image%=8;
|
2023-09-20 17:22:59 +00:00
|
|
|
|
|
|
|
|
2023-02-08 20:29:10 +00:00
|
|
|
|
2023-11-23 07:02:12 +00:00
|
|
|
|
|
|
|
//uint8_t _randomvalue=random(128);
|
|
|
|
//Serial.print("set buffer random. ");
|
|
|
|
//Serial.println(_randomvalue);
|
|
|
|
//flip.setBuffer_random(_randomvalue);
|
|
|
|
|
|
|
|
|
|
|
|
//for (uint8_t _x=0;_x<COLUMNS;_x++) {
|
|
|
|
// uint8_t _y=(sin( loopmillis/100000.0 + _x/5.0 )/2+0.5)*15+0.5;
|
|
|
|
// uint16_t _row=pow(2, _y);
|
|
|
|
// flip.setBufferColumn(_x,_row);
|
|
|
|
//}
|
|
|
|
|
2023-11-22 18:32:33 +00:00
|
|
|
|
2023-02-13 18:58:45 +00:00
|
|
|
|
|
|
|
|
2023-02-08 20:00:15 +00:00
|
|
|
|
|
|
|
last_change=loopmillis;
|
|
|
|
}
|
2023-11-23 07:02:12 +00:00
|
|
|
*/
|
2023-02-08 20:00:15 +00:00
|
|
|
|
2023-11-22 18:32:33 +00:00
|
|
|
|
|
|
|
UpdateReturn result=flip.updateByColumn(false,true,true); //0=not finished, 1=finished
|
|
|
|
//UpdateReturn result=flip.updateByColumn(true,false,false); //0=not finished, 1=finished <- most simple
|
2023-02-11 16:31:49 +00:00
|
|
|
if (result == finished) //just finished
|
2023-02-08 20:29:10 +00:00
|
|
|
{
|
|
|
|
unsigned long duration=millis()-last_change;
|
|
|
|
Serial.print("Last Change took "); Serial.print(duration); Serial.println(" ms");
|
|
|
|
Serial.print("Update max took "); Serial.print(flip.updateDuration); Serial.println(" ms");
|
2023-11-23 07:02:12 +00:00
|
|
|
resultNode.setProperty("duration").send((String)duration);
|
|
|
|
resultNode.setProperty("updateduration").send((String)flip.updateDuration);
|
2023-02-08 20:29:10 +00:00
|
|
|
flip.updateDuration=0; //reset
|
2023-02-11 17:51:33 +00:00
|
|
|
|
2023-11-22 18:32:33 +00:00
|
|
|
flip.shuffleOrder(10);
|
2023-02-08 20:29:10 +00:00
|
|
|
}
|
2023-01-22 21:47:03 +00:00
|
|
|
|
|
|
|
}
|
2023-11-23 07:02:12 +00:00
|
|
|
|
|
|
|
|
|
|
|
bool presetHandler(const HomieRange& range, const String& value) {
|
|
|
|
Serial.print("Received: "); Serial.println(value);
|
|
|
|
if (value == "white"){
|
|
|
|
flip.setBuffer_solid(1);
|
|
|
|
Homie.getLogger() << "Preset is White" << endl;
|
|
|
|
}else if(value == "black"){
|
|
|
|
flip.setBuffer_solid(0);
|
|
|
|
Homie.getLogger() << "Preset is Black" << endl;
|
|
|
|
}else if(value == "image1"){
|
|
|
|
flip.setBuffer_Image1();
|
|
|
|
Homie.getLogger() << "Preset is Image1" << endl;
|
|
|
|
}else if(value == "image2"){
|
|
|
|
flip.setBuffer_Image2();
|
|
|
|
Homie.getLogger() << "Preset is Image2" << endl;
|
|
|
|
}else if(value == "image3"){
|
|
|
|
flip.setBuffer_Image3();
|
|
|
|
Homie.getLogger() << "Preset is Image3" << endl;
|
|
|
|
}else if(value == "image4"){
|
|
|
|
flip.setBuffer_Image4();
|
|
|
|
Homie.getLogger() << "Preset is Image4" << endl;
|
|
|
|
}else if(value == "image5"){
|
|
|
|
flip.setBuffer_Image5();
|
|
|
|
Homie.getLogger() << "Preset is Image5" << endl;
|
|
|
|
}else if(value == "image6"){
|
|
|
|
flip.setBuffer_Image6();
|
|
|
|
Homie.getLogger() << "Preset is Image6" << endl;
|
|
|
|
}else if(value == "image7"){
|
|
|
|
flip.setBuffer_Image7();
|
|
|
|
Homie.getLogger() << "Preset is Image7" << endl;
|
|
|
|
}else if(value == "image8"){
|
|
|
|
flip.setBuffer_Image8();
|
|
|
|
Homie.getLogger() << "Preset is Image8" << endl;
|
|
|
|
}else{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
flipdotNode.setProperty("preset").send(value);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|