Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • c3pb/heizung
1 result
Show changes
Commits on Source (4)
nix-shell -p rustup udev.dev pkg-config openssl.dev nix-shell -p rustup udev.dev pkg-config openssl.dev
cargo install probe-rs-cli # renamed to probe-rs-tools, it seems cargo install probe-rs-cli # renamed to probe-rs-tools, it seems
cargo install probe-rs-debugger cargo install probe-rs-debugger
cargo install cargo-binutils
# https://github.com/raspberrypi/picoprobe # https://github.com/raspberrypi/picoprobe
# https://datasheets.raspberrypi.com/pico/getting-started-with-pico.pdf # https://datasheets.raspberrypi.com/pico/getting-started-with-pico.pdf
cargo run --bin blinky cargo run --bin blinky
......
#!/usr/bin/env python
# -*- coding: utf_8 -*-
# based on https://github.com/pymodbus-dev/pymodbus/blob/dev/examples/client_sync.py
import logging
import time
import sys
import struct
import pymodbus
from pymodbus.exceptions import ModbusException
from pymodbus.client import ModbusSerialClient
from pymodbus.file_message import FileRecord
from uf2 import *
PORT = '/dev/ttyUSB0'
DEVICE_ADDR = 1
logger = logging.getLogger()
logger.setLevel(logging.INFO)
log_handler = logging.StreamHandler(sys.stdout)
logger.addHandler(log_handler)
def main():
try:
client = ModbusSerialClient(
port=PORT,
timeout=0.2,
# Common optional paramers:
# framer=ModbusRtuFramer,
# timeout=10,
# retries=3,
# retry_on_empty=False,
# close_comm_on_error=False,
# strict=True,
#baudrate=19200,
baudrate=115200,
parity="E",
)
client.connect()
logger.info("connected")
x = client.write_registers(1, struct.unpack(">H", b"OK")[0], slave=DEVICE_ADDR)
logger.info("write to mark ok: %s", x)
except ModbusException as exc:
logger.error("%s", exc)
if __name__ == "__main__":
main()
# https://github.com/earlephilhower/arduino-pico/blob/c095fce5b2f26b03fa0e6374e3371a1799abb5b1/tools/uf2conv.py#L374C1-L382C32
import serial, time
ser = serial.Serial()
ser.port = "/dev/ttyACM0"
ser.open()
ser.baudrate = 9600
ser.dtr = True
time.sleep(0.1)
ser.dtr = False
ser.baudrate = 1200
ser.close()
...@@ -32,14 +32,17 @@ def main(): ...@@ -32,14 +32,17 @@ def main():
# retry_on_empty=False, # retry_on_empty=False,
# close_comm_on_error=False, # close_comm_on_error=False,
# strict=True, # strict=True,
baudrate=19200, baudrate=115200,
parity="E", parity="E",
) )
client.connect() client.connect()
logger.info("connected") logger.info("connected")
x = client.read_holding_registers(address=1, count=1, slave=DEVICE_ADDR) if False:
logger.info("holding reg 1: %s: %r", x, x.registers) x = client.read_holding_registers(address=1, count=1, slave=DEVICE_ADDR)
if isinstance(x, ModbusException):
raise x
logger.info("holding reg 1: %s: %r", x, x.registers)
scratch_reg = 2 scratch_reg = 2
client.write_register(address=scratch_reg, value=0x12, slave=DEVICE_ADDR) client.write_register(address=scratch_reg, value=0x12, slave=DEVICE_ADDR)
...@@ -96,7 +99,7 @@ def main(): ...@@ -96,7 +99,7 @@ def main():
time.sleep(0.1) time.sleep(0.1)
except ModbusException as exc: except ModbusException as exc:
logger.error("%s", exc) logger.exception("%s", exc)
if __name__ == "__main__": if __name__ == "__main__":
main() main()
...@@ -332,7 +332,6 @@ async fn reset_soon(delay: Duration) { ...@@ -332,7 +332,6 @@ async fn reset_soon(delay: Duration) {
/// Input a value 0 to 255 to get a color value /// Input a value 0 to 255 to get a color value
/// The colours are a transition r - g - b - back to r. /// The colours are a transition r - g - b - back to r.
fn wheel(mut wheel_pos: u8) -> RGB8 { fn wheel(mut wheel_pos: u8) -> RGB8 {
//return (0, 255, 0).into();
wheel_pos = 255 - wheel_pos; wheel_pos = 255 - wheel_pos;
if wheel_pos < 85 { if wheel_pos < 85 {
return (255 - wheel_pos * 3, 0, wheel_pos * 3).into(); return (255 - wheel_pos * 3, 0, wheel_pos * 3).into();
...@@ -368,7 +367,9 @@ async fn ws2812_task(pio: PIO1, pin: PIN_2, dma: DMA_CH3) { ...@@ -368,7 +367,9 @@ async fn ws2812_task(pio: PIO1, pin: PIN_2, dma: DMA_CH3) {
for j in 0..(256 * 5) { for j in 0..(256 * 5) {
//debug!("New Colors:"); //debug!("New Colors:");
for i in 0..NUM_LEDS { for i in 0..NUM_LEDS {
data[i] = wheel((((i * 256) as u16 / NUM_LEDS as u16 + j as u16) & 255) as u8); let mut color = wheel((((i * 256) as u16 / NUM_LEDS as u16 + j as u16) & 255) as u8);
color /= 8;
data[i] = color;
//debug!("R: {} G: {} B: {}", data[i].r, data[i].g, data[i].b); //debug!("R: {} G: {} B: {}", data[i].r, data[i].g, data[i].b);
} }
ws2812.write(&data).await; ws2812.write(&data).await;
......