Skip to content

Commit

Permalink
Merge pull request #15 from cpvalente/chore/examples
Browse files Browse the repository at this point in the history
Chore/examples
  • Loading branch information
cpvalente authored Aug 31, 2021
2 parents 2c25183 + 05d81a5 commit cb8b767
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 10 deletions.
18 changes: 10 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,18 @@
### Installing from github
You can get up and running quickly cloning from github.
Run the example file to make sure everything is up to scratch
```
```bash
$ git clone https://github.com/cpvalente/stupidArtnet.git
$ cd stupidArtnet
$ python3 example.py
$ python3 examples/example.py
```
### Installing from Pip
The project is now available in [Pip](https://pypi.org/project/stupidArtnet/1.0/) and can be installed with
```pip install stupidartnet```

### Basics
Sending simple Artnet packets is pretty easy
```
```python
# A StupidArtnet instance holds a target IP / universe and a buffer
a = StupidArtnet(target_ip, universe, packet_size)

Expand All @@ -43,10 +43,10 @@ a.show()
a.show()

# I HAVE ALSO ADDED AN UTILITY FUNCITON .send()
# THIS WOULD TACKE THE EFFECT OF DOING SETTING THE PACKET
# AND SHOWING THAT PACKET
# THIS WOULD TAKE THE EFFECT OF SETTING THE BUFFER
# AND CALLING SHOW
# a.set(packet)
# a.show(packet)
# a.show()
a.send(packet)

```
Expand All @@ -69,7 +69,9 @@ for x in range(100):
a.stop()
```

### Persistent sending
See examples
- [x] Use with Tkinter

### Notes

Expand Down Expand Up @@ -125,7 +127,7 @@ Artnet uses the concept of Universes and Subnets for data routing. I simplified
This will look correct and behave fine for smaller networks, wanting to be able to specify Universes, Subnets and Nets you can disable simplification and give values as needed. <br />
The spec for Artnet 4 applies here: 128 Nets contain 16 Subnets which contain 16 Universes. 128 * 16 * 16 = 32 768 Universes

```
```python
# Create a StupidArtnet instance with the relevant values

# By default universe is simplified to a value between 0 - 255
Expand Down
4 changes: 2 additions & 2 deletions example.py → stupidArtnet/examples/example.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from stupidArtnet import StupidArtnet
from stupidArtnet.StupidArtnet import StupidArtnet
import time
import random

Expand All @@ -25,7 +25,7 @@

# YOU CAN CREATE YOUR OWN BYTE ARRAY OF PACKET_SIZE
packet = bytearray(packet_size) # create packet for Artnet
for i in range(packet_size): # fill packet with sequential values
for i in range(packet_size): # fill packet with sequential values
packet[i] = (i % 256)

# ... AND SET IT TO STUPID ARTNET
Expand Down
68 changes: 68 additions & 0 deletions stupidArtnet/examples/tkinter_slider_to_artnet.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
"""(Very) Simple Example of using Tkinter with StupidArtnet.
It creates a simple window with a slider of value 0-255
This value is streamed in universe 0 channel 1
Note: The example imports stupid artnet locally from
a parent folder, real use import would be simpler
"""

from stupidArtnet.StupidArtnet import StupidArtnet
from tkinter import *


def updateValue(val):
"""Callback from slider onchange.
Sends the value of the slider to the artnet channel."""

global stupid
stupid.set_single_value(1, slider_val.get())


def cleanup():
"""Cleanup function for when window is closed.
Closes socket and destroys object."""
print('cleanup')

global stupid
stupid.stop()
del stupid

global window
window.destroy()


# ARTNET CODE
# -------------

# Create artnet object
stupid = StupidArtnet()

# Start persistent thread
stupid.start()


# TKINTER CODE
# --------------

# Create window object
window = Tk()

# Hold value of the slider
slider_val = IntVar()

# Create slider
scale = Scale(window, variable=slider_val,
command=updateValue, from_=255, to=0)
scale.pack(anchor=CENTER)

# Create label with value
label = Label(window)
label.pack()

# Cleanup on exit
window.protocol("WM_DELETE_WINDOW", cleanup)

# Start
window.mainloop()

0 comments on commit cb8b767

Please sign in to comment.