From ed05ea75c422caf1439bdea3d0bbb5e238bb9e7a Mon Sep 17 00:00:00 2001 From: redfast00 Date: Thu, 3 Feb 2022 07:02:23 +0100 Subject: [PATCH] Add indicators info module --- src/modules/info_002_indicators/.gitignore | 1 + src/modules/info_002_indicators/3d/.gitignore | 1 + src/modules/info_002_indicators/3d/case.scad | 66 +++++++++++ src/modules/info_002_indicators/doc/index.md | 29 +++++ src/modules/info_002_indicators/graphics.svg | 44 +++++++ .../info_002_indicators/info_indicators.ino | 110 ++++++++++++++++++ 6 files changed, 251 insertions(+) create mode 100644 src/modules/info_002_indicators/.gitignore create mode 100644 src/modules/info_002_indicators/3d/.gitignore create mode 100644 src/modules/info_002_indicators/3d/case.scad create mode 100644 src/modules/info_002_indicators/doc/index.md create mode 100644 src/modules/info_002_indicators/graphics.svg create mode 100644 src/modules/info_002_indicators/info_indicators.ino diff --git a/src/modules/info_002_indicators/.gitignore b/src/modules/info_002_indicators/.gitignore new file mode 100644 index 0000000..c799d34 --- /dev/null +++ b/src/modules/info_002_indicators/.gitignore @@ -0,0 +1 @@ +drawing.svg diff --git a/src/modules/info_002_indicators/3d/.gitignore b/src/modules/info_002_indicators/3d/.gitignore new file mode 100644 index 0000000..1567411 --- /dev/null +++ b/src/modules/info_002_indicators/3d/.gitignore @@ -0,0 +1 @@ +*.stl diff --git a/src/modules/info_002_indicators/3d/case.scad b/src/modules/info_002_indicators/3d/case.scad new file mode 100644 index 0000000..d59d2da --- /dev/null +++ b/src/modules/info_002_indicators/3d/case.scad @@ -0,0 +1,66 @@ +front_panel_thickness=2; +cut=200; +container_wall_thickness=1; +$fn=50; + +front_panel_height=100; +front_panel_width=50; + +module ccube(size = [1,1,1], center = false) +{ + sz = (len(size) == 3)?size:[size,size,size]; + if (len(center) == 1) + cube(size, center); + else + translate([center[0]?-sz[0]/2:0,center[1]?-sz[1]/2:0,center[2]?-sz[2]/2:0]) + cube(size); +} + + +module front_panel() { + difference() { + union() { + ccube([front_panel_height, front_panel_width, front_panel_thickness], center=[1, 1, 0]); + translate([0, 0, -4]) { + translate([front_panel_height/2 - 5 - container_wall_thickness, -front_panel_width/2 + container_wall_thickness]) cube(5); + translate([front_panel_height/2 - 5 - container_wall_thickness, front_panel_width/2 - container_wall_thickness - 5]) cube(5); + translate([-front_panel_height/2 + container_wall_thickness, -front_panel_width/2 + container_wall_thickness]) cube(5); + translate([-front_panel_height/2 + container_wall_thickness, front_panel_width/2 - container_wall_thickness - 5]) cube(5); + } + } + translate([0, 0, -1]) union() { + translate([0, front_panel_width/3]) ccube([55, 6, cut], center=[1, 1, 0]); + translate([0, -front_panel_width/3]) for ( i = [1 : 8] ){ + translate([10*i - front_panel_height/2 + 5, 0]) + cylinder(d = 3, h=cut); + } + } + } +} + +module back_panel() { + difference() { + union() { + ccube([front_panel_height, front_panel_width, 50+container_wall_thickness], center=[0, 1, 0]); + } + union() { + translate([container_wall_thickness, 0, container_wall_thickness]) ccube([front_panel_height-2*container_wall_thickness, front_panel_width-2*container_wall_thickness, cut], center=[0, 1, 0]); + translate([front_panel_height/2, 0, -1]) cylinder(d=10, h=cut); + translate([-1, 0, container_wall_thickness+7]) rotate([0, 90, 0]) cylinder(d=12, h=cut); + // Holes for M3 bolts + translate([0, 0, -1]) { + translate([container_wall_thickness + 5, -front_panel_width/2 + container_wall_thickness + 5]) cylinder(d=3.5, h=cut); + translate([container_wall_thickness + 5, front_panel_width/2 - container_wall_thickness - 5]) cylinder(d=3.5, h=cut); + translate([front_panel_height-container_wall_thickness-5, -front_panel_width/2 + container_wall_thickness + 5]) cylinder(d=3.5, h=cut); + translate([front_panel_height-container_wall_thickness-5, front_panel_width/2 - container_wall_thickness - 5]) cylinder(d=3.5, h=cut); + } + } + } + translate([container_wall_thickness+13, 0]) ccube([5, 10, container_wall_thickness+10], center=[0, 1, 0]); +} + +/* front_panel(); */ +/* back_panel(); */ + +// plate to insert between button and main case +cube([10, 10, 4.8]); diff --git a/src/modules/info_002_indicators/doc/index.md b/src/modules/info_002_indicators/doc/index.md new file mode 100644 index 0000000..bab32ee --- /dev/null +++ b/src/modules/info_002_indicators/doc/index.md @@ -0,0 +1,29 @@ +# Appendix B: Indicatorlampen + +\begin{figure}[!b] + \centering + \includegraphics[width=10cm,height=5cm,keepaspectratio]{./info_002_indicators/description.png} +\end{figure} + +Er zijn 2 soorten indicatorlampen: gelabelde en gekleurde. De gelabelde lampen staan +bovenaan de module, de gekleurde onderaan. + +## Gelabelde indicatorlampen + +De labels zijn (in volgorde): `WPI`, `KEL`, `DER`, `ZEUS`, `JDV`, `QRV`, `PSE`, `DRV`. + +## Gekleurde indicatorlampen + +Mogelijke kleuren zijn: + +\fcolorbox{black}{red}{\rule{0pt}{6pt}\rule{6pt}{0pt}} rood, \fcolorbox{black}{green}{\rule{0pt}{6pt}\rule{6pt}{0pt}} groen, \fcolorbox{black}{blue}{\rule{0pt}{6pt}\rule{6pt}{0pt}} blauw, \fcolorbox{black}{yellow}{\rule{0pt}{6pt}\rule{6pt}{0pt}} geel, \fcolorbox{black}{cyan}{\rule{0pt}{6pt}\rule{6pt}{0pt}} cyaan, \fcolorbox{black}{orange}{\rule{0pt}{6pt}\rule{6pt}{0pt}} oranje, \fcolorbox{black}{magenta}{\rule{0pt}{6pt}\rule{6pt}{0pt}} roze, \fcolorbox{black}{violet}{\rule{0pt}{6pt}\rule{6pt}{0pt}} paars + +Indien je niet zeker bent wat de kleur is van een bepaalde gekleurde indicatorlamp, +kan je op de witte knop op de zijkant van de module drukken. Zolang deze knop ingedrukt is, +worden tijdelijk alle kleuren in de volgorde van het lijstje hierboven getoond en gaan de gelabelde +indicatorlampen uit. Wanneer in de handleiding verwezen wordt naar indicatorlampen, gaat +dit enkel over hun staat wanneer de knop niet ingedrukt is. + +**Waarschuwing**: wanneer er in de handleiding verwezen wordt naar de kleur van indicatorlampen, +mag je enkel de gekleurde indicatorlampen in beschouwing nemen, niet de gelabelde indicatorlampen +(de leds in de gelabelde indicatorlampen zijn geel, maar deze tellen niet mee). diff --git a/src/modules/info_002_indicators/graphics.svg b/src/modules/info_002_indicators/graphics.svg new file mode 100644 index 0000000..a99727c --- /dev/null +++ b/src/modules/info_002_indicators/graphics.svg @@ -0,0 +1,44 @@ + + + + + + + + + + + + + + + + WPI + + KEL + DER + ZEUS + JDV + QRV + PSE + DRV + WPI + KEL + DER + ZEUS + JDV + QRV + PSE + DRV + + WPI + KEL + DER + ZEUS + JDV + QRV + PSE + DRV + + + diff --git a/src/modules/info_002_indicators/info_indicators.ino b/src/modules/info_002_indicators/info_indicators.ino new file mode 100644 index 0000000..9d43b93 --- /dev/null +++ b/src/modules/info_002_indicators/info_indicators.ino @@ -0,0 +1,110 @@ +// (c) 2022, redfast00 +// See the LICENSE file for conditions for copying + +/* Format of the info message + +length = 5 bytes +id = 2 + +message: +X X X X A +------v -> the labeled indicators + the colored indicators + +The first 4 bytes are for the 8 colored indicators, every +byte contains 2 indices into the color table. The first colored indicator index is +in the first (or most sigificant) 4 bits of the first byte, the second colored indicator +index in the last 4 bits of the first byte, and so on. + +The color table is defined below in the `colortable` variable + +The fifth byte is for the labeled indicators. The most significant bit (128) is +for the WPI label light, the least sigificant bit (1) for the DRV label light. The bit is 1 +if the light is on, 0 otherwise. All labels, in order: + +WPI 0b10000000 +KEL 0b01000000 +DER 0b00100000 +ZEUS 0b00010000 +JDV 0b00001000 +QRV 0b00000100 +PSE 0b00000010 +DRV 0b00000001 + +Some code to loop over all colored indicator values, assuming the info message was saved in `buffer` + +``` +for (uint8_t idx = 0; idx < 8; idx++) { + coloridx = (buffer[idx / 2] >> (4 * (1 - (idx & 1)))) & 0b111; +} +``` +*/ + +uint8_t colortable[8][3] = { + {20, 0, 0}, // red 0b0000 + {0, 20, 0}, // green 0b0001 + {0, 0, 20}, // blue 0b0010 + {10, 10, 0}, // yellow 0b0011 + {0, 10, 10}, // cyan 0b0100 + {15, 5, 0}, // orange 0b0101 + {15, 0, 5}, // pink 0b0110 + {5, 0, 15} // purple 0b0111 +}; + + +#include +#include +#define WS2812_PIN 6 +#define BUTTON_PIN 9 + +uint8_t led_pins[8] = {A0, A1, A2, A3, A4, A5, 3, 2}; + + +Adafruit_NeoPixel pixels(8, WS2812_PIN, NEO_GRB + NEO_KHZ800); +uint8_t led_buffer[5] = {0b00000001, 0b00100011, 0b01000101, 0b01100111, 0b11101100}; +bool render_now = true; + + + +void setup() { + Serial.begin(115200); + obus_module::setup(OBUS_TYPE_INFO, 2); + pixels.begin(); + pinMode(BUTTON_PIN, INPUT_PULLUP); + for (int i = 0; i < 8; i++) { + pinMode(led_pins[i], OUTPUT); + digitalWrite(led_pins[i], true); + } +} + +obus_can::message message; + +void render(bool realcolors) { + render_now = false; + for (uint8_t idx = 0; idx < 8; idx++) { + uint8_t coloridx = idx; + if (realcolors) { + coloridx = (led_buffer[idx / 2] >> (4 * (1 - (idx & 1)))) & 0b111; + } + pixels.setPixelColor(idx, pixels.Color(colortable[coloridx][0], colortable[coloridx][1], colortable[coloridx][2])); + } + pixels.show(); + for (int i = 0; i < 8; i++) { + digitalWrite(led_pins[i], ((led_buffer[4] >> i) & 0b1) && realcolors); + } +} + +void loop() { + obus_module::loopInfo(&message, info_generator); + render(digitalRead(BUTTON_PIN) == HIGH); +} + +int info_generator(uint8_t* buffer) { + for (int i = 0; i < 4; i++) { + led_buffer[i] = random(256) & 0b01110111; + } + led_buffer[4] = random(256); + render_now = true; + memcpy(buffer, led_buffer, 5); + return 5; +}