Skip to content

Commit f5d82e5

Browse files
committed
initial commit
0 parents  commit f5d82e5

4 files changed

Lines changed: 154 additions & 0 deletions

File tree

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
dots.py
2+
__pycache__

README.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# python-fluepdot
2+
3+
This is a small collection of functions for interacting with a
4+
[fluepdot](https://fluepdot.readthedocs.io/en/latest/) module.
5+
6+
the first call after importing should always be to set the URL at
7+
which the module can be reached.
8+
9+
```python
10+
import fluepdot as fd
11+
12+
fd.set_url("module.local")
13+
```
14+
15+
## Functions
16+
17+
18+
function | args | default values | return type | description
19+
---|---|---|---|---
20+
post_time ||| None | indefinitly sets the module to display the current time.
21+
get_size ||| (int, int) | returns the size of the connected display
22+
get_frame ||| str | returns the current frame stored by the module
23+
get_pixel | x: int, y: int | x=0, y=0 | returns the state of a single pixel
24+
get_fonts ||| None | prints a list of fonts installed on the module
25+
get_mode ||| fluepdot.Mode | returns the mode the module is in
26+
post_text | text: str, x: int, y: int, font: str | x=0, y=0, font="DejaVuSans12" | requests.Response | posts a text to the module and returns the requests response
27+
post_frame | frame: List[List[bool]] || requests.Response | posts a frame to the module and returns the requests response
28+
set_pixel | x: int, y: int | x=0, y=0 | requests.Response | sets a pixel on the display to active and returns the requests response
29+
unset_pixel | x: int, y: int | x=0, y=0 | sets a pixel on thes display to inactive and returns the requests response
30+
set_mode | mode: fluepdot.Mode | mode=Mode.FULL | requests.Response | sets the module to FULL or DIFFERENTIAL update mode and returns the requests response

fluepdot.py

Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
# python fluepdot module
2+
3+
import requests
4+
import binascii
5+
from requests import Response
6+
from enum import Enum
7+
from typing import Any, Dict, Optional, List
8+
9+
"""
10+
Small library to interact with a fluepdot controled display
11+
https://fluepdot.readthedocs.io/en/latest/
12+
13+
it should only be required to change the baseURL
14+
15+
Currently there is no support for changing the timings.
16+
"""
17+
18+
GetParam = Dict[str, Any]
19+
PostParam = str
20+
21+
class Mode(Enum):
22+
FULL = 0
23+
DIFFERENTIAL = 1
24+
25+
# endpoints:
26+
baseURL: str = None
27+
frameURL: str = "/framebuffer"
28+
pixelURL: str = "/pixel"
29+
textURL: str = "/framebuffer/text"
30+
fontURL: str = "/fonts"
31+
modeURL: str = "/rendering/mode"
32+
33+
# size defaults:
34+
width: int=115
35+
height: int=16
36+
37+
fonts: Optional[List[str]] = None
38+
39+
def set_url(url: str):
40+
baseURL = url
41+
42+
def post_time() -> None:
43+
import datetime
44+
dt: str = ""
45+
while True:
46+
ndt: str = datetime.datetime.now().strftime("%d.%m.%y %H:%M")
47+
if ndt != dt:
48+
dt = ndt
49+
post_text(dt, x=8, y=1, font="fixed_7x14")
50+
51+
52+
def get_size() -> (int, int):
53+
global width, height
54+
frame=get_frame()
55+
width=len(frame[0])
56+
height=len(frame)-1
57+
return [width, height]
58+
59+
def get_frame() -> List[str]:
60+
r = _get(frameURL)
61+
return r.text.split('\n')
62+
63+
def get_pixel(x: int=0, y: int=0 ) -> bool:
64+
r = _get(pixelURL, get={x, y})
65+
print(r)
66+
return False
67+
68+
def get_fonts() -> None:
69+
r = _get(fontURL)
70+
fonts = r.text.split("\n")
71+
print(fonts)
72+
73+
def get_mode() -> Mode:
74+
r = _get(modeURL)
75+
return Mode(r.text)
76+
77+
def post_text(text: str, x: int = 0, y: int = 0, font: str = "DejaVuSans12") -> Response:
78+
return _post(textURL, get={"x": x, "y": y, "font": font}, post=text)
79+
80+
def post_frame(frame: List[List[bool]]) -> Response:
81+
data: List(List(str)) = [[" "]*width for _ in range(height)]
82+
for x, l in frame:
83+
for y, b in l:
84+
if b:
85+
try:
86+
data[x, y] = "X"
87+
except IndexError as e:
88+
print(e)
89+
return _post(frameURL, post=data)
90+
91+
def set_pixel(x: int=0, y: int=0) -> Response:
92+
return _post(pixelURL, get={x, y})
93+
94+
def unset_pixel(x: int=0, y: int=0) -> Response:
95+
return _delete(pixelURL, get={x, y})
96+
97+
def set_mode(mode: Mode=Mode.FULL) -> Response:
98+
return _put(modeURL, post=str(mode.value))
99+
100+
def _delete(endpoint: str, get: GetParam={}, post: PostParam='') -> Response:
101+
if baseURL == None:
102+
raise RuntimeError('baseURL is None, call set_url')
103+
return requests.delete(url=baseURL+endpoint, params=get)
104+
105+
def _post(endpoint: str, get: GetParam={}, post: PostParam='') -> Response:
106+
if baseURL == None:
107+
raise RuntimeError('baseURL is None, call set_url')
108+
return requests.post(url=baseURL+endpoint, params=get, data=post)
109+
110+
def _put(endpoint: str, get: GetParam={}, post: PostParam='') -> Response:
111+
if baseURL == None:
112+
raise RuntimeError('baseURL is None, call set_url')
113+
return requests.put(url=baseURL+endpoint, params=get, data=post)
114+
115+
def _get(endpoint: str, get: GetParam={}) -> Response:
116+
if baseURL == None:
117+
raise RuntimeError('baseURL is None, call set_url')
118+
return requests.get(url=baseURL+endpoint, params=get)
119+
120+
if __name__ == "__main__":
121+
pass

requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
requests

0 commit comments

Comments
 (0)