Skip to content

Commit

Permalink
Merge branch '3.0.0_prerelease'
Browse files Browse the repository at this point in the history
  • Loading branch information
shillinc-osu committed Jun 2, 2024
2 parents 631290d + ac50dac commit fdf3fd0
Show file tree
Hide file tree
Showing 102 changed files with 32,572 additions and 16,988 deletions.
Binary file added .DS_Store
Binary file not shown.
57 changes: 57 additions & 0 deletions .github/workflows/doxygen.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# This is a basic workflow to help you get started with Actions

name: Doxygen Action

# Controls when the action will run. Triggers the workflow on push or pull request
# events but only for the master branch
on:
push:
branches: [ 3.0.0_prerelease ]



# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
# This workflow contains a single job called "build"
build:
# The type of runner that the job will run on
runs-on: ubuntu-latest

# Steps represent a sequence of tasks that will be executed as part of the job
steps:

# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v2

- name: Doxygen Action_dev
uses: mattnotmitt/[email protected]
with:
# Path to Doxyfile
doxyfile-path: "./docs/deviceDoxyfile" # default is ./Doxyfile
# Working directory
working-directory: "." # default is .


- name: Build_web
uses: andstor/jsdoc-action@v1
with:
source_dir: ./WebApp/src
recurse: true
output_dir: ./docs/web

- name: Deploy
uses: peaceiris/actions-gh-pages@v3
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
# Default Doxyfile build documentation to html directory.
# Change the directory if changes in Doxyfile
publish_dir: ./docs

- name: Deploy
uses: peaceiris/actions-gh-pages@v3
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
# Default Doxyfile build documentation to html directory.
# Change the directory if changes in Doxyfile
publish_dir: ./landing-page
keep_files: true
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,7 @@ __pycache__/

node_modules/
build/
act.exe
docs/manual/mdpdf.log
docs/manual/wkhtmltopdf.exe
main/.DS_Store
6 changes: 6 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"files.associations": {
"cmath": "cpp",
"variant": "cpp"
}
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
Binary file added Archive/NanoLux_Stereo/.DS_Store
Binary file not shown.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
13 changes: 10 additions & 3 deletions VirtualLEDStrip/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,19 @@
OpenCV,
NumPy,
PySerial,
PySimpleGUI,
Pillow

Also ensure that LED_WIDTH, is set to the same as NUMLEDS running on the ESP32.
You no longer need to ensure the LED strip is the correct length: this is done automatically by the simulator.

# Usage
1. Uncomment the flag "VIRTUAL_LED_STRIP", this will begin writing out to the serial port, ensure that the serial monitor is closed.
2. Ensure that the ESP32 is plugged into your machine, on communication port 3(COM3).
2. Ensure the flag "DEBUG" is commented. This can cause instability in the simulator.
2. Ensure that the ESP32 is plugged into your machine, on communication port 4(COM4).
3. Then simply run the python script


# Future Revisions
1. Abstract all NanoLux features into a class.
2. Move all UI code into a separate ui.py file.
3. Move all reads from serial to a separate thread.
4. Improve auto disconnection logic.
Binary file added VirtualLEDStrip/assets/icon.ico
Binary file not shown.
Binary file added VirtualLEDStrip/assets/logo2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
53 changes: 0 additions & 53 deletions VirtualLEDStrip/main.py

This file was deleted.

155 changes: 155 additions & 0 deletions VirtualLEDStrip/main.pyw
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
import sim_constants as sc
import numpy as np
import PySimpleGUI as sg
import sim_helpers as sim

# Convert the logo's relative path to this file to an
# absolute system path.
logo_path = sim.get_absolute_path(sc.LOGO_RELATIVE_PATH)

# Convert the Windows' icon relative path to a system path.
icon_path = sim.get_absolute_path(sc.ICON_RELATIVE_PATH)

old_serial_options = [sc.NO_SERIAL_PORT] + sim.ports_to_list()
if "COM1" in old_serial_options:
old_serial_options.remove("COM1")

# Configure the GUI
sg.theme(sc.APP_THEME)
layout = [
[
sg.Image(logo_path, subsample=sc.LOGO_SCALE),
sg.OptionMenu(
values=old_serial_options,
key=sc.COM_SELECTOR_KEY,
default_value=sc.NO_SERIAL_PORT,
),
sg.Button(sc.RESCAN_BUTTON, key=sc.RESCAN_BUTTON),
],
sim.make_display_bar(sc.HSV_KEY),
sim.make_display_bar(sc.RGB_KEY),
sim.make_display_bar(sc.BGR_KEY),
[
sg.Button(sc.CONNECT_BUTTON, key=sc.CONNECT_BUTTON),
sg.Button(sc.DISCONNECT_BUTTON, key=sc.DISCONNECT_BUTTON),
sg.Text(sc.state_to_string[sc.DEFAULT_STATE], key=sc.STATUS_FIELD)
],
]

# Create the Window
window = sg.Window(
sc.APP_NAME,
layout,
icon=sim.path_to_png(icon_path),
)

# Ensure the openCV arrays are global variables
bgr = np.zeros((sc.DEFAULT_LED_HEIGHT, sc.LED_BAR_TARGET_LENGTH, 3), np.uint8)
hsv, rgb = bgr, bgr

