Little improvements, i guess
This commit is contained in:
parent
360312692b
commit
1bbb742315
@ -7,7 +7,10 @@ local errorMessage = nil
|
|||||||
local oldPrint = print
|
local oldPrint = print
|
||||||
|
|
||||||
function print(...)
|
function print(...)
|
||||||
local string = string.format(...)
|
local string = ""
|
||||||
|
for _, v in ipairs({...}) do
|
||||||
|
string = string .. v
|
||||||
|
end
|
||||||
love.mqtt.send("controller/stdout", string)
|
love.mqtt.send("controller/stdout", string)
|
||||||
oldPrint(...)
|
oldPrint(...)
|
||||||
end
|
end
|
||||||
|
@ -1078,7 +1078,7 @@ function client_mt:_apply_network_timeout()
|
|||||||
local allData = ""
|
local allData = ""
|
||||||
while true do
|
while true do
|
||||||
local size = math.min(totalSize, 16384)
|
local size = math.min(totalSize, 16384)
|
||||||
local data, err = sync_recv_func(size)
|
local data, err = sync_recv_func(size, ...)
|
||||||
if not data and (err == "timeout" or err == "wantread") then
|
if not data and (err == "timeout" or err == "wantread") then
|
||||||
loop.timeouted = true
|
loop.timeouted = true
|
||||||
coroutine_yield(err)
|
coroutine_yield(err)
|
||||||
|
@ -45,7 +45,7 @@ end
|
|||||||
-- Set connection's socket to non-blocking mode and set a timeout for it
|
-- Set connection's socket to non-blocking mode and set a timeout for it
|
||||||
function luasocket.settimeout(conn, timeout)
|
function luasocket.settimeout(conn, timeout)
|
||||||
conn.timeout = timeout
|
conn.timeout = timeout
|
||||||
conn.sock:settimeout(timeout, "t")
|
conn.sock:settimeout(timeout, "b")
|
||||||
end
|
end
|
||||||
|
|
||||||
-- export module table
|
-- export module table
|
||||||
|
@ -20,6 +20,7 @@ local function onMessage(data)
|
|||||||
end
|
end
|
||||||
|
|
||||||
local function onConnect(connack)
|
local function onConnect(connack)
|
||||||
|
print("Connected")
|
||||||
if connack.rc ~= 0 then
|
if connack.rc ~= 0 then
|
||||||
print("Connection to broker failed:", connack:reason_string())
|
print("Connection to broker failed:", connack:reason_string())
|
||||||
os.exit(1)
|
os.exit(1)
|
||||||
@ -29,7 +30,7 @@ local function onConnect(connack)
|
|||||||
topic = "spider/telemetry/#"
|
topic = "spider/telemetry/#"
|
||||||
})
|
})
|
||||||
|
|
||||||
print("Connected and subscribed")
|
print("Subscribed")
|
||||||
end
|
end
|
||||||
|
|
||||||
client = mqtt.client {
|
client = mqtt.client {
|
||||||
|
@ -29,7 +29,7 @@ def process_request(request):
|
|||||||
global mqttc
|
global mqttc
|
||||||
|
|
||||||
image_count += 1
|
image_count += 1
|
||||||
if image_count > 30:
|
if image_count > 10:
|
||||||
image_count = 0
|
image_count = 0
|
||||||
print(f'Request completed: {request}')
|
print(f'Request completed: {request}')
|
||||||
|
|
||||||
|
@ -2,7 +2,6 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/blackjack/webcam"
|
|
||||||
mqtt "github.com/eclipse/paho.mqtt.golang"
|
mqtt "github.com/eclipse/paho.mqtt.golang"
|
||||||
"log"
|
"log"
|
||||||
"time"
|
"time"
|
||||||
@ -45,79 +44,6 @@ func onPing(client mqtt.Client, msg mqtt.Message) {
|
|||||||
publishTelemetry(client, "pong", msg.Payload())
|
publishTelemetry(client, "pong", msg.Payload())
|
||||||
}
|
}
|
||||||
|
|
||||||
func handleWebcam(client mqtt.Client) {
|
|
||||||
cam, err := webcam.Open("/dev/video0")
|
|
||||||
if err != nil {
|
|
||||||
log.Fatalf("Could not open webcam: %v\n", err)
|
|
||||||
}
|
|
||||||
defer cam.Close()
|
|
||||||
|
|
||||||
supportedFormat := cam.GetSupportedFormats()
|
|
||||||
//log.Printf("Supported formats:\n")
|
|
||||||
imageFormat := webcam.PixelFormat(0)
|
|
||||||
for format, description := range supportedFormat {
|
|
||||||
if description == "10-bit Bayer GBGB/RGRG" {
|
|
||||||
imageFormat = format
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//width, height := 1296, 972
|
|
||||||
//width, height := uint32(2592), uint32(1944)
|
|
||||||
width, height := uint32(640), uint32(480)
|
|
||||||
|
|
||||||
if imageFormat != webcam.PixelFormat(0) {
|
|
||||||
_, _, _, err = cam.SetImageFormat(imageFormat, width, height)
|
|
||||||
if err != nil {
|
|
||||||
log.Fatalf("Could not set image format: %v\n", err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
supportedFramerates := cam.GetSupportedFramerates(imageFormat, width, height)
|
|
||||||
log.Printf("Supported frame rates:\n")
|
|
||||||
for _, format := range supportedFramerates {
|
|
||||||
log.Printf(" - %s\n", format)
|
|
||||||
}
|
|
||||||
|
|
||||||
controls := cam.GetControls()
|
|
||||||
log.Printf("Controls:\n")
|
|
||||||
for _, control := range controls {
|
|
||||||
log.Printf(" - %s\n", control)
|
|
||||||
}
|
|
||||||
|
|
||||||
//cam.SetAutoWhiteBalance(true)
|
|
||||||
//cam.SetControl()
|
|
||||||
|
|
||||||
//err = cam.SetFramerate(10)
|
|
||||||
//if err != nil {
|
|
||||||
// log.Fatalf("Could not set framerate: %v\n", err)
|
|
||||||
//}
|
|
||||||
|
|
||||||
err = cam.StartStreaming()
|
|
||||||
if err != nil {
|
|
||||||
log.Fatalf("Could not start streaming webcam: %v\n", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
count := 0
|
|
||||||
for {
|
|
||||||
err = cam.WaitForFrame(100)
|
|
||||||
if err != nil {
|
|
||||||
log.Fatalf("Could not start streaming webcam: %v\n", err)
|
|
||||||
}
|
|
||||||
frame, err := cam.ReadFrame()
|
|
||||||
if err != nil {
|
|
||||||
log.Fatalf("Could not read frame: %v\n", err)
|
|
||||||
}
|
|
||||||
if len(frame) > 0 {
|
|
||||||
count++
|
|
||||||
if count > 30*4 {
|
|
||||||
print("Publishing frame\n")
|
|
||||||
publishTelemetry(client, "camfeed", frame)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
opts := mqtt.NewClientOptions()
|
opts := mqtt.NewClientOptions()
|
||||||
opts.AddBroker(broker)
|
opts.AddBroker(broker)
|
||||||
@ -138,7 +64,6 @@ func main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
InitBattery()
|
InitBattery()
|
||||||
//go handleWebcam(client)
|
|
||||||
|
|
||||||
slowTelemetry := time.NewTicker(3 * time.Second)
|
slowTelemetry := time.NewTicker(3 * time.Second)
|
||||||
defer slowTelemetry.Stop()
|
defer slowTelemetry.Stop()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user