now running led stuff on core 2, and autodetection of ports

This commit is contained in:
Kevin Santo Cappuccio 2023-07-08 09:04:30 -07:00
parent 3c9b6b5273
commit ae8c46155d
10 changed files with 723 additions and 257 deletions

View File

@ -34,20 +34,35 @@ lastDiagram = 1
print("\n\r")
while portSelected == False:
autodetected = -1
ports = serial.tools.list_ports.comports()
i = 0
for port, desc, hwid in ports:
i = i + 1
print("{}: {} [{}]".format(i, port, desc))
selection = input ("\n\n\rSelect the port connected to your Jumperless ('r' to rescan)\n\n\r")
#selection = "3"
if selection.isdigit() == True and int(selection) <= i:
portName = ports[int(selection) - 1].device
portSelected = True
if desc == "Jumperless":
autodetected = i
selection = -1
if autodetected != -1:
selection = autodetected
print ("\n\n\rAutodetected Jumperless at",end=" ")
print(ports[int(selection) - 1].device)
portName = ports[int(selection) - 1].device
portSelected = True
serialconnected = 1
else:
selection = input ("\n\n\rSelect the port connected to your Jumperless ('r' to rescan)\n\n\r")
#selection = "3"
if selection.isdigit() == True and int(selection) <= i:
portName = ports[int(selection) - 1].device
portSelected = True
print(ports[int(selection) - 1].device)
serialconnected = 1
#print(0 in ports)

View File

@ -0,0 +1,56 @@
{
"build": {
"arduino": {
"earlephilhower": {
"variant": "rpipico",
"boot2_source": "boot2_w25q080_2_padded_checksum.S",
"usb_vid": "0x2e8a",
"usb_pid": "0x000a",
"usb_manufacturer": "Architeuthis Flux",
"usb_product": "Jumperless"
}
},
"core": "arduino",
"cpu": "cortex-m0plus",
"extra_flags": "-D ARDUINO_RASPBERRY_PI_PICO -DARDUINO_ARCH_RP2040 -DUSBD_MAX_POWER_MA=500",
"f_cpu": "133000000L",
"hwids": [
[
"0x2E8A",
"0x00C0"
]
],
"mcu": "rp2040",
"variant": "RASPBERRY_PI_PICO"
},
"debug": {
"jlink_device": "RP2040_M0_0",
"openocd_target": "rp2040.cfg",
"svd_path": "rp2040.svd"
},
"frameworks": [
"arduino"
],
"name": "Jumperless",
"upload": {
"maximum_ram_size": 270336,
"maximum_size": 2097152,
"require_upload_port": true,
"native_usb": true,
"use_1200bps_touch": true,
"wait_for_upload_port": false,
"protocol": "picotool",
"protocols": [
"blackmagic",
"cmsis-dap",
"jlink",
"raspberrypi-swd",
"picotool",
"picoprobe"
]
},
"description": "A jumperless breadboard",
"url": "https://github.com/Architeuthis-Flux/Jumperless",
"vendor": "Architeuthis Flux"
}

View File

@ -13,9 +13,9 @@ platform = https://github.com/maxgerhardt/platform-raspberrypi.git
framework = arduino
board_build.core = earlephilhower
board_build.filesystem_size = 0.5m
upload_port = /dev/cu.usbmodem11301
monitor_port = /dev/cu.usbmodem11301
extra_scripts = post:scripts/extra_script.py
;upload_port = /dev/cu.usbmodem11701 ;leave these out, the script will find the port
;monitor_port = /dev/cu.usbmodem11701
extra_scripts = pre:scripts/find_Jumperless_upload.py, post:scripts/extra_script.py
monitor_speed = 256000
[env:pico]

View File

@ -1,12 +1,50 @@
Import("env")
#import serial
#env = DefaultEnvironment()
def find_jumperless_port_monitor(source, target, env):
import serial.tools.list_ports
#print(env.dump())
while True:
autodetected = -1
ports = serial.tools.list_ports.comports()
i = 0
for port, desc, hwid in ports:
#print("{}: {} [{}]".format(i, port, desc))
if desc == "Jumperless":
autodetected = i
i = i + 1
if autodetected != -1:
selection = autodetected
env.Replace(MONITOR_PORT=ports[selection][0])
#env.Replace(UPLOAD_PORT=ports[selection][0])
#env.Replace("monitor_port", ports[selection][0])
#env.ConfigEnvOption(env, "monitor_port", ports[selection][0])
print("Autodetected jumperless port: " + ports[selection][0])
return ports[selection][0]
def after_upload(source, target, env):
port = env.GetProjectOption("monitor_port")
#port = env.GetProjectOption("monitor_port")
port = find_jumperless_port_monitor(source, target, env)
print("waiting for " + port + " ...")
import serial
while True:
try:
s = serial.Serial(port)
#env.dump()
break
except:
pass