# Update the application window with new images.
def update_bars(bgr, hsv, rgb):
window[sc.RGB_KEY].update(data=sim.mat_to_png(rgb))
window[sc.BGR_KEY].update(data=sim.mat_to_png(bgr))
window[sc.HSV_KEY].update(data=sim.mat_to_png(hsv))

def update_selector_options():
options = [sc.NO_SERIAL_PORT] + sim.ports_to_list()
if "COM1" in options:
options.remove("COM1")
window[sc.COM_SELECTOR_KEY].update(values=options, value=sc.NO_SERIAL_PORT)

def disconnect_teardown(SER):
SER.close()
SER = None
return sc.DISCONNECTED_STATE

if __name__ == '__main__':

# Application state setup
app_state = sc.DEFAULT_STATE
SER = None
connection_attempted = False

# Ensure that the bars are drawn at least once
event, values = window.read(0)
blank = np.zeros((sc.DEFAULT_LED_HEIGHT, sc.DEFAULT_LED_WIDTH, 3), np.uint8) # (B, G, R)
blank = sim.resize_image(blank, 10, 30)
update_bars(blank, blank, blank)

# Main application loop
while app_state != sc.EXITING_STATE:

# Check for events from the UI.
event, values = window.read(0)
if event == sg.WIN_CLOSED: # if user closes window or clicks cancel
app_state = sc.EXITING_STATE

if event == sc.RESCAN_BUTTON:
update_selector_options()

# Reset the bgr image
bgr = np.zeros((sc.DEFAULT_LED_HEIGHT, sc.LED_BAR_TARGET_LENGTH, 3), np.uint8) # (B, G, R)

match app_state:
case sc.CONNECTING_STATE:
# Set the disable state of both buttons
window[sc.CONNECT_BUTTON].update(disabled=True)
window[sc.DISCONNECT_BUTTON].update(disabled=False)

# If the connection button is pressed again, disconnect.
if event == sc.DISCONNECT_BUTTON:
app_state = sc.DISCONNECTED_STATE

# Attempt to connect to serial. If serial_setup returns a value
# that is not None, move to the connected state and give a
# notification print.
SER = sim.serial_setup(sc.NO_DEBUG, values[sc.COM_SELECTOR_KEY])
if SER != None:
app_state = sc.CONNECTED_STATE
print("Connected to NanoLux device.")
connection_attempted = False

case sc.CONNECTED_STATE:
# Set the disable state of both buttons
window[sc.CONNECT_BUTTON].update(disabled=True)
window[sc.DISCONNECT_BUTTON].update(disabled=False)

# Try to grab serial data and transform the blank image using the BGR
# data from the AudioLux.
# If this fails for whatever reason, move to the disconnected state and
# disconnect from the AudioLux.
try:
# Read in data from serial and process it into a bgr image.
serial_data = SER.readline().decode("utf-8").split()
bgr = sim.update_image(bgr, serial_data)
hsv, rgb = sim.bgr_to_hsv_rgb(bgr)
update_bars(bgr, hsv, rgb)
except:
app_state = disconnect_teardown(SER)
update_selector_options()

# If the connection button is pressed again, disconnect.
if event == sc.DISCONNECT_BUTTON:
app_state = disconnect_teardown(SER)

case sc.DISCONNECTED_STATE:

# Set the disable state of both buttons
window[sc.CONNECT_BUTTON].update(disabled=False)
window[sc.DISCONNECT_BUTTON].update(disabled=True)

# If we are in the disconnected state, wait until the connect button
# is pressed before moving to the connecting state.
if event == sc.CONNECT_BUTTON:
app_state = sc.CONNECTING_STATE

case _:
# If we are in this state, there is an issue with state control.
# If this print occurs, there is a code issue that must be resolved.
app_state = sc.EXITING_STATE

# Update the graphs on the UI that display the virtual LED strips
# if not in the process of exiting.
if app_state != sc.EXITING_STATE:
window[sc.STATUS_FIELD].update(sc.state_to_string[app_state])
39 changes: 39 additions & 0 deletions VirtualLEDStrip/sim_constants.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# State constants
CONNECTING_STATE = 0
CONNECTED_STATE = 1
DISCONNECTED_STATE = 2
EXITING_STATE = 3
state_to_string = [
'Connecting',
'Connected',
'Disconnected',
'Exiting'
]
DEFAULT_STATE = DISCONNECTED_STATE

# UI Elements
CONNECT_BUTTON = "Connect"
DISCONNECT_BUTTON = "Disconnect"
STATUS_FIELD = "-STATUS-"
HSV_KEY = "HSV"
BGR_KEY = "BGR"
RGB_KEY = "RGB"
LOGO_SCALE = 10
LOGO_RELATIVE_PATH = '\\assets\logo2.png'
ICON_RELATIVE_PATH = '\\assets\icon.ico'
APP_NAME = "Nanolux LED Strip Simulator"
APP_THEME = 'SystemDefault'
COM_SELECTOR_KEY = 'COMSelector'
RESCAN_BUTTON = 'Rescan'

# Numpy Constants
DEFAULT_LED_HEIGHT = 1
DEFAULT_LED_WIDTH = 60
LED_BAR_TARGET_LENGTH = 600

# Debug
NO_DEBUG = False
DEBUG = True

# Connection constants
NO_SERIAL_PORT = 'No Serial'
Loading

0 comments on commit fdf3fd0

Please sign in to comment.