|
1 | | -# AnimatedLEDStrip Client Library for Python |
2 | | - |
3 | 1 | [](https://travis-ci.com/AnimatedLEDStrip/client-python) |
4 | 2 | [](https://pypi.python.org/pypi/animatedledstrip-client) |
5 | 3 | [](https://codecov.io/gh/AnimatedLEDStrip/client-python) |
6 | 4 |
|
7 | | -This library allows a Python 3 client to connect to an AnimatedLEDStrip server, allowing the client to send animations to the server and receive currently running animations from the server, among other information. |
| 5 | +# AnimatedLEDStrip Client Library for Python |
| 6 | + |
| 7 | +This library allows a Python 3 client to communicate with an AnimatedLEDStrip server. |
8 | 8 |
|
9 | 9 | ## Adding the Library to a Project |
| 10 | + |
10 | 11 | The library is available via pip: |
11 | 12 |
|
12 | 13 | ```bash |
13 | 14 | pip3 install animatedledstrip-client |
14 | 15 | ``` |
15 | 16 |
|
16 | 17 | ## Creating an `AnimationSender` |
17 | | -An `AnimationSender` is constructed with two arguments: |
18 | | -- `ip_address`: The IP address of the server (as a string) |
19 | | -- `port_num`: The port that the client should connect to (as an integer) |
20 | 18 |
|
21 | | -```python |
22 | | -from animatedledstrip import AnimationSender |
23 | | - |
24 | | -sender = AnimationSender("10.0.0.254", 5) |
25 | | -``` |
26 | | - |
27 | | -## Starting an `AnimationSender` |
28 | | -An `AnimationSender` is started by calling the `start()` method on the instance. |
| 19 | +An `ALSHttpClient` is created with `ALSHttpClient(ip_address)`. |
29 | 20 |
|
30 | 21 | ```python |
31 | | -sender.start() |
32 | | -``` |
| 22 | +from animatedledstrip import ALSHttpClient |
33 | 23 |
|
34 | | -## Stopping the `AnimationSender` |
35 | | -An `AnimationSender` is stopped by calling the `end()` method on the instance. |
36 | | - |
37 | | -```python |
38 | | -sender.end() |
| 24 | +sender = ALSHttpClient('10.0.0.254') |
39 | 25 | ``` |
40 | 26 |
|
41 | | -## Sending Data |
42 | | -An animation can be sent to the server by creating an instance of the `AnimationData` class, then calling `send_animation()` with the instance as the argument. |
| 27 | +## Communicating with the Server |
43 | 28 |
|
44 | | -```python |
45 | | -from animatedledstrip import AnimationData, ColorContainer |
46 | | - |
47 | | -color = ColorContainer() |
48 | | -color.add_color(0xFF) |
49 | | -color.add_color(0xFF00) |
50 | | - |
51 | | -data = AnimationData() |
52 | | -data.add_color(color) |
53 | | - |
54 | | -sender.send_data(data) |
55 | | -``` |
56 | | - |
57 | | -#### `AnimationData` type notes |
58 | | -The Python library uses the following values for `continuous` and `direction`: |
59 | | -- `continuous`: `None`, `True`, `False` |
60 | | -- `direction`: `Direction.FORWARD`, `Direction.BACKWARD` |
61 | | - |
62 | | -## Receiving Data |
63 | | -Received animations are saved to the `running_animations` dict and removed when an `EndAnimation` is received for that animation. |
64 | | - |
65 | | -In addition, the Python library uses callbacks that run functions to allow you to specify what to do with data that is received. |
66 | | - |
67 | | -### ReceiveCallback |
68 | | -The `receiveCallback` is called whenever the sender receives `bytes` from the server. |
69 | | -The `bytes` are passed to your callback. |
70 | | -Use the `newAnimationDataCallback`, `newAnimationInfoCallback`, `newEndAnimationCallback`, `newSectionCallback` *(Coming soon)* and `newStripInfoCallback` *(Coming soon)* callbacks to handle each type of data. |
71 | | -Runs before `newAnimationDataCallback`, `newAnimationInfoCallback`, `newEndAnimationCallback`, `newSectionCallback` and `newStripInfoCallback`. |
72 | | - |
73 | | -```python |
74 | | -def receiveData(data: bytes): |
75 | | - # Your code here |
76 | | - |
77 | | -sender.on_receive_callback = receiveData |
78 | | -``` |
| 29 | +This library follows the conventions laid out for [AnimatedLEDStrip client libraries](https://animatedledstrip.github.io/client-libraries), with the following modifications: |
79 | 30 |
|
80 | | -### NewAnimationDataCallback |
81 | | -The `newAnimationDataCallback` is called whenever the sender receives an `AnimationData` instance from the server. |
82 | | -The `AnimationData` instance is passed to your callback. |
83 | | -Runs after the `receiveCallback`. |
84 | | - |
85 | | -```python |
86 | | -def processAnimationData(data: 'AnimationData'): |
87 | | - # Your code here |
88 | | - |
89 | | -sender.on_new_animation_data_callback = processAnimationData |
90 | | -``` |
91 | | - |
92 | | -### NewAnimationInfoCallback |
93 | | -The `newAnimationInfoCallback` is called whenever the sender receives an `AnimationInfo` instance from the server. |
94 | | -The `AnimationInfo` instance is passed to your callback. |
95 | | -Runs after the `receiveCallback`. |
96 | | - |
97 | | -```python |
98 | | -def handleNewAnimationInfo(info: 'AnimationInfo'): |
99 | | - # Your code here |
100 | | - |
101 | | -sender.on_new_animation_info_callback = handleNewAnimationInfo |
102 | | -``` |
103 | | - |
104 | | -### NewEndAnimationCallback |
105 | | -The `newEndAnimationCallback` is called whenever the sender receives an `EndAnimation` instance from the server. |
106 | | -The `EndAnimation` instance is passed to your callback. |
107 | | -Runs after the `receiveCallback`. |
108 | | - |
109 | | -```python |
110 | | -def handleEndAnimation(anim: 'EndAnimation'): |
111 | | - # Your code here |
112 | | - |
113 | | -sender.on_new_end_animation_callback = handleEndAnimation |
114 | | -``` |
115 | | - |
116 | | -### NewSectionCallback *(Coming soon)* |
117 | | -The `newSectionCallback` is called whenever the sender receives a `Section` instance from the server. |
118 | | -The `Section` instance is passed to your callback. |
119 | | -Runs after the `receiveCallback`. |
120 | | - |
121 | | -```python |
122 | | -def newSectionHandler(sect: 'Section'): |
123 | | - # Your code here |
124 | | - |
125 | | -sender.on_new_section_callback = newSectionHandler |
126 | | -``` |
127 | | - |
128 | | -### NewStripInfoCallback *(Coming soon)* |
129 | | -The `newStripInfoCallback` is called whenever the sender receives a `StripInfo` instance from the server. |
130 | | -The `StripInfo` instance is passed to your callback. |
131 | | -Runs after the `receiveCallback`. |
132 | | - |
133 | | -```python |
134 | | -def processStripInfo(info: 'StripInfo'): |
135 | | - # Your code here |
136 | | - |
137 | | -sender.on_new_strip_info_callback = processStripInfo |
138 | | -``` |
| 31 | +- Function names and class variables are in snake case to follow Python style conventions |
| 32 | +- `get_supported_animations_dict` is provided as an alias for `get_supported_animations_map` |
| 33 | +- `get_sections_dict` is provided as an alias for `get_sections_map` |
0 commit comments