View File

@ -0,0 +1,30 @@
Import("env")
def find_jumperless_port_upload(source, target, env):
import serial
import serial.tools.list_ports
autodetected = -1
ports = serial.tools.list_ports.comports()
i = 0
for port, desc, hwid in ports:
print("{}: {} [{}]".format(i, port, desc))
if desc == "Jumperless":
autodetected = i
i = i + 1
if autodetected != -1:
selection = autodetected
env.Replace(MONITOR_PORT=ports[selection][0])
env.Replace(UPLOAD_PORT=ports[selection][0])
#(env, "monitor_port", ports[selection][0])
# ConfigEnvOption(env, "upload_port", ports[selection][0])
print("Autodetected jumperless port: " + ports[selection][0])
env.AddPreAction("upload", find_jumperless_port_upload)

View File

@ -224,9 +224,20 @@ void sendPath(int i, int setOrClear)
{
continue;
}
// delayMicroseconds(800);
// netNumberC2 = path[i].net;
// onOffC2 = setOrClear;
// nodeC2 = path[i].node1;
// lightUpNetCore2 = 1;
lightUpNet(path[i].net, path[i].node1, setOrClear,255);
lightUpNet(path[i].net, path[i].node2, setOrClear,255);
// delayMicroseconds(800);
// nodeC2 = path[i].node2;
// lightUpNetCore2 = 1;
lightUpNet(path[i].net, path[i].node1, setOrClear);
lightUpNet(path[i].net, path[i].node2, setOrClear);
chYdata = path[i].y[chip];
chXdata = path[i].x[chip];

View File

@ -2,6 +2,14 @@
#define CH446Q_H
extern int netNumberC2;
extern int onOffC2;
extern int nodeC2;
extern int brightnessC2;
extern int hueShiftC2;
extern int lightUpNetCore2;
void initCH446Q(void);
void sendAllPaths(void); // should we sort them by chip? for now, no

View File

