Crate contourwall_core

source ·
Expand description

This library provides an interface for controlling the tiles using the ContourWall protocol over serial communication with an ESP32 device mounted on each tile of the ContourWall.

The ContourWallCore struct represents the core functionality, allowing you to initialize a connection to a COM port, send commands to update LED colors, retrieve tile identifiers, and more.

For more details on available commands and usage, refer to the individual function documentation.

§Example Usage

To utilize this library, ensure you have the necessary serial port permissions and ESP32 firmware flashed with the ContourWall protocol support.

use std::ffi::CString;
use contourwall_core::*;

fn main() {
    let com_port = CString::new("/dev/ttyUSB3").expect("CString conversion failed").into_raw();
    let baud_rate = 921_600;
    let mut cw = new(com_port, baud_rate);

    let status_code = command_1_solid_color(&mut cw, 255, 0, 255); // Sets all LEDs to purple
    assert_eq!(status_code, StatusCode::Ok.as_u8());

    let status_code = command_0_show(&mut cw); // Shows the changes on the LED tiles
    assert_eq!(status_code, StatusCode::Ok.as_u8());
}

§Compatibility

This library is compatible with both Windows and Linux systems, It has been tested on Windows devices and a Raspberry Pi 5. MacOS is untested, however it should work.

§Errors

Errors encountered during serial communication or protocol execution are indicated through StatusCode values returned by the library functions.

§Safety

This library uses unsafe Rust code to interface with C-style pointers and raw bytes for serial communication. Extra care should be taken to ensure proper usage to avoid memory unsafety and undefined behavior.

§Protocol Documentation

This library assumes adherence to the ContourWall protocol. Please refer to the protocol documentation for more information on commands and their expected behavior.

§License

This library is distributed under the terms of the MIT license. See the LICENSE file for details.

Modules§

  • Enum abstraction over the StatusCodes used signal the status of the ESP32.

Structs§

  • ContourWallCore encapsulates the essential elements required for communication with LED tiles, including timing parameters and the serial port connection.

Functions§

  • Executes command_0_show of the protocol.
  • Executes command_1_solid_color of the protocol, which sets all pixels on a tile to one specific color.
  • Executes command_2_update_all of the protocol, sets LED’s to individually assigned colors based on index of the RGB values
  • Executes command_3_update_all of the protocol, sets some LED’s to individually assigned colors based given index with RGB code.
  • Executes command_4_get_tile_identifier of the protocol. Returns the tile identifier which is set in the EEPROM of the ESP32
  • Executes command_5_set_tile_identifier of the protocol. Sets a new tile identifier in the EEPROM of the ESP32
  • Transfers ownership of the ContourWallCore object back to Rust and frees the memory.
  • Returns current set frame_time of the ContourWallCore struct in milliseconds.
  • Creates a new instance of the ContourWallCore struct.
  • Sets the frame_time field of the ContourWallCore struct in milliseconds.