Better controller code
This commit is contained in:
parent
a6a2d19ff8
commit
7811684bad
1
.gitignore
vendored
1
.gitignore
vendored
@ -1,3 +1,4 @@
|
|||||||
*.zip
|
*.zip
|
||||||
.vscode
|
.vscode
|
||||||
.idea
|
.idea
|
||||||
|
*.bin
|
||||||
|
@ -4,12 +4,29 @@ local function getTextY(line)
|
|||||||
end
|
end
|
||||||
|
|
||||||
function love.draw2()
|
function love.draw2()
|
||||||
|
local width, height = love.graphics.getDimensions()
|
||||||
|
|
||||||
-- Set background
|
-- Set background
|
||||||
love.graphics.setBackgroundColor(0, 0, 0)
|
love.graphics.setBackgroundColor(0, 0, 0)
|
||||||
love.graphics.setColor(1, 1, 1)
|
love.graphics.setColor(1, 1, 1)
|
||||||
|
|
||||||
|
-- Draw camera feed
|
||||||
if BotState.camfeed then
|
if BotState.camfeed then
|
||||||
love.graphics.draw(BotState.camfeed)
|
local imageWidth = BotState.camfeed:getWidth()
|
||||||
|
local imageHeight = BotState.camfeed:getHeight()
|
||||||
|
|
||||||
|
local scaleWidth = width / imageWidth
|
||||||
|
local scaleHeight = height / imageHeight
|
||||||
|
local scale = math.min(scaleWidth, scaleHeight)
|
||||||
|
|
||||||
|
local scaledWidth = imageWidth * scale
|
||||||
|
local scaledHeight = imageHeight * scale
|
||||||
|
|
||||||
|
love.graphics.draw(BotState.camfeed,
|
||||||
|
(width - scaledWidth) / 2, (height - scaledHeight) / 2,
|
||||||
|
0,
|
||||||
|
scale, scale
|
||||||
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Draw time
|
-- Draw time
|
||||||
|
@ -2,13 +2,13 @@ FROM alpine:3.20.1
|
|||||||
|
|
||||||
RUN apk add --no-cache git meson alpine-sdk cmake linux-headers python3 python3-dev \
|
RUN apk add --no-cache git meson alpine-sdk cmake linux-headers python3 python3-dev \
|
||||||
py3-yaml py3-jinja2 py3-ply py3-pybind11 py3-pybind11-dev py3-paho-mqtt
|
py3-yaml py3-jinja2 py3-ply py3-pybind11 py3-pybind11-dev py3-paho-mqtt
|
||||||
#RUN apk add --no-cache libcamera libcamera-tools libcamera-v4l2 python3 python3-dev \
|
|
||||||
# cython py3-setuptools alpine-sdk ffmpeg ffmpeg-dev
|
|
||||||
|
|
||||||
WORKDIR /libcamera
|
WORKDIR /libcamera
|
||||||
ADD libcamera /libcamera
|
ADD libcamera /libcamera
|
||||||
RUN meson setup --prefix /usr build && ninja -C build install
|
RUN meson setup --prefix /usr build && ninja -C build install
|
||||||
|
|
||||||
|
RUN apk add --no-cache py3-pillow
|
||||||
|
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
COPY mfb.py /app
|
COPY mfb.py /app
|
||||||
COPY spider-cam.py /app
|
COPY spider-cam.py /app
|
||||||
|
@ -3,10 +3,12 @@ import paho.mqtt.client as mqtt
|
|||||||
import selectors
|
import selectors
|
||||||
import sys
|
import sys
|
||||||
import time
|
import time
|
||||||
|
import io
|
||||||
|
from PIL import Image
|
||||||
|
|
||||||
import mfb
|
import mfb
|
||||||
|
|
||||||
image_count = 0
|
image_count = 9999
|
||||||
|
|
||||||
def camera_name(camera):
|
def camera_name(camera):
|
||||||
return camera.id
|
return camera.id
|
||||||
@ -16,12 +18,18 @@ def handle_camera_event(cm):
|
|||||||
for req in reqs:
|
for req in reqs:
|
||||||
process_request(req)
|
process_request(req)
|
||||||
|
|
||||||
|
def sendImage(plane):
|
||||||
|
image = Image.frombytes("RGBA", (800, 600), plane.tobytes())
|
||||||
|
pngBytes = io.BytesIO()
|
||||||
|
image.save(pngBytes, "png")
|
||||||
|
mqttc.publish("spider/telemetry/camfeed", pngBytes.getvalue())
|
||||||
|
|
||||||
def process_request(request):
|
def process_request(request):
|
||||||
global camera, image_count
|
global camera, image_count
|
||||||
global mqttc
|
global mqttc
|
||||||
|
|
||||||
image_count += 1
|
image_count += 1
|
||||||
if image_count > 50:
|
if image_count > 30:
|
||||||
image_count = 0
|
image_count = 0
|
||||||
print(f'Request completed: {request}')
|
print(f'Request completed: {request}')
|
||||||
|
|
||||||
@ -37,7 +45,7 @@ def process_request(request):
|
|||||||
'/'.join([str(p.bytes_used) for p in metadata.planes]))
|
'/'.join([str(p.bytes_used) for p in metadata.planes]))
|
||||||
with mfb.MappedFrameBuffer(buffer) as mappedBuffer:
|
with mfb.MappedFrameBuffer(buffer) as mappedBuffer:
|
||||||
for plane in mappedBuffer.planes:
|
for plane in mappedBuffer.planes:
|
||||||
mqttc.publish("spider/telemetry/camfeed", plane[0:256000].tobytes())
|
sendImage(plane)
|
||||||
|
|
||||||
request.reuse()
|
request.reuse()
|
||||||
camera.queue_request(request)
|
camera.queue_request(request)
|
||||||
|
File diff suppressed because one or more lines are too long
Loading…
x
Reference in New Issue
Block a user