13 Commits

Author SHA1 Message Date
d63ed10d44 Add sentry 2023-06-03 21:26:15 +02:00
a53ab8e209 Add py.typed 2023-02-28 23:13:41 +01:00
f69939f783 Add pre-commit 2023-02-28 22:51:50 +01:00
ce1d881c84 Add pre commit 2023-02-28 22:45:14 +01:00
0cb91e268d Version bump 2023-02-28 21:19:17 +01:00
2ece5d2bee Added method for projector sleep 2023-02-28 21:18:12 +01:00
24ef94cce9 Add Done badge 2022-11-12 21:52:27 +01:00
5f6544e939 Small Changes 2022-09-04 16:51:59 +02:00
6405418f42 Added a Readme 2022-07-05 16:08:14 +02:00
991fcff5b3 Changes 2022-07-05 15:48:45 +02:00
3990149c53 Now with sleep! 2022-07-04 21:52:47 +02:00
a44f01b2ee Add pre-commit 2022-06-25 19:17:22 +02:00
8a40a9ad5b Ahum 2022-06-25 18:37:56 +02:00
14 changed files with 1176 additions and 21 deletions

3
.gitignore vendored
View File

@@ -1,3 +1,4 @@
.vscode/
### Generated by gibo (https://github.com/simonwhitaker/gibo) ### Generated by gibo (https://github.com/simonwhitaker/gibo)
### https://raw.github.com/github/gitignore/e5323759e387ba347a9d50f8b0ddd16502eb71d4/Python.gitignore ### https://raw.github.com/github/gitignore/e5323759e387ba347a9d50f8b0ddd16502eb71d4/Python.gitignore
@@ -215,5 +216,3 @@ Sessionx.vim
tags tags
# Persistent undo # Persistent undo
[._]*.un~ [._]*.un~

21
.pre-commit-config.yaml Normal file
View File

@@ -0,0 +1,21 @@
# See https://pre-commit.com for more information
# See https://pre-commit.com/hooks.html for more hooks
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v3.2.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-yaml
- id: check-added-large-files
- repo: https://github.com/python-poetry/poetry
rev: 1.4.0 # add version here
hooks:
- id: poetry-check
- id: poetry-lock
- id: poetry-export
args: ["-f", "requirements.txt", "-o", "requirements.txt"]
- repo: https://github.com/psf/black
rev: 23.1.0
hooks:
- id: black

View File

@@ -671,4 +671,4 @@ into proprietary programs. If your program is a subroutine library, you
may consider it more useful to permit linking proprietary applications with may consider it more useful to permit linking proprietary applications with
the library. If this is what you want to do, use the GNU Lesser General the library. If this is what you want to do, use the GNU Lesser General
Public License instead of this License. But first, please read Public License instead of this License. But first, please read
<https://www.gnu.org/licenses/why-not-lgpl.html>. <https://www.gnu.org/licenses/why-not-lgpl.html>.

5
Makefile Normal file
View File

@@ -0,0 +1,5 @@
.PHONY: publish
publish:
poetry publish --build --repository gitea
clean:
find . -type f -name "*.py[co]" -delete -or -type d -name "__pycache__" -delete -or -type -name "dist" -delete

35
README.md Normal file
View File

