Skip to content

Commit

Permalink
Update m5x camera driver and append _ for devices that end with numbers
Browse files Browse the repository at this point in the history
  • Loading branch information
bill88t committed Feb 6, 2024
1 parent e0aca40 commit f83860f
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 77 deletions.
119 changes: 43 additions & 76 deletions extra/ov3660_m5x/LjinuxRoot/bin/camera.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
)

if "init" in vr("opts")["o"] or "i" in vr("opts")["o"]:
ljinux.api.setvar("return", "1")
if vr("dev") not in ljinux.devices:
if "mode" in vr("opts")["o"] or "m" in vr("opts")["o"]:
if "mode" in vr("opts")["o"]:
Expand Down Expand Up @@ -47,52 +48,57 @@
toml=ljinux.api.betterpath(vr("pr")),
),
)
ljinux.devices[vr("dev")] = espcamera.Camera(
data_pins=board.D,
pixel_clock_pin=board.PCLK,
vsync_pin=board.VSYNC,
href_pin=board.HREF,
i2c=board.SSCB_I2C(),
external_clock_pin=board.XCLK,
external_clock_frequency=20_000_000,
powerdown_pin=None,
reset_pin=board.RESET,
pixel_format=vr("px"),
frame_size=vr("fr"),
jpeg_quality=vr("qual"),
framebuffer_count=1,
grab_mode=espcamera.GrabMode.LATEST,
ljinux.devices[vr("dev")] = []
ljinux.devices[vr("dev")].append(
espcamera.Camera(
data_pins=board.D,
pixel_clock_pin=board.PCLK,
vsync_pin=board.VSYNC,
href_pin=board.HREF,
i2c=board.SSCB_I2C(),
external_clock_pin=board.XCLK,
external_clock_frequency=20_000_000,
powerdown_pin=None,
reset_pin=board.RESET,
pixel_format=vr("px"),
frame_size=vr("fr"),
jpeg_quality=vr("qual"),
framebuffer_count=1,
grab_mode=espcamera.GrabMode.LATEST,
)
)
term.write('Initializing camera on mode "' + vr("mode") + '"')
ljinux.devices[vr("dev")].vflip = True
ljinux.devices[vr("dev")].denoise = cptoml.fetch(
ljinux.devices[vr("dev")][0].vflip = True
ljinux.devices[vr("dev")][0].denoise = cptoml.fetch(
"denoise",
toml=ljinux.api.betterpath(vr("pr")),
)
ljinux.devices[vr("dev")].awb_gain = True
ljinux.devices[vr("dev")][0].awb_gain = True
sleep(0.5)
ljinux.devices[vr("dev")].take()
ljinux.devices[vr("dev")][0].take()
term.write("Initialized!")
ljinux.api.setvar("return", "0")
else:
term.write("Camera already initialized.")

if "capture" in vr("opts")["o"] or "c" in vr("opts")["o"]:
ljinux.api.setvar("return", "1")
if vr("dev") not in ljinux.devices:
term.write("Camera not initialized.")
else:
vr("photo_data", ljinux.devices[vr("dev")].take(0.4))
vr("ql", ljinux.devices[vr("dev")].quality)
vr("photo_data", ljinux.devices[vr("dev")][0].take(0.4))
vr("ql", ljinux.devices[vr("dev")][0].quality)
while not isinstance(vr("photo_data"), memoryview):
if ljinux.devices[vr("dev")].quality < 20:
ljinux.devices[vr("dev")].quality += 1
vr("photo_data", ljinux.devices[vr("dev")].take(0.4))
if ljinux.devices[vr("dev")][0].quality < 20:
ljinux.devices[vr("dev")][0].quality += 1
vr("photo_data", ljinux.devices[vr("dev")][0].take(0.4))
term.write(
'Snapped! Quality={}\nSaving to "'.format(
ljinux.devices[vr("dev")].quality
ljinux.devices[vr("dev")][0].quality
),
end="",
)
ljinux.devices[vr("dev")].quality = vr("ql")
ljinux.devices[vr("dev")][0].quality = vr("ql")
vr("tt", time.localtime())
vr("pic_name", "M5X-")
if vr("tt").tm_mday < 10:
Expand All @@ -115,59 +121,20 @@
with ljinux.api.fopen(vr("pic_name"), "wb") as pv[get_pid()]["f"]:
vr("f").write(vr("photo_data"))
term.write("Saved!")

# if "serve" in vr("opts")["o"] or "s" in vr("opts")["o"]:
# if vr("dev") not in ljinux.devices:
# term.write("Camera not initialized.")
# else:
#
#
#
# term.write(
# "Starting RTSP Camera server on "
# + str(ipconf["ip"])
# + ":80"
# )
# webserver = HTTPServer(ljinux.modules["network"]._pool)
# @webserver.route("/capture", "POST")
# def base(request):
# ljinux.io.ledset(3)
# vr("res", "FAIL: Invalid form.")
# vr("raw", request.raw_request.decode("UTF-8").split())
# vr("data_pos", vr("raw").find('{"'))
# if vr("data_pos") != -1:
# import json
# vr("data", loads(" ".join(vr("raw")[vr("pos"):])))
# term.write("Got: " + str(vr("data")))
# vr("res", "ok")
# del json
# return HTTPResponse(body=vr("res"))
#
# @webserver.route("/")
# def base(request):
# ljinux.io.ledset(3)
# return HTTPResponse(body=vr("res"))
#
# ipconf = ljinux.modules["network"].get_ipconf()
# term.write("Started. Press Ctrl + C to stop.")
# webserver.start(
# host=str(ipconf["ip"]),
# port=80,
# )
# while not term.is_interrupted():
# try:
# webserver.poll()
# except KeyboardInterrupt:
# term.write("Exiting")
# except Exception as err:
# term.write(f"Error: {err}")
ljinux.api.setvar("return", "0")

if "deinit" in vr("opts")["o"] or "d" in vr("opts")["o"]:
ljinux.api.setvar("return", "1")
if vr("dev") not in ljinux.devices:
term.write("Camera not initialized.")
term.write("Camera not initialized!")
else:
ljinux.devices[vr("dev")].deinit()
del ljinux.devices[vr("dev")], espcamera
ljinux.devices[vr("dev")][0].deinit()
ljinux.devices[vr("dev")].pop()
if not len(ljinux.devices[vr("dev")]):
del ljinux.devices[vr("dev")], espcamera
term.write("Camera deinitialized successfully.")
ljinux.api.setvar("return", "0")

if not len(vr("opts")["o"]) or "h" in vr("opts")["o"] or "help" in vr("opts")["o"]:
term.write("help menu here")
ljinux.based.run("cat /usr/share/help/camera.txt")
ljinux.api.setvar("return", "0")
11 changes: 11 additions & 0 deletions extra/ov3660_m5x/LjinuxRoot/usr/share/help/camera.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
Usage: camera [OPTION...]
Configure and capture camera data.

-h, --help give this help list
-i, --init initialize the camera
-d, --deinit deinitialize the camera
-c, --capture capture a photo, and save it to a file
-m, --mode use an alternative mode

Default settings are configured in "/etc/camera.d/config.toml".
The different modes are in "/etc/camera.d/presets/".
5 changes: 4 additions & 1 deletion source/ljinux.py
Original file line number Diff line number Diff line change
Expand Up @@ -800,10 +800,13 @@ def listdir(path=".") -> list:
devs.sort()
terms.sort()
for i in devs:
name = i
if name[-1].isdigit():
name += "_"
for j in range(len(ljinux.devices[i])):
res.append(
[
i + str(j),
name + str(j),
"c",
[7, 7, 7],
0,
Expand Down

0 comments on commit f83860f

Please sign in to comment.