Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions display_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import dot3k.lcd as lcd
import st7036

# Initialize the LCD with SPI configuration
try:
lcd = st7036.st7036(register_select_pin=25, spi_bus=0, spi_chip_select=0) # Ensure these values match your setup
except Exception as e:
print(f"Failed to initialize Display-O-Tron LCD: {e}")
lcd = None
3 changes: 2 additions & 1 deletion docker/.env.sample
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ JAMS_URL=https://jams.jams
JAMS_API_TOKEN=your_jams_api_token
PG_USER=jolt
PG_PASS=jolt
PRINTER_IDENTIFIER=/dev/usb/lp0
PRINTER_IDENTIFIER=/dev/usb/lp0
USE_DISPLAY=False
24 changes: 19 additions & 5 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
# Use the official Python image from the Docker Hub
FROM python:3.12-slim

# Install libusb and other USB dependencies
RUN apt-get update && apt-get install -y libusb-1.0-0-dev usbutils
FROM python:3.12

# Install system dependencies for USB and GPIO
RUN apt-get update && \
apt-get install -y \
libusb-1.0-0-dev \
usbutils \
build-essential \
python3-dev \
python3-setuptools \
python3-wheel && \
rm -rf /var/lib/apt/lists/*

# Set the working directory
WORKDIR /jolt
Expand All @@ -19,6 +27,9 @@ COPY ./requirements.txt .
# Copy the check_db.py file into the container
COPY ./check_db.py .

# Copy the check_db.py file into the container
COPY ./display_test.py .

# Install any needed packages specified in requirements.txt
RUN pip install --no-cache-dir -r requirements.txt

Expand All @@ -28,8 +39,11 @@ RUN chmod +x entrypoint.sh
# Make check_db.py executable
RUN chmod +x check_db.py

# Make check_db.py executable
RUN chmod +x display_test.py

# Make port 5000 available to the world outside this container
EXPOSE 5000

# Run flask app with gunicorn
CMD ["bash", "entrypoint.sh"]
CMD ["python3", "display_test.py"]
8 changes: 8 additions & 0 deletions docker/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,23 @@ services:
container_name: jolt-server
restart: unless-stopped
command: ./entrypoint.sh
privileged: true # Only needed if using display
ports:
- "5000:5000"
environment:
- DATABASE_URL=postgresql://${PG_USER}:${PG_PASS}@jolt-db:5432/jolt-main
- JAMS_URL=https://jams.jams
- JAMS_API_TOKEN=your_jams_api_token
- PRINTER_IDENTIFIER='/dev/usb/lp0'
- USE_DISPLAY=False
volumes:
- /path/to/db_migrations:/jolt/migrations
# Optional for Display
- /sys/class/gpio:/sys/class/gpio
- /dev/mem:/dev/mem
- /dev/gpiomem:/dev/gpiomem
- /dev/spidev0.0:/dev/spidev0.0
- /dev/i2c-1:/dev/i2c-1
depends_on:
- jolt-db
jolt-db:
Expand Down
8 changes: 7 additions & 1 deletion jolt/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@
from dotenv import load_dotenv
from flask import Flask

from jolt.extensions import db, migrate, WSS
from jolt.extensions import db, migrate, WSS, DISPLAY
from jolt.routes import bp as routes_bp
from jolt.print_queue_handler import PrintQueueHandler
from jolt import helper


JAMS_URL = None
Expand All @@ -36,6 +37,11 @@ def create_app():
JAMS_API_TOKEN = os.getenv('JAMS_API_TOKEN', 'jams_api_token')
PRINTER_IDENTIFIER = os.getenv('PRINTER_IDENTIFIER', '/dev/usb/lp0')

use_display = os.getenv('USE_DISPLAY', False)
if use_display:
DISPLAY.init()
DISPLAY.show_text(helper.get_local_ip())

Http_headers['Authorization'] = JAMS_API_TOKEN

# Initialise DB
Expand Down
21 changes: 21 additions & 0 deletions jolt/display.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import dot3k.lcd as lcd
import time

class Display:
def init(self):
lcd.clear()

def show_text(self, text):
lcd.clear()

if len(text) <= 16:
lcd.write(text)
else:
self.scroll_text(text)

def scroll_text(self, text):
while True:
for i in range(len(text) - 15):
lcd.clear()
lcd.write(text[i:i+16])
time.sleep(0.2)
4 changes: 3 additions & 1 deletion jolt/extensions.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
from flask_sqlalchemy import SQLAlchemy
from flask_migrate import Migrate
from jolt.websocket_server import WebsocketServer
from jolt.display import Display

db = SQLAlchemy()
migrate = Migrate()
WSS = WebsocketServer()
WSS = WebsocketServer()
DISPLAY = Display()
10 changes: 10 additions & 0 deletions jolt/helper.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import socket
import psutil


def get_local_ip():
for interface, addresses in psutil.net_if_addrs().items():
for address in addresses:
if address.family == socket.AF_INET and not address.address.startswith("127."):
return address.address
return "127.0.0.1"
2 changes: 1 addition & 1 deletion jolt/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

bp = Blueprint('routes', __name__)

@bp.route('/')
@bp.route('/test')
def test():
success, error = print_image_label('Bot Test', 'Test Event')
if success:
Expand Down
11 changes: 2 additions & 9 deletions jolt/websocket_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
from urllib.parse import urlencode
import jolt
import psutil
import socket
from jolt.enums import RequestType
from jolt import helper

class WebsocketServer():
def __init__(self):
Expand Down Expand Up @@ -60,7 +60,7 @@ def process_incoming_message(self, message):
ram_usage = memory_info.percent
disk_info = psutil.disk_usage('/')
disk_usage = disk_info.percent
local_ip = self.get_local_ip()
local_ip = helper.get_local_ip()

from jolt import PQH
response_body = {
Expand All @@ -79,13 +79,6 @@ def process_incoming_message(self, message):

return None

def get_local_ip(self):
for interface, addresses in psutil.net_if_addrs().items():
for address in addresses:
if address.family == socket.AF_INET and not address.address.startswith("127."):
return address.address
return "127.0.0.1"

def build_websocket_message(self, type, body):
return {
'TYPE': type.name,
Expand Down
6 changes: 5 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,8 @@ Flask-Migrate
psycopg2-binary
psutil
requests
gunicorn
gunicorn
RPi.GPIO
dot3k
st7036
spidev