This commit is contained in:
matteo porta 2022-06-29 11:02:58 +02:00
parent d867ec709d
commit 05dde48ee6
8 changed files with 144 additions and 32 deletions

View File

@ -24,15 +24,14 @@ class ArchiveSynchronizer(Component):
def config_changed(self):
self.machine_id = self.config.machine_id
config = self.config["archive_synchronizer"]
self.archive_endpoint = config["archive_endpoint"]
self.images_path = config["images_path"]
self._do_set_period({"period": float(config["poll_time"])})
self.hold_time = round(float(config["hold_time"]) * 1000)
self.gcs_client = storage.Client.from_service_account_json(config["service_account_json"])
self.archive_endpoint = self.config[self.name]["archive_endpoint"]
self.images_path = self.config[self.name]["images_path"]
self._do_set_period({"period": float(self.config[self.name]["poll_time"])})
self.hold_time = round(float(self.config[self.name]["hold_time"]) * 1000)
self.gcs_client = storage.Client.from_service_account_json(self.config[self.name]["service_account_json"])
self.gcs_client._http.mount("", HTTPAdapter(max_retries=Retry(total=0))) # this seems to be useless
self.gcs_client._http.adapters.move_to_end("", last=False) # this seems to be useless
self.bucket_id = config["bucket_id"]
self.bucket_id = self.config[self.name]["bucket_id"]
self.gcs_bucket = None
@db.connection_context()

View File

@ -0,0 +1,16 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
"version": "0.2.0",
"configurations": [
{
"cwd": "${workspaceRoot}",
"executable": "./bin/executable.elf",
"name": "Debug Microcontroller",
"request": "launch",
"type": "cortex-debug",
"servertype": "pyocd"
}
]
}

View File

@ -1,32 +1,77 @@
#include <Adafruit_NeoPixel.h>
#include <limits.h>
#include <stdint.h>
#ifdef __AVR__
#include <avr/power.h>
#endif
// MACRO DEFINITIONS
#define PIN 21
#define NUMPIXELS 12
// pixel selection 32bit (4bytes)
// pixel color 1 byte per color, 3 colors (3bytes)
// \n ender (1bytes)
#define SERIAL_MESSAGE_LEN 8
// TYPES DEFINITION
typedef union {
uint32_t value;
uint8_t bytes[4];
} Address;
typedef uint8_t Color[3];
// GLOBAL VARIABLES
size_t read = 0;
uint8_t message[SERIAL_MESSAGE_LEN] = { 0 };
Address address = { 0 };
Color color = { 0 };
Adafruit_NeoPixel pixels(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);
#define DELAYVAL 50
// SETUP PROCEDURE
void setup() {
#if defined(__AVR_ATtiny85__) && (F_CPU == 16000000)
clock_prescale_set(clock_div_1);
#endif
Serial.begin(9600);
pixels.begin();
}
uint8_t parse_message(uint8_t *message, Address *address, Color color) {
if (message[SERIAL_MESSAGE_LEN - 1] != '\n') {
Serial.write("missing message termination (\\n)");
return 1;
}
// little endian
address->bytes[3] = message[0];
address->bytes[2] = message[1];
address->bytes[1] = message[2];
address->bytes[0] = message[3];
color[0] = message[4];
color[1] = message[5];
color[2] = message[6];
return 0;
}
void loop() {
pixels.clear();
for (int i = 0; i < NUMPIXELS; i++) {
pixels.setPixelColor(i, pixels.Color(195, 155, 125));
read = Serial.readBytes(message, SERIAL_MESSAGE_LEN);
if (read > 0 && read != SERIAL_MESSAGE_LEN) {
Serial.write("bad message length: %d instead of %d\n", read, SERIAL_MESSAGE_LEN);
return;
}
if (parse_message(message, &address, color)) {
Serial.write(", failed to parse message\n");
return;
}
if (address.value == UINT_MAX || address.value > NUMPIXELS) {
pixels.clear();
for (int i = 0; i < NUMPIXELS; i++) {
pixels.setPixelColor(i, pixels.Color(color[0], color[1], color[2]));
}
pixels.show();
delay(DELAYVAL);
Serial.write("ok\n");
} else {
pixels.setPixelColor(i, pixels.Color(color[0], color[1], color[2]));
pixels.show();
Serial.write("ok\n");
}
while (1) {
1;
}
}
}

View File

