Skip to content

Commit 7f544f1

Browse files
committed
Repackage and focus on Python only code.
1 parent 27a7dfc commit 7f544f1

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+806
-6044
lines changed
File renamed without changes.

Dockerfile

Lines changed: 0 additions & 20 deletions
This file was deleted.

Makefile

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
LIBRARY_NAME := $(shell hatch project metadata name 2> /dev/null)
2+
LIBRARY_VERSION := $(shell hatch version 2> /dev/null)
3+
4+
.PHONY: usage install uninstall check pytest qa build-deps check tag wheel sdist clean dist testdeploy deploy
5+
usage:
6+
ifdef LIBRARY_NAME
7+
@echo "Library: ${LIBRARY_NAME}"
8+
@echo "Version: ${LIBRARY_VERSION}\n"
9+
else
10+
@echo "WARNING: You should 'make dev-deps'\n"
11+
endif
12+
@echo "Usage: make <target>, where target is one of:\n"
13+
@echo "install: install the library locally from source"
14+
@echo "uninstall: uninstall the local library"
15+
@echo "dev-deps: install Python dev dependencies"
16+
@echo "check: perform basic integrity checks on the codebase"
17+
@echo "qa: run linting and package QA"
18+
@echo "pytest: run Python test fixtures"
19+
@echo "clean: clean Python build and dist directories"
20+
@echo "build: build Python distribution files"
21+
@echo "testdeploy: build and upload to test PyPi"
22+
@echo "deploy: build and upload to PyPi"
23+
@echo "tag: tag the repository with the current version\n"
24+
25+
install:
26+
./install.sh --unstable
27+
28+
uninstall:
29+
./uninstall.sh
30+
31+
dev-deps:
32+
python3 -m pip install -r requirements-dev.txt
33+
sudo apt install dos2unix
34+
35+
check:
36+
@bash check.sh
37+
38+
qa:
39+
tox -e qa
40+
41+
pytest:
42+
tox -e py
43+
44+
nopost:
45+
@bash check.sh --nopost
46+
47+
tag:
48+
git tag -a "v${LIBRARY_VERSION}" -m "Version ${LIBRARY_VERSION}"
49+
50+
build: check
51+
@hatch build
52+
53+
clean:
54+
-rm -r dist
55+
56+
testdeploy: build
57+
twine upload --repository testpypi dist/*
58+
59+
deploy: nopost build
60+
twine upload dist/*

README.md

Lines changed: 65 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -1,89 +1,65 @@
1-
![Blinkt!](blinkt-logo.png)
2-
3-
[![Build Status](https://travis-ci.com/pimoroni/blinkt.svg?branch=master)](https://travis-ci.com/pimoroni/blinkt)
4-
[![Coverage Status](https://coveralls.io/repos/github/pimoroni/blinkt/badge.svg?branch=master)](https://coveralls.io/github/pimoroni/blinkt?branch=master)
5-
[![PyPi Package](https://img.shields.io/pypi/v/blinkt.svg)](https://pypi.python.org/pypi/blinkt)
6-
[![Python Versions](https://img.shields.io/pypi/pyversions/blinkt.svg)](https://pypi.python.org/pypi/blinkt)
7-
8-
https://shop.pimoroni.com/products/blinkt
9-
10-
Eight super-bright RGB LED indicators, ideal for adding visual notifications to your Raspberry Pi on their own or on a pHAT stacking header.
11-
12-
## Installing
13-
14-
### Full install (recommended):
15-
16-
We've created an easy installation script that will install all pre-requisites and get your Blinkt!
17-
up and running with minimal efforts. To run it, fire up Terminal which you'll find in Menu -> Accessories -> Terminal
18-
on your Raspberry Pi desktop, as illustrated below:
19-
20-
![Finding the terminal](http://get.pimoroni.com/resources/github-repo-terminal.png)
21-
22-
In the new terminal window type the command exactly as it appears below (check for typos) and follow the on-screen instructions:
23-
24-
```bash
25-
curl https://get.pimoroni.com/blinkt | bash
26-
```
27-
28-
Alternatively, on Raspbian, you can download the `pimoroni-dashboard` and install your product by browsing to the relevant entry:
29-
30-
```bash
31-
sudo apt-get install pimoroni
32-
```
33-
(you will find the Dashboard under 'Accessories' too, in the Pi menu - or just run `pimoroni-dashboard` at the command line)
34-
35-
If you choose to download examples you'll find them in `/home/pi/Pimoroni/blinkt/`.
36-
37-
### Manual install:
38-
39-
#### Library install for Python 3:
40-
41-
on Raspbian:
42-
43-
```bash
44-
sudo apt-get install python3-blinkt
45-
```
46-
47-
other environments:
48-
49-
```bash
50-
sudo pip3 install blinkt
51-
```
52-
53-
#### Library install for Python 2:
54-
55-
on Raspbian:
56-
57-
```bash
58-
sudo apt-get install python-blinkt
59-
```
60-
61-
other environments:
62-
63-
```bash
64-
sudo pip2 install blinkt
65-
```
66-
67-
### Development:
68-
69-
If you want to contribute, or like living on the edge of your seat by having the latest code, you should clone this repository, `cd` to the library directory, and run:
70-
71-
```bash
72-
sudo python3 setup.py install
73-
```
74-
(or `sudo python setup.py install` whichever your primary Python environment may be)
75-
76-
## Documentation & Support
77-
78-
* Guides and tutorials - https://learn.pimoroni.com/blinkt
79-
* Function reference - http://docs.pimoroni.com/blinkt/
80-
* GPIO Pinout - https://pinout.xyz/pinout/blinkt
81-
* Get help - http://forums.pimoroni.com/c/support
82-
83-
## Unofficial / Third-party libraries
84-
85-
* Golang library & examples by [Alex Ellis](https://www.alexellis.io) - https://github.com/alexellis/blinkt_go, https://github.com/alexellis/blinkt_go_examples
86-
* Java library by Jim Darby - https://github.com/hackerjimbo/PiJava
87-
* Java library by @HoldYourWaffle - https://github.com/HoldYourWaffle/blinkt4j
88-
* Node.js library by @irrelon - https://github.com/irrelon/node-blinkt
89-
* Rust library by @golemparts - https://github.com/golemparts/blinkt
1+
![Blinkt!](blinkt-logo.png)
2+
3+
[![Build Status](https://travis-ci.com/pimoroni/blinkt.svg?branch=master)](https://travis-ci.com/pimoroni/blinkt)
4+
[![Coverage Status](https://coveralls.io/repos/github/pimoroni/blinkt/badge.svg?branch=master)](https://coveralls.io/github/pimoroni/blinkt?branch=master)
5+
[![PyPi Package](https://img.shields.io/pypi/v/blinkt.svg)](https://pypi.python.org/pypi/blinkt)
6+
[![Python Versions](https://img.shields.io/pypi/pyversions/blinkt.svg)](https://pypi.python.org/pypi/blinkt)
7+
8+
https://shop.pimoroni.com/products/blinkt
9+
10+
Eight super-bright RGB LED indicators, ideal for adding visual notifications to your Raspberry Pi on their own or on a pHAT stacking header.
11+
12+
## Installing
13+
14+
### Full install (recommended):
15+
16+
We've created an easy installation script that will install all pre-requisites and get your Blinkt!
17+
up and running with minimal efforts. To run it, fire up Terminal which you'll find in Menu -> Accessories -> Terminal
18+
on your Raspberry Pi desktop, as illustrated below:
19+
20+
![Finding the terminal](http://get.pimoroni.com/resources/github-repo-terminal.png)
21+
22+
In the new terminal window type the command exactly as it appears below (check for typos) and follow the on-screen instructions:
23+
24+
```bash
25+
git clone https://github.com/pimoroni/blinkt
26+
cd blinkt
27+
./install.sh
28+
```
29+
30+
### Manual install:
31+
32+
```bash
33+
python3 -m pip install blinkt
34+
```
35+
### Development:
36+
37+
If you want to contribute, or like living on the edge of your seat by having the latest code, you should clone this repository, `cd` to the library directory, and run:
38+
39+
```bash
40+
make dev-deps
41+
make build
42+
```
43+
44+
To run QA and tests, use:
45+
46+
```bash
47+
make check
48+
make qa
49+
make pytest
50+
```
51+
52+
## Documentation & Support
53+
54+
* Guides and tutorials - https://learn.pimoroni.com/blinkt
55+
* Function reference - http://docs.pimoroni.com/blinkt/
56+
* GPIO Pinout - https://pinout.xyz/pinout/blinkt
57+
* Get help - http://forums.pimoroni.com/c/support
58+
59+
## Unofficial / Third-party libraries
60+
61+
* Golang library & examples by [Alex Ellis](https://www.alexellis.io) - https://github.com/alexellis/blinkt_go, https://github.com/alexellis/blinkt_go_examples
62+
* Java library by Jim Darby - https://github.com/hackerjimbo/PiJava
63+
* Java library by @HoldYourWaffle - https://github.com/HoldYourWaffle/blinkt4j
64+
* Node.js library by @irrelon - https://github.com/irrelon/node-blinkt
65+
* Rust library by @golemparts - https://github.com/golemparts/blinkt

library/blinkt.py renamed to blinkt/__init__.py

Lines changed: 25 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22
import atexit
33
import time
44

5-
import RPi.GPIO as GPIO
5+
import gpiod
6+
7+
from gpiod.line import Direction, Value
68

79

810
__version__ = '0.1.2'
@@ -11,20 +13,13 @@
1113
CLK = 24
1214
NUM_PIXELS = 8
1315
BRIGHTNESS = 7
16+
GPIOCHIP = "/dev/gpiochip4"
1417

1518
pixels = [[0, 0, 0, BRIGHTNESS]] * NUM_PIXELS
1619

1720
sleep_time = 0
1821

19-
_gpio_setup = False
20-
_clear_on_exit = True
21-
22-
23-
def _exit():
24-
if _clear_on_exit:
25-
clear()
26-
show()
27-
GPIO.cleanup()
22+
gpio_lines = None
2823

2924

3025
def set_brightness(brightness):
@@ -48,45 +43,47 @@ def clear():
4843

4944
def _write_byte(byte):
5045
for x in range(8):
51-
GPIO.output(DAT, byte & 0b10000000)
52-
GPIO.output(CLK, 1)
46+
gpio_lines.set_value(DAT, Value.ACTIVE if (byte & 0b10000000) else Value.INACTIVE)
47+
gpio_lines.set_value(CLK, Value.ACTIVE)
5348
time.sleep(sleep_time)
5449
byte <<= 1
55-
GPIO.output(CLK, 0)
50+
gpio_lines.set_value(CLK, Value.INACTIVE)
5651
time.sleep(sleep_time)
5752

5853

5954
# Emit exactly enough clock pulses to latch the small dark die APA102s which are weird
6055
# for some reason it takes 36 clocks, the other IC takes just 4 (number of pixels/2)
6156
def _eof():
62-
GPIO.output(DAT, 0)
57+
gpio_lines.set_value(DAT, Value.INACTIVE)
6358
for x in range(36):
64-
GPIO.output(CLK, 1)
59+
gpio_lines.set_value(CLK, Value.ACTIVE)
6560
time.sleep(sleep_time)
66-
GPIO.output(CLK, 0)
61+
gpio_lines.set_value(CLK, Value.INACTIVE)
6762
time.sleep(sleep_time)
6863

6964

7065
def _sof():
71-
GPIO.output(DAT, 0)
66+
gpio_lines.set_value(DAT, Value.INACTIVE)
7267
for x in range(32):
73-
GPIO.output(CLK, 1)
68+
gpio_lines.set_value(CLK, Value.ACTIVE)
7469
time.sleep(sleep_time)
75-
GPIO.output(CLK, 0)
70+
gpio_lines.set_value(CLK, Value.INACTIVE)
7671
time.sleep(sleep_time)
7772

7873

7974
def show():
8075
"""Output the buffer to Blinkt!."""
81-
global _gpio_setup
82-
83-
if not _gpio_setup:
84-
GPIO.setmode(GPIO.BCM)
85-
GPIO.setwarnings(False)
86-
GPIO.setup(DAT, GPIO.OUT)
87-
GPIO.setup(CLK, GPIO.OUT)
88-
atexit.register(_exit)
89-
_gpio_setup = True
76+
global gpio_lines
77+
78+
if not gpio_lines:
79+
gpio_lines = gpiod.request_lines(
80+
GPIOCHIP,
81+
consumer="blinkt",
82+
config={
83+
DAT: gpiod.LineSettings(direction=Direction.OUTPUT, output_value=Value.INACTIVE),
84+
CLK: gpiod.LineSettings(direction=Direction.OUTPUT, output_value=Value.INACTIVE)
85+
}
86+
)
9087

9188
_sof()
9289

0 commit comments

Comments
 (0)