@ -4,9 +4,6 @@
#include "MatrixStateRP2040.h"
#include "fileParsing.h"
Adafruit_NeoPixel leds(LED_COUNT, LED_PIN, NEO_GRB + NEO_KHZ800);
rgbColor netColors[MAX_NETS] = {0};
@ -16,34 +13,37 @@ uint8_t brightness = BRIGHTNESS;
int showLEDsCore2 = 0;
int netNumberC2 = 0;
int onOffC2 = 0;
int nodeC2 = 0;
int brightnessC2 = 0;
int hueShiftC2 = 0;
int lightUpNetCore2 = 0;
#ifdef EEPROMSTUFF
#include <EEPROM.h>
bool debugLEDs = 1; //EEPROM.read(DEBUG_LEDSADDRESS);
bool debugLEDs = 1; // EEPROM.read(DEBUG_LEDSADDRESS);
#else
bool debugLEDs = 1;
#else
bool debugLEDs = 1;
#endif
rgbColor specialNetColors[8] =
{{00, 00, 00},
{0x00, 0xFF, 0x30},
{0xFF, 0x41, 0x14},
{0xFF, 0x10, 0x40},
{0xeF, 0x78, 0x7a},
{0xeF, 0x40, 0x7f},
{0xFF, 0xff, 0xff},
{0xff, 0xFF, 0xff}};
rgbColor specialNetColors[8] =
{{00, 00, 00},
{0x00, 0xFF, 0x30},
{0xFF, 0x41, 0x14},
{0xFF, 0x10, 0x40},
{0xeF, 0x78, 0x7a},
{0xeF, 0x40, 0x7f},
{0xFF, 0xff, 0xff},
{0xff, 0xFF, 0xff}};
rgbColor railColors[4] =
{
{0xFF, 0x41, 0x14},
{0x00, 0xFF, 0x30},
{0xFF, 0x00, 0x40},
{0x00, 0xFF, 0x30}};
rgbColor railColors[4] =
{
{0xFF, 0x41, 0x14},
{0x00, 0xFF, 0x30},
{0xFF, 0x00, 0x40},
{0x00, 0xFF, 0x30}};
void initLEDs(void)
{
@ -53,67 +53,24 @@ void initLEDs(void)
debugLEDs = 1;
}
EEPROM.write(DEBUG_LEDSADDRESS, debugLEDs);
EEPROM.commit();
delay(80);
pinMode(LED_PIN, OUTPUT);
delay(2);
delay(20);
leds.begin(); // INITIALIZE NeoPixel strip object (REQUIRED)
delay(2);
delay(20);
showLEDsCore2 = 1; // Turn OFF all pixels ASAP
delay(4);
delay(40);
leds.setBrightness(BRIGHTNESS);
}
void colorWipe(uint32_t color, int wait)
{
for (int i = 0; i < leds.numPixels(); i++)
{ // For each pixel in strip...
leds.setPixelColor(i, color); // Set pixel's color (in RAM)
showLEDsCore2 = 1; // Update strip to match
delay(wait); // Pause for a moment
}
}
void rainbowy(int saturation, int brightness, int wait)
{
for (long firstPixelHue = 0; firstPixelHue < 5 * 65536; firstPixelHue += 256)
{
// strip.rainbow() can take a single argument (first pixel hue) or
// optionally a few extras: number of rainbow repetitions (default 1),
// saturation and value (brightness) (both 0-255, similar to the
// ColorHSV() function, default 255), and a true/false flag for whether
// to apply gamma correction to provide 'truer' colors (default true).
leds.rainbow(firstPixelHue, 1, saturation, brightness, true);
// Above line is equivalent to:
// strip.rainbow(firstPixelHue, 1, 255, 255, true);
showLEDsCore2 = 1;// Update strip with new contents
delay(wait); // Pause for a moment
}
}
void clearLEDs(void)
{
for (int i = 0; i < 60; i++)
{ // For each pixel in strip...
leds.setPixelColor(i, 0); // Set pixel's color (in RAM)
// Update strip to match
}
showLEDsCore2 = 1;
delay(20);
EEPROM.commit();
delay(100);
}
void assignNetColors(void)
{
// numberOfNets = 60;
uint16_t colorDistance = (255 / (numberOfNets-2));
uint16_t colorDistance = (255 / (numberOfNets - 2));
/* rgbColor specialNetColors[8] =
{0x000000,
@ -126,49 +83,62 @@ void assignNetColors(void)
0xC8FFC8};
*/
if (debugLEDs)
{
Serial.print("\n\rcolorDistance: ");
Serial.print(colorDistance);
Serial.print("\n\r");
Serial.print("numberOfNets: ");
Serial.print(numberOfNets);
Serial.print("\n\rassigning net colors\n\r");
Serial.print("\n\rNet\t\tR\tG\tB\t\tH\tS\tV");
delay(3);
}
if (debugLEDs)
{
Serial.print("\n\rcolorDistance: ");
Serial.print(colorDistance);
Serial.print("\n\r");
Serial.print("numberOfNets: ");
Serial.print(numberOfNets);
Serial.print("\n\rassigning net colors\n\r");
Serial.print("\n\rNet\t\tR\tG\tB\t\tH\tS\tV");
}
delay(6);
for (int i = 0; i < 8; i++)
{
hsvColor netHsv = RgbToHsv(specialNetColors[i]);
netHsv.v = SPECIALNETBRIGHTNESS;
rgbColor netRgb = HsvToRgb(netHsv);
specialNetColors[i] = netRgb;
netColors[i] = specialNetColors[i];
net[i].color = netColors[i];
if (debugLEDs)
{
Serial.print("\n\r");
Serial.print(net[i].name);
Serial.print("\t");
Serial.print(net[i].color.r, HEX);
Serial.print("\t");
Serial.print(net[i].color.g, HEX);
Serial.print("\t");
Serial.print(net[i].color.b, HEX);
Serial.print("\t\t");
Serial.print(netHsv.h);
Serial.print("\t");
Serial.print(netHsv.s);
Serial.print("\t");
Serial.print(netHsv.v);
delay(3);
}
{
Serial.print("\n\r");
Serial.print(net[i].name);
Serial.print("\t");
Serial.print(net[i].color.r, HEX);
Serial.print("\t");
Serial.print(net[i].color.g, HEX);
Serial.print("\t");
Serial.print(net[i].color.b, HEX);
Serial.print("\t\t");
Serial.print(netHsv.h);
Serial.print("\t");
Serial.print(netHsv.s);
Serial.print("\t");
Serial.print(netHsv.v);
}
delay(10);
}
for (int i = 0; i < 5; i++)
{
for (int j = 0; j < 4; j++)
{
hsvColor netHsv = RgbToHsv(railColors[j]);
uint32_t color = packRgb(railColors[j].r, railColors[j].g, railColors[j].b);
netHsv.v = RAILBRIGHTNESS;
rgbColor netRgb = HsvToRgb(netHsv);
uint32_t color = packRgb(netRgb.r, netRgb.g, netRgb.b); // packRgb(railColors[j].r, railColors[j].g, railColors[j].b);
leds.setPixelColor(railsToPixelMap[j][i], color); // top positive rail
}
@ -182,7 +152,7 @@ if (debugLEDs)
*/
}
showLEDsCore2 = 1;
delay(2);
int skipSpecialColors = 0;
uint8_t hue = 8;
@ -195,7 +165,7 @@ if (debugLEDs)
int foundColor = 0;
for (uint8_t hueScan = hue+(colorDistance/4) ; hueScan <= 254; hueScan += (colorDistance))
for (uint8_t hueScan = hue + (colorDistance / 4); hueScan <= 254; hueScan += (colorDistance))
{
for (int k = 0; k < 8; k++)
{
@ -203,7 +173,7 @@ if (debugLEDs)
if (hueScan > snColor.h)
{
if (hueScan - snColor.h < colorDistance/2)
if (hueScan - snColor.h < colorDistance / 2)
{
skipSpecialColors = 1;
// Serial.print("skipping special color: ");
@ -213,7 +183,7 @@ if (debugLEDs)
break;
}
}
else if (snColor.h - hueScan < colorDistance/2)
else if (snColor.h - hueScan < colorDistance / 2)
{
skipSpecialColors = 1;
// continue;
@ -244,7 +214,7 @@ if (debugLEDs)
if (i == numberOfNets && foundColor == 0)
{
//hueScan = 0;
// hueScan = 0;
}
}
if (foundColor == 0)
@ -260,39 +230,36 @@ if (debugLEDs)
net[i].color.g = netColors[i].g;
net[i].color.b = netColors[i].b;
if (debugLEDs)
{
Serial.print("\n\r");
Serial.print(net[i].name);
Serial.print("\t\t");
Serial.print(net[i].color.r, DEC);
Serial.print("\t");
Serial.print(net[i].color.g, DEC);
Serial.print("\t");
Serial.print(net[i].color.b, DEC);
Serial.print("\t\t");
Serial.print(hue);
Serial.print("\t");
Serial.print(saturation);
Serial.print("\t");
Serial.print(brightness);
delay(3);
}
{
Serial.print("\n\r");
Serial.print(net[i].name);
Serial.print("\t\t");
Serial.print(net[i].color.r, DEC);
Serial.print("\t");
Serial.print(net[i].color.g, DEC);
Serial.print("\t");
Serial.print(net[i].color.b, DEC);
Serial.print("\t\t");
Serial.print(hue);
Serial.print("\t");
Serial.print(saturation);
Serial.print("\t");
Serial.print(brightness);
}
delay(3);
}
}
uint32_t packRgb(uint8_t r, uint8_t g, uint8_t b)
{
return (uint32_t)r << 16 | (uint32_t)g << 8 | b;
}
void lightUpNet(int netNumber, int node, int onOff , int brightness2, int hueShift)
void lightUpNet(int netNumber, int node, int onOff, int brightness2, int hueShift)
{
if (net[netNumber].nodes[1] != 0 && net[netNumber].nodes[1] < 62)
if (net[netNumber].nodes[1] != 0 && net[netNumber].nodes[1] < 121)
{
for (int j = 0; j < MAX_NODES; j++)
@ -301,27 +268,52 @@ void lightUpNet(int netNumber, int node, int onOff , int brightness2, int hueShi
{
break;
}
if (net[netNumber].nodes[j] < 62)
if (net[netNumber].nodes[j] < 121)
{
if (net[netNumber].nodes[j] == node || node == -1)
{
if (onOff == 1)
{
uint32_t color;
if (hueShift != 0)
int pcbExtinction = 0;
int colorCorrection = 0;
int pcbHueShift = 0;
if (net[netNumber].nodes[j] >= NANO_D0 && net[netNumber].nodes[j] <= NANO_A7)
{
struct rgbColor colorToShift = {net[netNumber].color.r, net[netNumber].color.g, net[netNumber].color.b};
struct rgbColor shiftedColor = shiftHue(colorToShift, hueShift);
color = packRgb((shiftedColor.r * brightness2) >> 8, (shiftedColor.g * brightness2) >> 8, (shiftedColor.b * brightness2) >> 8);
} else {
color = packRgb((net[netNumber].color.r * brightness2) >> 8, (net[netNumber].color.g * brightness2) >> 8, (net[netNumber].color.b * brightness2) >> 8);
}
pcbExtinction = PCBEXTINCTION;
// hueShift += PCBHUESHIFT;
colorCorrection = 1;
}
struct rgbColor colorToShift = {net[netNumber].color.r, net[netNumber].color.g, net[netNumber].color.b};
struct rgbColor shiftedColor = shiftHue(colorToShift, hueShift, pcbExtinction, 254);
if (colorCorrection != 0)
{
shiftedColor = pcbColorCorrect(shiftedColor);
}
color = packRgb(shiftedColor.r, shiftedColor.g, shiftedColor.b);
/*
Serial.print("color: ");
Serial.print(color,HEX);
Serial.print(" r: ");
Serial.print(shiftedColor.r);
Serial.print(" g: ");
Serial.print(shiftedColor.g);
Serial.print(" b: ");
Serial.print(shiftedColor.b);
Serial.print(" hueShift: ");
Serial.print(hueShift);
Serial.print(" pcbExtinction: ");
Serial.print(pcbExtinction);
Serial.print(" brightness2: ");
Serial.println(brightness2);
*/
leds.setPixelColor(nodesToPixelMap[net[netNumber].nodes[j]], color);
}
else
@ -333,76 +325,293 @@ void lightUpNet(int netNumber, int node, int onOff , int brightness2, int hueShi
}
showLEDsCore2 = 1;
}
}
struct rgbColor shiftHue (struct rgbColor colorToShift, int hueShift)
struct rgbColor pcbColorCorrect(rgbColor colorToShift)
{
uint8_t redShift = 0;
uint8_t greenShift = 0;
uint8_t blueShift = 0;
int testNeg = 0;
struct rgbColor colorToShiftRgb = colorToShift;
struct hsvColor colorToShiftHsv = RgbToHsv(colorToShiftRgb);
if (colorToShiftHsv.h > 100 && colorToShiftHsv.h < 150)
{
// Serial.print("hue: ");
// Serial.print(colorToShiftHsv.h);
// Serial.print("\tcolorToShift.r: ");
// Serial.print(colorToShift.r);
// Serial.print("\tcolorToShift.g: ");
// Serial.print(colorToShift.g);
// Serial.print("\tcolorToShift.b: ");
// Serial.print(colorToShift.b);
if (PCBREDSHIFTBLUE < 0)
{
testNeg = colorToShiftRgb.r;
testNeg -= abs(PCBREDSHIFTBLUE);
if (testNeg < 0)
{
colorToShiftRgb.r = 0;
}
else
{
colorToShiftRgb.r = colorToShiftRgb.r - abs(PCBREDSHIFTBLUE);
}
}
else
{
colorToShiftRgb.r = colorToShiftRgb.r + abs(PCBREDSHIFTBLUE);
if (colorToShiftRgb.r > 254)
{
colorToShiftRgb.r = 254;
}
}
if (PCBGREENSHIFTBLUE < 0)
{
testNeg = colorToShiftRgb.g;
testNeg -= abs(PCBGREENSHIFTBLUE);
if (testNeg < 0)
{
colorToShiftRgb.g = 0;
}
else
{
colorToShiftRgb.g = colorToShiftRgb.g - abs(PCBGREENSHIFTBLUE);
}
}
else
{
colorToShiftRgb.g = colorToShiftRgb.g + abs(PCBGREENSHIFTBLUE);
if (colorToShiftRgb.g > 254)
{
colorToShiftRgb.g = 254;
}
}
if (PCBBLUESHIFTBLUE < 0)
{
testNeg = colorToShiftRgb.b;
testNeg -= abs(PCBBLUESHIFTBLUE);
if (testNeg < 0)
{
colorToShiftRgb.b = 0;
}
else
{
colorToShiftRgb.b = colorToShiftRgb.b - abs(PCBBLUESHIFTBLUE);
}
}
else
{
colorToShiftRgb.b = colorToShiftRgb.b + abs(PCBBLUESHIFTBLUE);
if (colorToShiftRgb.b > 254)
{
colorToShiftRgb.b = 254;
}
}
// Serial.print("\t\tShifted.r: ");
// Serial.print(colorToShiftRgb.r);
// Serial.print("\tShifted.g: ");
// Serial.print(colorToShiftRgb.g);
// Serial.print("\tShifted.b: ");
// Serial.println(colorToShiftRgb.b);
// Serial.print("\n\n\r");
}
else if (colorToShiftHsv.h >= 150 && colorToShiftHsv.h < 255)
{
// Serial.print("hue: ");
// Serial.print(colorToShiftHsv.h);
// Serial.print("\tcolorToShift.r: ");
// Serial.print(colorToShift.r);
// Serial.print("\tcolorToShift.g: ");
// Serial.print(colorToShift.g);
// Serial.print("\tcolorToShift.b: ");
// Serial.print(colorToShift.b);
if (PCBREDSHIFTPINK < 0)
{
testNeg = colorToShiftRgb.r;
testNeg -= abs(PCBREDSHIFTPINK);
if (testNeg < 0)
{
colorToShiftRgb.r = 0;
}
else
{
colorToShiftRgb.r = colorToShiftRgb.r - abs(PCBREDSHIFTPINK);
}
}
else
{
colorToShiftRgb.r = colorToShiftRgb.r + abs(PCBREDSHIFTPINK);
if (colorToShiftRgb.r > 254)
{
colorToShiftRgb.r = 254;
}
}
if (PCBGREENSHIFTPINK < 0)
{
testNeg = colorToShiftRgb.g;
testNeg -= abs(PCBGREENSHIFTPINK);
if (testNeg < 0)
{
colorToShiftRgb.g = 0;
}
else
{
colorToShiftRgb.g = colorToShiftRgb.g - abs(PCBGREENSHIFTPINK);
}
}
else
{
colorToShiftRgb.g = colorToShiftRgb.g + abs(PCBGREENSHIFTPINK);
if (colorToShiftRgb.g > 254)
{
colorToShiftRgb.g = 254;
}
}
if (PCBBLUESHIFTPINK < 0)
{
testNeg = colorToShiftRgb.b;
testNeg -= abs(PCBBLUESHIFTPINK);
if (testNeg < 0)
{
colorToShiftRgb.b = 0;
}
else
{
colorToShiftRgb.b = colorToShiftRgb.b - abs(PCBBLUESHIFTPINK);
}
}
else
{
colorToShiftRgb.b = colorToShiftRgb.b + abs(PCBBLUESHIFTPINK);
if (colorToShiftRgb.b > 254)
{
colorToShiftRgb.b = 254;
}
}
}
return colorToShiftRgb;
}
struct rgbColor shiftHue(struct rgbColor colorToShift, int hueShift, int brightnessShift, int saturationShift)
{
struct hsvColor colorToShiftHsv = RgbToHsv(colorToShift);
struct hsvColor colorToShiftHsv = RgbToHsv(colorToShift);
colorToShiftHsv.h = colorToShiftHsv.h + hueShift;
colorToShiftHsv.s = colorToShiftHsv.s + saturationShift;
colorToShiftHsv.v = colorToShiftHsv.v + brightnessShift;
if (colorToShiftHsv.v > 255)
{
colorToShiftHsv.v = 255;
}
colorToShiftHsv.h = colorToShiftHsv.h + hueShift;
if (colorToShiftHsv.s > 255)
{
colorToShiftHsv.s = 255;
}
if (colorToShiftHsv.h > 255)
{
colorToShiftHsv.h = colorToShiftHsv.h - 255;
if (colorToShiftHsv.h > 255)
{
colorToShiftHsv.h = colorToShiftHsv.h - 255;
}
struct rgbColor colorToShiftRgb = HsvToRgb(colorToShiftHsv);
return colorToShiftRgb;
}
struct rgbColor colorToShiftRgb = HsvToRgb(colorToShiftHsv);
return colorToShiftRgb;
}
void lightUpNode(int node)
{
leds.setPixelColor(nodesToPixelMap[node], 0xffffff);
uint32_t randColor = random(0, 0xffffff);
leds.setPixelColor(node, (randColor));
showLEDsCore2 = 1;
delay(2000);
leds.setPixelColor(node, 0);
}
void lightUpRail(int rail, int onOff, int brightness2)
{
for (int j = 0; j < 4; j++)
{
if (j == rail || rail == -1)
{
for (int i = 0; i < 5; i++)
{
if (onOff == 1)
{
uint32_t color = packRgb((railColors[j].r * brightness2) >> 8, (railColors[j].g * brightness2) >> 8, (railColors[j].b * brightness2) >> 8);
//Serial.println(color,HEX);
leds.setPixelColor(railsToPixelMap[j][i], color);
}
else
{
leds.setPixelColor(railsToPixelMap[j][i], 0);
}
}
}
}
showLEDsCore2 = 1;
delay(1);
leds.setPixelColor(110, 0xaa0011);
leds.setPixelColor(83, packRgb((railColors[1].r * brightness2) >> 8, (railColors[1].g * brightness2) >> 8, (railColors[1].b * brightness2) >> 8));
leds.setPixelColor(108, packRgb((railColors[1].r * brightness2) >> 8, (railColors[1].g * brightness2) >> 8, (railColors[1].b * brightness2) >> 8));
leds.setPixelColor(109, packRgb((railColors[0].r * brightness2) >> 8, (railColors[0].g * brightness2) >> 8, (railColors[0].b * brightness2) >> 8));
leds.setPixelColor(96, packRgb((railColors[2].r * brightness2) >> 8, (railColors[2].g * brightness2) >> 8, (railColors[2].b * brightness2) >> 8));
leds.setPixelColor(106, packRgb((railColors[0].r * brightness2) >> 8, (railColors[0].g * brightness2) >> 8, (railColors[0].b * brightness2) >> 8));
for (int j = 0; j < 4; j++)
{
if (j == rail || rail == -1)
{
for (int i = 0; i < 5; i++)
{
if (onOff == 1)
{
uint32_t color = packRgb((railColors[j].r * brightness2) >> 8, (railColors[j].g * brightness2) >> 8, (railColors[j].b * brightness2) >> 8);
// Serial.println(color,HEX);
leds.setPixelColor(railsToPixelMap[j][i], color);
}
else
{
leds.setPixelColor(railsToPixelMap[j][i], 0);
}
}
}
}
showLEDsCore2 = 1;
delay(3);
}
void showNets(void)
@ -513,4 +722,56 @@ hsvColor RgbToHsv(rgbColor rgb)
hsv.h = 171 + 43 * (rgb.r - rgb.g) / (rgbMax - rgbMin);
return hsv;
}
void colorWipe(uint32_t color, int wait)
{
for (int i = 0; i < leds.numPixels(); i++)
{ // For each pixel in strip...
leds.setPixelColor(i, color); // Set pixel's color (in RAM)
showLEDsCore2 = 1; // Update strip to match
delay(wait); // Pause for a moment
}
}
void rainbowy(int saturation, int brightness, int wait)
{
for (long firstPixelHue = 0; firstPixelHue < 5 * 65536; firstPixelHue += 256)
{
// strip.rainbow() can take a single argument (first pixel hue) or
// optionally a few extras: number of rainbow repetitions (default 1),
// saturation and value (brightness) (both 0-255, similar to the
// ColorHSV() function, default 255), and a true/false flag for whether
// to apply gamma correction to provide 'truer' colors (default true).
leds.rainbow(firstPixelHue, 1, saturation, brightness, true);
// Above line is equivalent to:
// strip.rainbow(firstPixelHue, 1, 255, 255, true);
showLEDsCore2 = 1; // Update strip with new contents
delay(wait); // Pause for a moment
}
}
void clearLEDs(void)
{
for (int i = 0; i <= LED_COUNT; i++)
{ // For each pixel in strip...
leds.setPixelColor(i, 0); // Set pixel's color (in RAM)
// Update strip to match
}
lightUpRail(-1,1);
// for (int i = 80; i <= 109; i++)
// { // For each pixel in strip...
// if (nodesToPixelMap[i] > NANO_D0 && nodesToPixelMap[i] < NANO_A7)
// {
// leds.setPixelColor(i, 0); // Set pixel's color (in RAM)
// }
// // leds.setPixelColor(i, 0); // Set pixel's color (in RAM)
// // Update strip to match
// }
showLEDsCore2 = 1;
}

View File

@ -7,8 +7,34 @@
#include "NetsToChipConnections.h"
#define LED_PIN 25
#define LED_COUNT 80
#define BRIGHTNESS 120
#define LED_COUNT 111
#define BRIGHTNESS 50
#define RAILBRIGHTNESS 55
#define SPECIALNETBRIGHTNESS 60
// #define PCBEXTINCTION 0 //extra brightness for to offset the extinction through pcb
#define PCBREDSHIFTBLUE -25 //extra hue shift to offset the hue shift through pcb
#define PCBGREENSHIFTBLUE -25
#define PCBBLUESHIFTBLUE 42
#define PCBEXTINCTION 0 //extra brightness for to offset the extinction through pcb
#define PCBREDSHIFTPINK -18 //extra hue shift to offset the hue shift through pcb
#define PCBGREENSHIFTPINK -25
#define PCBBLUESHIFTPINK 35
// #define PCBEXTINCTION 0 //extra brightness for to offset the extinction through pcb
// #define PCBREDSHIFTBLUE 0 //extra hue shift to offset the hue shift through pcb
// #define PCBGREENSHIFTBLUE 0
// #define PCBBLUESHIFTBLUE 0
// #define PCBEXTINCTION 0 //extra brightness for to offset the extinction through pcb
// #define PCBREDSHIFTPINK 0 //extra hue shift to offset the hue shift through pcb
// #define PCBGREENSHIFTPINK 0
// #define PCBBLUESHIFTPINK 0
// #define PCBHUESHIFT 0
extern Adafruit_NeoPixel leds;
extern bool debugLEDs;
@ -32,11 +58,35 @@ typedef struct hsvColor
unsigned char v;
} hsvColor;
const int nodesToPixelMap[69] = { 0, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,
30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61};
const int numbers[120] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,
31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,
61,62,63,64,65,66,67,68,69,
70,71,72,73,74,75,76,77,78,79,
80,81,82,83,84,85,86,87,88,89,
90,91,92,93,94,95,96,97,98,99,
100,101,102,103,104,105,106,107,108,109,
110,111,112,113,114,115,116,117,118,119};
const int nodesToPixelMap[120] = { 0, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,
30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,
0,0,0,0,0,0,0,
81,80,84,85,86,87,88,89,90,91,92,93,94,
95,82,97,98,99,100,101,102,103,104,105,106,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
};
const int bbPixelToNodesMap[120] = { 1, 2, 3, 4, 5, 6, 7, 8, 9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,
32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,
0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,
NANO_D1, NANO_D0, NANO_RESET, GND, NANO_D2, NANO_D3, NANO_D4, NANO_D5, NANO_D6, NANO_D7, NANO_D8, NANO_D9, NANO_D10, NANO_D11, NANO_D12,
NANO_D13, SUPPLY_3V3, NANO_AREF, NANO_A0, NANO_A1, NANO_A2, NANO_A3, NANO_A4, NANO_A5, NANO_A6, NANO_A7, SUPPLY_5V, NANO_RESET, GND, SUPPLY_5V
};
const int bbPixelToNodesMap[62] = { 1, 2, 3, 4, 5, 6, 7, 8, 9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,
32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61};
const int railsToPixelMap[4][5] = {{70,73,74,77,78},//top positive rail
{71,72,75,76,79},//top negative rail
@ -49,17 +99,18 @@ const int pixelsToRails[20] = {B_RAIL_NEG, B_RAIL_POS, B_RAIL_POS, B_RAIL_NEG, B
extern rgbColor netColors[MAX_NETS];
struct rgbColor shiftHue (struct rgbColor colorToShift, int hueShift);
struct rgbColor shiftHue (struct rgbColor colorToShift, int hueShift = 0, int brightnessShift = 0, int saturationShift = 0);
void initLEDs(void);
void clearLEDs(void);
void colorWipe(uint32_t color, int wait);
void rainbowy(int ,int, int wait);
void showNets(void);
void assignNetColors (void);
void lightUpRail (int railNumber, int onOff = 1, int brightness = BRIGHTNESS);
void lightUpRail (int railNumber, int onOff = 1, int brightness = RAILBRIGHTNESS);
void lightUpNet (int netNumber = -1 , int node = -1, int onOff = 1, int brightness = BRIGHTNESS, int hueShift = 0);//-1 means all nodes (default)
void lightUpNode (int node);
rgbColor pcbColorCorrect (rgbColor colorToCorrect);
hsvColor RgbToHsv(rgbColor rgb);
rgbColor HsvToRgb(hsvColor hsv);

View File

@ -30,6 +30,7 @@
#endif
int sendAllPathsCore2 = 0;
// https://wokwi.com/projects/367384677537829889
@ -50,9 +51,7 @@ void setup()
debugFlagInit();
#endif
#ifdef PIOSTUFF
initCH446Q();
#endif
initADC();
initDAC();
@ -73,28 +72,35 @@ setDac0_5V(0.0);
void setup1()
{
//delay(100);
#ifdef PIOSTUFF
initCH446Q();
#endif
initLEDs();
lightUpRail(-1, 1, 220);
lightUpRail(-1, 1);
}
void loop()
{
// getNodesToConnect();
// bridgesToPaths();
// assignNetColors();
// sendAllPaths();
// examples
// add connection
char input;
unsigned long timer = 0;
// initArduino();
//
//rainbowy(255,145,100);
//rainbowy(255,125,30);
// while(1)
// {
// for (int i = 0; i < 30; i++)
// { Serial.println(80+i);
// lightUpNode(80+i);
// showLEDsCore2 = 1;
// //delay(500);
// }
// }
menu:
// arduinoPrint();
@ -175,7 +181,9 @@ menu:
assignNetColors();
#ifdef PIOSTUFF
sendAllPaths();
sendAllPathsCore2 = 1;
//sendAllPaths();
#endif
if (debugNMtime)
@ -221,6 +229,7 @@ menu:
assignNetColors();
#ifdef PIOSTUFF
sendAllPaths();
#endif
@ -284,31 +293,7 @@ menu:
// AIRCR_Register = 0x5FA0004; // this just hardware resets the rp2040, it would be too much of a pain in the ass to reinitialize everything
break;
/*
case '{':
lastCommandWrite(input);
runCommandAfterReset('u');
//lastCommandWrite('{');
parseWokwiFileToNodeFile();
getNodesToConnect();
Serial.println("\n\n\rnetlist\n\r");
listSpecialNets();
listNets();
// printBridgeArray();
bridgesToPaths();
assignNetColors();
sendAllPaths();
EEPROM.write(CLEARBEFORECOMMANDADDRESS, 0);
EEPROM.commit();
break;
*/
case 'd':
{
debugFlagInit();
@ -376,22 +361,33 @@ menu:
goto menu;
while (1)
{
// waveGen();
}
}
void loop1()
{
if (showLEDsCore2 == 1)
{
delayMicroseconds(9200);
leds.show();
delayMicroseconds(1200);
delayMicroseconds(9200);
showLEDsCore2 = 0;
}
if (sendAllPathsCore2 == 1)
{
delayMicroseconds(9200);
sendAllPaths();
delayMicroseconds(9200);
sendAllPathsCore2 = 0;
}
}