@ -0,0 +1,52 @@
import sys
import traceback
if "--sim-serial-neo-pixels" in sys.argv:
import components.dummies.serial as serial
else:
import serial
from ctypes import c_uint32
from .component import Component
C_UINT32_MAX = c_uint32(-1).value
class Serial_Label_Printer(Component):
def __init__(self, config=None, name=None):
super().__init__(config=config, name=name, threaded=False)
def config_changed(self):
self.address = self.config[self.name]["address"]
self.baudrate = int(self.config[self.name]["baudrate"])
self.stopbits = getattr(serial, self.config[self.name].get("stopbits", "stopbits_one").upper())
self.parity = getattr(serial, self.config[self.name].get("parity", "parity_none").upper())
self.bytesize = getattr(serial, self.config[self.name].get("bytesize", "eightbits").upper())
def set(self, pixel, color):
if type(pixel) is not int or pixel < 0 or pixel > C_UINT32_MAX:
raise ValueError(f"the pixel parameter must be a int between 0 and {C_UINT32_MAX} (broadcast)")
if not color.startswith("#") or len(color) != 7:
raise ValueError("the color parameter must be in the html hex format: '#RRGGBB'")
try:
conn = serial.Serial(
self.address,
baudrate=self.baudrate,
stopbits=self.stopbits,
parity=self.parity,
bytesize=self.bytesize,
)
conn.write(int.to_bytes(pixel, length=4, byteorder="big") + bytes.fromhex(color[1:7]) + b"\n")
response = conn.readline()
if response != "ok\n":
self.log.error(response.strip())
conn.close()
except serial.serialutil.SerialException:
self.log.exception(traceback.format_exc())
def set_pixel_color(self, pixel, color):
self.set(pixel, color)
def set_all_pixel_color(self, color):
self.set(C_UINT32_MAX, color)

View File

@ -13,7 +13,7 @@ class Os_Label_Printer(Component):
self.simulate = True
def config_changed(self):
self.platform = self.config["label_printer"]["platform"]
self.platform = self.config[self.name]["platform"]
# for windows:
# cmd
# wmic printer list brief
@ -21,7 +21,7 @@ class Os_Label_Printer(Component):
# Get-Printer
# for cups (linux, osx)
# lpstat -p -d
self.printer = self.config["label_printer"]["printer"]
self.printer = self.config[self.name]["printer"]
def print_label(self, template, archived):
# LOAD LABEL TEMPLATE

View File

@ -15,11 +15,11 @@ class Serial_Label_Printer(Component):
super().__init__(config=config, name=name, threaded=False)
def config_changed(self):
self.address = self.config["label_printer"]["address"]
self.baudrate = int(self.config["label_printer"]["baudrate"])
self.stopbits = getattr(serial, self.config["label_printer"].get("stopbits", "stopbits_one").upper())
self.parity = getattr(serial, self.config["label_printer"].get("parity", "parity_none").upper())
self.bytesize = getattr(serial, self.config["label_printer"].get("bytesize", "eightbits").upper())
self.address = self.config[self.name]["address"]
self.baudrate = int(self.config[self.name]["baudrate"])
self.stopbits = getattr(serial, self.config[self.name].get("stopbits", "stopbits_one").upper())
self.parity = getattr(serial, self.config[self.name].get("parity", "parity_none").upper())
self.bytesize = getattr(serial, self.config[self.name].get("bytesize", "eightbits").upper())
def print_label(self, template, archived):
# LOAD LABEL TEMPLATE

View File

@ -21,7 +21,7 @@ class TestComponent(Component):
paused=paused,
threaded=threaded,
)
self.parameter = self.config["test"]["parameter"]
self.parameter = self.config[self.name]["parameter"]
def _get(self, data=None):
super()._get([self.parameter] + [random() for i in range(2)])

View File

@ -15,13 +15,13 @@ class VisionSaver(Component):
super().__init__(config=config, name=name, threaded=False)
def config_changed(self):
self.location = Path(self.config["vision_saver"]["path"])
self.location = Path(self.config[self.name]["path"])
os.makedirs(self.location, exist_ok=True)
self.mask_zones = self.config["vision_saver"].get("mask_zones", None)
self.minimum_disk_free_space_gb = self.config["vision_saver"].get("minimum_disk_free_space_gb", None)
self.mask_zones = self.config[self.name].get("mask_zones", None)
self.minimum_disk_free_space_gb = self.config[self.name].get("minimum_disk_free_space_gb", None)
if self.minimum_disk_free_space_gb is not None:
self.minimum_disk_free_space_gb = float(self.minimum_disk_free_space_gb)
self.time_format = self.config["vision_saver"]["time_format"]
self.time_format = self.config[self.name]["time_format"]
def save(self, save_time, img, mask=True):
timestamp = datetime.fromtimestamp(save_time).strftime(self.time_format)