diff --git a/openBeken_win32_mvsc2017.vcxproj b/openBeken_win32_mvsc2017.vcxproj
index 049f207a6..411bbbfce 100644
--- a/openBeken_win32_mvsc2017.vcxproj
+++ b/openBeken_win32_mvsc2017.vcxproj
@@ -1025,6 +1025,7 @@
+
@@ -1348,6 +1349,7 @@
+
diff --git a/openBeken_win32_mvsc2017.vcxproj.filters b/openBeken_win32_mvsc2017.vcxproj.filters
index 4887a2635..f2e684d18 100644
--- a/openBeken_win32_mvsc2017.vcxproj.filters
+++ b/openBeken_win32_mvsc2017.vcxproj.filters
@@ -330,6 +330,7 @@
+
@@ -481,6 +482,7 @@
+
diff --git a/src/sim/Controller_WS2812.cpp b/src/sim/Controller_WS2812.cpp
new file mode 100644
index 000000000..f904a51de
--- /dev/null
+++ b/src/sim/Controller_WS2812.cpp
@@ -0,0 +1,56 @@
+#ifdef WINDOWS
+#include "Controller_WS2812.h"
+#include "Shape.h"
+#include "Junction.h"
+
+extern "C" {
+ bool SM16703P_GetPixel(uint32_t pixel, byte *dst);
+}
+
+void CControllerWS2812::setShapesActive(bool b) {
+ for (int i = 0; i < shapes.size(); i++) {
+ shapes[i]->setActive(b);
+ }
+}
+
+void CControllerWS2812::setShapesFillColor(const CColor &c) {
+ for (int i = 0; i < shapes.size(); i++) {
+ shapes[i]->setFillColor(c);
+ }
+}
+void CControllerWS2812::onDrawn() {
+ byte rgb[3];
+
+ CColor col_green(0, 255, 0);
+ int idx = a->getDepth();
+ if (b->getDepth() < idx)
+ idx = b->getDepth();
+ //printf("%i - depth %i\n", this, idx);
+ SM16703P_GetPixel(idx, rgb);
+ col_green.fromRGB(rgb);
+ setShapesActive(true);
+ setShapesFillColor(col_green);
+}
+class CJunction *CControllerWS2812::findOtherJunctionIfPassable(class CJunction *ju) {
+ if (ju == a)
+ return b;
+ return a;
+}
+class CControllerBase *CControllerWS2812::cloneController(class CShape *origOwner, class CShape *newOwner) {
+ CControllerWS2812 *r = new CControllerWS2812();
+ for (int i = 0; i < shapes.size(); i++) {
+ CShape *s = shapes[i];
+ const char *searchName = s->getName();
+ class CShape *newShape = newOwner->findShapeByName_r(searchName);
+ r->addShape(newShape);
+ }
+ if (a) {
+ r->a = newOwner->findShapeByName_r(a->getName())->asJunction();
+ }
+ if (b) {
+ r->b = newOwner->findShapeByName_r(b->getName())->asJunction();
+ }
+ return r;
+}
+
+#endif
diff --git a/src/sim/Controller_WS2812.h b/src/sim/Controller_WS2812.h
new file mode 100644
index 000000000..f0694615a
--- /dev/null
+++ b/src/sim/Controller_WS2812.h
@@ -0,0 +1,34 @@
+#ifndef __CONTROLLER_WS2812_H__
+#define __CONTROLLER_WS2812_H__
+
+#include "sim_local.h"
+#include "Controller_Base.h"
+#include "Coord.h"
+
+class CControllerWS2812 : public CControllerBase {
+ TArrayshapes;
+ class CJunction *a, *b;
+
+ void setShapesActive(bool b);
+ void setShapesFillColor(const CColor &c);
+public:
+ CControllerWS2812() {
+ a = b = 0;
+ }
+ CControllerWS2812(class CJunction *_a, class CJunction *_b) {
+ a = _a;
+ b = _b;
+ }
+ void setShape(CShape *p) {
+ shapes.clear();
+ shapes.push_back(p);
+ }
+ void addShape(CShape *p) {
+ shapes.push_back(p);
+ }
+ virtual void onDrawn();
+ virtual class CControllerBase *cloneController(class CShape *origOwner, class CShape *newOwner);
+ virtual class CJunction *findOtherJunctionIfPassable(class CJunction *ju);
+};
+
+#endif // __CONTROLLER_WS2812_H__
diff --git a/src/sim/Junction.h b/src/sim/Junction.h
index afd6672fa..9c8bee6c4 100644
--- a/src/sim/Junction.h
+++ b/src/sim/Junction.h
@@ -35,9 +35,10 @@ class CJunction : public CShape {
float duty;
int visitCount;
bool bCurrentSource;
+ int depth;
public:
CJunction() {
-
+ depth = 0;
}
CJunction(int _x, int _y, const char *s, int gpio = -1) {
this->setPosition(_x, _y);
@@ -47,6 +48,7 @@ public:
this->duty = 100;
this->visitCount = 0;
this->bCurrentSource = false;
+ this->depth = 0;
}
virtual ~CJunction();
virtual CShape *cloneShape();
@@ -74,6 +76,12 @@ public:
int getGPIO() const {
return gpioIndex;
}
+ int getDepth() const {
+ return this->depth;
+ }
+ void setDepth(int d) {
+ this->depth = d;
+ }
void setVoltage(float f) {
voltage = f;
}
diff --git a/src/sim/PrefabManager.cpp b/src/sim/PrefabManager.cpp
index 4de88ce7a..73e1e8211 100644
--- a/src/sim/PrefabManager.cpp
+++ b/src/sim/PrefabManager.cpp
@@ -8,6 +8,7 @@
#include "Controller_SimulatorLink.h"
#include "Controller_BL0942.h"
#include "Controller_Pot.h"
+#include "Controller_WS2812.h"
#include "Junction.h"
class CShape *PrefabManager::generateVDD() {
@@ -407,7 +408,7 @@ class CShape *PrefabManager::generateWS2812B() {
CJunction *b = o->addJunction(bulb_radius, 0);
b->setName("B");
b->addText(-25, -5, "");
- CControllerBulb *bulb = new CControllerBulb(a, b);
+ CControllerWS2812 *bulb = new CControllerWS2812(a, b);
o->setController(bulb);
filler->setName("internal_bulb_filler");
bulb->setShape(filler);
diff --git a/src/sim/Solver.cpp b/src/sim/Solver.cpp
index 718a79859..43995b52b 100644
--- a/src/sim/Solver.cpp
+++ b/src/sim/Solver.cpp
@@ -27,7 +27,7 @@ void CSolver::solveVoltages() {
}
}
// Idea: count steps to VDD/GND and use it to support multiple objects on line?
-void CSolver::floodJunctions(CJunction *ju, float voltage, float duty) {
+void CSolver::floodJunctions(CJunction *ju, float voltage, float duty, int depth) {
if (ju == 0)
return;
if (ju->getVisitCount() != 0)
@@ -35,20 +35,21 @@ void CSolver::floodJunctions(CJunction *ju, float voltage, float duty) {
ju->setVisitCount(1);
ju->setVoltage(voltage);
ju->setDuty(duty);
+ ju->setDepth(depth);
for (int i = 0; i < ju->getLinksCount(); i++) {
CJunction *other = ju->getLink(i);
- floodJunctions(other, voltage, duty);
+ floodJunctions(other, voltage, duty, depth);
}
for (int i = 0; i < ju->getEdgesCount(); i++) {
CEdge *e = ju->getEdge(i);
CJunction *o = e->getOther(ju);
- floodJunctions(o, voltage, duty);
+ floodJunctions(o, voltage, duty, depth);
}
CControllerBase *cntr = ju->findOwnerController_r();
if (cntr != 0) {
CJunction *other = cntr->findOtherJunctionIfPassable(ju);
if (other) {
- floodJunctions(other, voltage, duty);
+ floodJunctions(other, voltage, duty, depth+1);
}
}
}
diff --git a/src/sim/Solver.h b/src/sim/Solver.h
index 39a3af4dc..cfac8eea3 100644
--- a/src/sim/Solver.h
+++ b/src/sim/Solver.h
@@ -6,7 +6,7 @@
class CSolver {
class CSimulation *sim;
- void floodJunctions(class CJunction *ju, float voltage, float duty);
+ void floodJunctions(class CJunction *ju, float voltage, float duty, int depth = 0);
public:
void setSimulation(class CSimulation *p) {
sim = p;
diff --git a/src/sim/sim_local.h b/src/sim/sim_local.h
index 33aeea14a..e20f50666 100644
--- a/src/sim/sim_local.h
+++ b/src/sim/sim_local.h
@@ -148,7 +148,11 @@ public:
operator float*() {
return &r;
}
-
+ void fromRGB(const byte *rgb) {
+ r = (rgb[0]) / 255.0f;
+ g = (rgb[1]) / 255.0f;
+ b = (rgb[2]) / 255.0f;
+ }
operator const float *() const {
return &r;
}