add a link between simulator and per pixel drv

This commit is contained in:
Tester23
2024-04-29 00:08:39 +02:00
parent d60876ee6d
commit 7aa735b7de
9 changed files with 116 additions and 8 deletions

View File

@ -1025,6 +1025,7 @@
<ClCompile Include="src\sim\Controller_Button.cpp" />
<ClCompile Include="src\sim\Controller_Pot.cpp" />
<ClCompile Include="src\sim\Controller_SimulatorLink.cpp" />
<ClCompile Include="src\sim\Controller_WS2812.cpp" />
<ClCompile Include="src\sim\CursorManager.cpp" />
<ClCompile Include="src\sim\Junction.cpp" />
<ClCompile Include="src\sim\Line.cpp" />
@ -1348,6 +1349,7 @@
<ClInclude Include="src\sim\Controller_Button.h" />
<ClInclude Include="src\sim\Controller_Pot.h" />
<ClInclude Include="src\sim\Controller_SimulatorLink.h" />
<ClInclude Include="src\sim\Controller_WS2812.h" />
<ClInclude Include="src\sim\CursorManager.h" />
<ClInclude Include="src\sim\Junction.h" />
<ClInclude Include="src\sim\Line.h" />

View File

@ -330,6 +330,7 @@
<ClCompile Include="src\driver\drv_freeze.c" />
<ClCompile Include="src\driver\drv_sm16703P.c" />
<ClCompile Include="src\selftest\selftest_ws2812b.c" />
<ClCompile Include="src\sim\Controller_WS2812.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="src\base64\base64.h" />
@ -481,6 +482,7 @@
<ClInclude Include="src\new_tokenizer.h" />
<ClInclude Include="src\ntp_time.h" />
<ClInclude Include="src\obk_config.h" />
<ClInclude Include="src\sim\Controller_WS2812.h" />
</ItemGroup>
<ItemGroup>
<CustomBuild Include="..\..\platforms\bk7231t\bk7231t_os\beken378\func\include\net_param_pub.h" />

View File

@ -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

View File

@ -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 {
TArray<class CShape *>shapes;
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__

View File

@ -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;
}

View File

@ -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);

View File

@ -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);
}
}
}

View File

@ -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;

View File

@ -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;
}