@@ -0,0 +1,35 @@
[![Build Status](https://drone.marijndoeve.nl/api/badges/Marijn/ProjectorPi/status.svg)](https://drone.marijndoeve.nl/Marijn/ProjectorPi)
# ProjectorPi
Projector is a personal tool I user to control my _Panasonic PT-RW330_ projector and _Extron IN1604 DTP_ scalar over serial using a Raspberry Pi.
## Build wheels
Building the project can be done using poetry.
```shell
$ poetry build
```
## Install locally
```shell
$ pip install .
```
## Usage
Make sure the user is a member of the `dialout` group.
Wake projector and scaler and select input 2:
```shell
$ projectorpi 2
```
Put projector and scalar in sleep mode:
```shell
$ projectorpi --sleep
```

1075
poetry.lock generated

File diff suppressed because it is too large Load Diff

View File

@@ -1,9 +1,9 @@
[tool.poetry] [tool.poetry]
name = "ProjectorPi" name = "ProjectorPi"
version = "0.1.0" version = "0.3.0"
description = "" description = ""
authors = ["Marijn Doeve <marijn@doeve.me>"] authors = ["Marijn Doeve <marijn@doeve.me>"]
licence = "GPL-3.0-or-later" license = "GPL-3.0-or-later"
[tool.poetry.scripts] [tool.poetry.scripts]
projectorpi = "projectorpi.cli:main" projectorpi = "projectorpi.cli:main"
@@ -11,8 +11,14 @@ projectorpi = "projectorpi.cli:main"
[tool.poetry.dependencies] [tool.poetry.dependencies]
python = "^3.9" python = "^3.9"
pyserial = "^3.5" pyserial = "^3.5"
sentry-sdk = "^1.25.0"
[tool.poetry.dev-dependencies] [tool.poetry.dev-dependencies]
black = "*"
mypy = "^0.961"
pre-commit = "^2.19.0"
twine = "^4.0.1"
types-setuptools = "^57.4.18"
[build-system] [build-system]
requires = ["poetry-core>=1.0.0"] requires = ["poetry-core>=1.0.0"]

12
requirements.txt Normal file
View File

@@ -0,0 +1,12 @@
certifi==2023.5.7 ; python_version >= "3.9" and python_version < "4.0" \
--hash=sha256:0f0d56dc5a6ad56fd4ba36484d6cc34451e1c6548c61daad8c320169f91eddc7 \
--hash=sha256:c6c2e98f5c7869efca1f8916fed228dd91539f9f1b444c314c06eef02980c716
pyserial==3.5 ; python_version >= "3.9" and python_version < "4.0" \
--hash=sha256:3c77e014170dfffbd816e6ffc205e9842efb10be9f58ec16d3e8675b4925cddb \
--hash=sha256:c4451db6ba391ca6ca299fb3ec7bae67a5c55dde170964c7a14ceefec02f2cf0
sentry-sdk==1.25.0 ; python_version >= "3.9" and python_version < "4.0" \
--hash=sha256:5be3296fc574fa8a4d9b213b4dcf8c8d0246c08f8bd78315c6286f386c37555a \
--hash=sha256:fe85cf5d0b3d0aa3480df689f9f6dc487de783defb0a95043368375dc893645e
urllib3==2.0.2 ; python_version >= "3.9" and python_version < "4.0" \
--hash=sha256:61717a1095d7e155cdb737ac7bb2f4324a858a1e2e6466f6d03ff630ca68d3cc \
--hash=sha256:d055c2f9d38dc53c808f6fdc8eab7360b6fdbbde02340ed25cfbcd817c62469e

View File

@@ -0,0 +1,2 @@
from .extron import ExtronSerial
from .projector import ProjectorSerial

View File

@@ -1,8 +1,20 @@
#! /usr/bin/env python3 #! /usr/bin/env python3
from argparse import ArgumentParser from argparse import ArgumentParser
from time import sleep
from .projector import ProjectorSerial from .projector import ProjectorSerial
from .extron import ExtronSerial from .extron import ExtronSerial
import sentry_sdk
sentry_sdk.init(
dsn="https://4a9c016c11074639a16778c78709e402@sentry.marijndoeve.nl/2",
# Set traces_sample_rate to 1.0 to capture 100%
# of transactions for performance monitoring.
# We recommend adjusting this value in production.
traces_sample_rate=1.0,
)
verbose = False verbose = False
@@ -34,6 +46,7 @@ def main():
if args.input: if args.input:
proj.power_on() proj.power_on()
extr.wake() extr.wake()
sleep(1)
extr.change_input(args.input) extr.change_input(args.input)
elif args.sleep: elif args.sleep:

View File

@@ -1,6 +1,4 @@
# w == escape import sys
# | == carriage return
from types import LambdaType
from typing import Callable from typing import Callable
from .serialdevice import SerialDevice from .serialdevice import SerialDevice
@@ -42,10 +40,15 @@ class ExtronSerial(SerialDevice):
response = super().send_command(command) response = super().send_command(command)
if response and response[0] == "E": if response and response[0] == "E":
print(response, self.ERRORS.get(response, "Unknown")) print(
f"{response}: {self.ERRORS.get(response, 'Unknown')}", file=sys.stderr
)
return response return response
def _check_sleep(self) -> str:
return self.send_command(C("PSAV"))
def sleep(self) -> None: def sleep(self) -> None:
self.send_command(C("1PSAV")) self.send_command(C("1PSAV"))
@@ -56,7 +59,7 @@ class ExtronSerial(SerialDevice):
self.send_command(f"{input}!") self.send_command(f"{input}!")
def is_sleeping(self) -> bool: def is_sleeping(self) -> bool:
response = self.send_command(C("PSAV")) response = self._check_sleep()
return bool(int(response)) return bool(int(response))

View File

@@ -16,7 +16,7 @@ class ProjectorSerial(SerialDevice):
def send_command(self, command: str, device_id: str = "ZZ") -> str: def send_command(self, command: str, device_id: str = "ZZ") -> str:
assert device_id in ["01", "02", "03", "04", "05", "06", "ZZ"] assert device_id in ["01", "02", "03", "04", "05", "06", "ZZ"]
full_command = f"\x02AD{device_id};{command}\x03" full_command = f"{STX}AD{device_id};{command}{ETX}"
return super().send_command(full_command) return super().send_command(full_command)
@@ -25,3 +25,6 @@ class ProjectorSerial(SerialDevice):
def power_off(self) -> None: def power_off(self) -> None:
self.send_command("POF") self.send_command("POF")
def is_on(self) -> bool:
return self.send_command("QPW") == "001"

0
src/projectorpi/py.typed Normal file
View File

View File

@@ -12,7 +12,6 @@ class SerialDevice:
self.prefix = "" self.prefix = ""
def send_command(self, command: str) -> str: def send_command(self, command: str) -> str:
with Serial(self.serial_port, self.baudrate, timeout=3) as s: with Serial(self.serial_port, self.baudrate, timeout=3) as s:
if self.verbose: if self.verbose:
print(self.prefix, "send:", command) print(self.prefix, "send:", command)