Skip to content

Software

Mick Harrigan edited this page May 20, 2023 · 18 revisions

Overview

This codebase is entirely written in Rust for the UMBC UHDRTZ Capstone Project.

The entire UHDRTZ is built on the Bevy Game Engine with version 0.10.0. This is what defines the whole paradigm used.

The codebase consists of the following structure:

.
├── assets
│  ├── audio
│  │  └── RomanceAnonimo.mp3
│  ├── background.png
│  └── xhair.png
├── Cargo.lock
├── Cargo.toml
├── examples
│  ├── old_tests
│  │  ├── async_bluetooth_bevy.rs
│  │  ├── audio.rs
│  │  ├── bluetooth.rs
│  │  ├── get_camera_properties.rs
│  │  ├── gui_test.rs
│  │  ├── nokhwa_query.rs
│  │  ├── snap_single_image.rs
│  │  └── states.rs
│  └── README.md
├── README.md
├── src
│  ├── audio.rs
│  ├── bluetooth.rs
│  ├── camera.rs
│  ├── gui.rs
│  ├── lib.rs
│  ├── main.rs
│  ├── plugin.rs
│  ├── setup.rs
│  └── zoetrope.rs
├── uhdrtz-crank
│  └── README.md
└── uhdrtz-rust.wiki
   ├── Hardware.md
   ├── Home.md
   ├── Setup-Guide.md
   └── Software.md

At the top of this is the src/ directory where all the actual source code is stored.

Next is the assets/ directory, where the crosshair, test background image, and audio/ directory are stored.

audio/ is where the program checks for audio files to be played during runtime. Audio must be in the <filename>.mp3 format to be played.

From the of the actual code is the src/lib.rs and src/main.rs files that are what re-export the code from the other files as well as the primary executable. The other files are described below in terms of the Bevy Plugins that they correspond with.

Plugins

Within this system there is a compartmentalization of functionality. This breakdown is between the Plugins of each major piece of functionality.

These plugins are as follows:

  • Animation
  • Audio
  • Bluetooth
  • Gui
  • Setup
  • Base

Each of these have their smaller parts (functions, data, control structures, etc.) within their own file in the src/ directory. At the top of this is then the meta-plugin ZoetropePlugins which is a container for all the previous plugins.

Animation

This plugin controls the animation and creation of animateable objects. This also controls any data that would be necessary for the animation. The file that this is attached to is src/zoetrope.rs. The major structures within are that of the ZoetropeImage, ZoetropeAnimationThresholdSpeed, Slices, and RotationDirection. These containers are what define the image that is to be rotated, the speed of the rotation that the crank must be rotated at to reach full animation, the amount of rotational frames within a piece of art, and a controller for which direction the audio and animation should go relative to the crank input.

Additionally, the major functions are zoetrope_setup, zoetrope_animation, and zoetrope_next_camera_frame. These are what define the main aspects of the zoetrope action.

The setup function creates all the things that need to exist in the "scene", that being the physical camera, internal logical camera, disc to display the images, and the crosshair.

The animation function takes the rotational data from the arduino in the crank and converts that to an angular rotation of the disc that the image is projected onto.

The next camera frame function gets the next image from the camera and sets the image on the disc to that new image.

Audio

This plugin controls the addition of the audio and which song will be played. The data contained here is an empty event for triggering a volume change, and a song to be played. The file for this is src/audio.rs. The functions are audio_setup, audio_modulation_rotation, and change_audio_volume. In order what they do is create a song that can be played and referenced later, change the audio playback direction, and update the volume.

For the most part these functions can speak for themselves in how they operate.

Bluetooth

This plugin controls reading from the arduino and placing that into a structure that the rest of the bevy tools can interact with. The file that is used for this plugin is src/bluetooth.rs. There are some constants that are required that are pre-defined on the arduino itself inside of the uhdrtz-crank directory as well.

The data that is stored is the rotation value from the arduino or if the arduino is connected. The major functions are get_bluetooth_data and find_crank_arduino. These have a lot of boilerplate to them that really the gist is that in find_crank_arduino the arduino is connected to and stored to the computer then in get_bluetooth_data the data is constantly read into RotationInterval.

GUI

This is the plugin that controls the debug GUI that appears while running the full system. It is contained in src/gui.rs. The important structures are that of the UiState and ColorSettings. These control if the UI is visible and what the camera controls settings should be (Brightness, Contrast, Saturation, etc.).

The major functions are as follows: gui_full, gui_set_crosshair, gui_open, gui_camera_control, and cursor_visibility.

All but gui_full are short, so their descriptions are as follows.

gui_set_crosshair sets the crosshair to be visible or invisible depending on the UiState. gui_open shows the GUI windows depending on the UiState. gui_camera_control moves the logical camera depending on the arrow keys. cursor_visibility hides the cursor unless the GUI is open.

In the case of gui_full it controls the creation of the main windows and what they can interact with. This includes sending camera controls like Brightness, Contrast, Zoom, etc.. It also can change the volume of the music and the audio direction based on the rotation. The animation direction can also be changed. Then lastly is the preset camera locations and rotational threshold speed.

Setup

This plugin is the largest and controls the startup window and systems. The containing file is src/setup.rs.

The plugin creates a window on the computer, initializes the settings of the overall system, runs an internal state machine, and transitions to the running of the full system. Most of it is boilerplate that sets up other parts of the code, but also has a few things that are necessary.

The data used is the amount of slices in the art, rotation interval container, arduino connection, and the camera settings. The primary function that is used is setup_menu where the selectors for the physical camera, resolution, crank connection, audio source, and amount of slices are.

When a camera and matching arduino are connected then the continue button is ready and the system can transition through the cleanup_menu function. This sends the information captured before and changes the window to the new settings for running.

Base

This does not have a file associated with it. This plugin determines the timing for the animation based on the amount of slices, sets the background color to black, and allows closing the app with escape.

Camera

This is not a specific plugin but does have a file associated with it. The file is src/camera.rs. This file contains the definition of the camera and how it sends and recieves images and controls.

Additionally the function hash_available_cameras takes all cameras currently connected to the computer and creates a list of them and their indices.

Clone this wiki locally