Files
nandi 52b42890d6
CI / test (push) Canceled after 0s
Camera: C ISP pipeline, contrast autofocus, and VFR video
- Add chandra-camera-isp.c (C/OpenMP) for Quad-Bayer unpack, CCM, and tone mapping, with a NumPy fallback when it is not built
- Add non-blocking contrast-detection VCM autofocus, with lens subdev discovery on the sensor's I2C bus
- Tune Quad-Bayer AE: a video-mode vblank cap, damped steps, and full analog gain before extending blanking
- Record variable-frame-rate video through a streaming Matroska muxer, and count dropped frames
- Ship libcamera IPA tuning files for imx376, imx519, and uncalibrated sensors
- Map camera buffers by fd and sync them with dma-buf ioctls
2026-11-28 19:25:43 -08:00

192 lines
6.6 KiB
MoonBit

///| The network panel module (components/network) driven through the shell, against a fake
/// network backend: the status it shows, its Wi-Fi list, and the actions its clicks and keys ask
/// for. Needs the modules: run scripts/build-modules.sh.
///|
fn net_status() -> @network.NetStatus {
{
state: Wifi,
name: "Home",
signal: 72,
message: "",
wifi_enabled: true,
airplane: false,
managed: true,
has_wifi: true,
}
}
///|
fn net_comp(tag : String) -> (@host.ChandraCompositor, @network.FakeNet) {
let comp = new_comp(tag)
let fake = @network.FakeNet::new(net_status(), [
{ ssid: "Home", signal: 72, secured: true, active: true, saved: true },
{ ssid: "Office", signal: 55, secured: true, active: false, saved: false },
{ ssid: "Cafe", signal: 30, secured: false, active: false, saved: false },
{ ssid: "Lab", signal: 20, secured: true, active: false, saved: true },
])
comp.shell.set_network_backend(fake as &@network.NetBackend)
ignore(comp.compose_frame())
(comp, fake)
}
///| The middle of popup row `i` (6 px margin, 30 px rows), `dx` from its left edge.
fn net_row(comp : @host.ChandraCompositor, i : Int, dx? : Int = 60) -> (Int, Int) {
let pr = comp.shell.slot_popup_rect(comp.shell.slot_of("network"))
(pr.x + dx, pr.y + 6 + i * 30 + 14)
}
///|
fn click_row(comp : @host.ChandraCompositor, i : Int, t : UInt, dx? : Int = 60) -> Unit {
let (x, y) = net_row(comp, i, dx~)
click_at(comp, x, y, t)
}
///|
fn last_action(fake : @network.FakeNet) -> @network.NetAction? {
fake.actions.last()
}
///|
test "the network module lists Wi-Fi networks and asks to connect, disconnect and forget" {
let (comp, fake) = net_comp("net-list")
let slot = comp.shell.slot_of("network")
assert_true(comp.shell.slot_rect(slot).w > 0) // it is in the default panel
assert_true(fake.ticks > 0)
click_module(comp, "network", 1U)
assert_eq(last_action(fake), Some(Scan)) // opening the popup scans
// Status, Wi-Fi, Airplane mode, the heading, four networks.
let pr = comp.shell.slot_popup_rect(slot)
assert_eq(pr.h, 12 + 8 * 30)
// An open network connects at once; so does a saved one.
click_row(comp, 6, 10U)
assert_eq(last_action(fake), Some(Connect("Cafe", "")))
click_row(comp, 7, 15U)
assert_eq(last_action(fake), Some(Connect("Lab", "")))
// "Forget" at the right of a saved network.
click_row(comp, 7, 20U, dx=pr.w - 30)
assert_eq(last_action(fake), Some(Forget("Lab")))
// The one in use disconnects.
click_row(comp, 4, 25U)
assert_eq(last_action(fake), Some(Disconnect))
assert_eq(fake.actions.length(), 5)
}
///|
test "a new secured network asks for its password in the popup" {
let (comp, fake) = net_comp("net-password")
let slot = comp.shell.slot_of("network")
click_module(comp, "network", 1U)
click_row(comp, 5, 5U) // Office: a password field opens under it
assert_eq(comp.shell.slot_popup_rect(slot).h, 12 + 9 * 30)
assert_eq(last_action(fake), Some(Scan))
for k in ["s", "3", "c", "r", "e", "t", "x", "Backspace", "Space", "1"] {
comp.shell.key_down(k)
}
comp.shell.key_down("Enter")
ignore(comp.compose_frame())
assert_eq(last_action(fake), Some(Connect("Office", "s3cret 1")))
assert_eq(comp.shell.slot_popup_rect(slot).h, 12 + 8 * 30) // the field is gone
// Escape leaves the field first, then the popup.
click_row(comp, 5, 10U)
comp.shell.key_down("p")
comp.shell.key_down("Escape")
ignore(comp.compose_frame())
assert_eq(comp.shell.slot_popup_rect(slot).h, 12 + 8 * 30)
comp.shell.key_down("Escape")
ignore(comp.compose_frame())
assert_eq(comp.shell.slot_popup_rect(slot).w, 0)
assert_eq(last_action(fake), Some(Connect("Office", "s3cret 1"))) // nothing sent for "p"
}
///|
test "the Wi-Fi and airplane switches, and status only without NetworkManager" {
let (comp, fake) = net_comp("net-switch")
let slot = comp.shell.slot_of("network")
click_module(comp, "network", 1U)
click_row(comp, 1, 5U) // Wi-Fi off: the list goes
assert_eq(last_action(fake), Some(SetWifi(false)))
assert_eq(comp.shell.slot_popup_rect(slot).h, 12 + 3 * 30)
click_row(comp, 1, 10U)
assert_eq(last_action(fake), Some(SetWifi(true)))
click_row(comp, 2, 15U)
assert_eq(last_action(fake), Some(SetAirplane(true)))
// A message shows under the status.
fake.status = { ..fake.status, message: "Couldn't connect to Office: wrong password?" }
ignore(comp.compose_frame())
assert_eq(comp.shell.slot_popup_rect(slot).h, 12 + 4 * 30)
// Read-only (no NetworkManager): the status and why, nothing to switch.
fake.status = {
..net_status(),
state: Wired,
name: "enp3s0",
managed: false,
message: "NetworkManager isn't running: status only",
}
ignore(comp.compose_frame())
assert_eq(comp.shell.slot_popup_rect(slot).h, 12 + 2 * 30)
let n = fake.actions.length()
click_row(comp, 1, 20U)
assert_eq(fake.actions.length(), n)
}
///| Whether any pixel in `r` looks like Noto Color Emoji's olive-green turtle (`g > r && g > b + 40`).
fn has_turtle_pixels(px : @renderer.Pixmap, r : @scene.Rect) -> Bool {
for y = r.y; y < r.y + r.h; y = y + 1 {
for x = r.x; x < r.x + r.w; x = x + 1 {
match px.pixel(x, y) {
Some(c) => {
let cr = c.r.to_int()
let cg = c.g.to_int()
let cb = c.b.to_int()
if cg > cr && cg > cb + 40 {
return true
}
}
None => ()
}
}
}
false
}
///| Whether any Text draw op inside `ops` contains `sub`.
fn ops_have_text(ops : Array[@scene.DrawOp], sub : String) -> Bool {
for op in ops {
match op {
Text(_, _, s, _, _, _, _) | MonoText(_, _, s, _, _, _, _) =>
if s.contains(sub) {
return true
}
_ => ()
}
}
false
}
///|
test "Wi-Fi SSID with turtle emoji survives wasm boundary and renders in colour" {
let comp = new_comp("net-turtle")
let fake = @network.FakeNet::new(
{ ..net_status(), name: "🐢" },
[
{ ssid: "🐢", signal: 72, secured: true, active: true, saved: true },
{ ssid: "🐢 5G", signal: 55, secured: true, active: false, saved: false },
],
)
comp.shell.set_network_backend(fake as &@network.NetBackend)
click_module(comp, "network", 1U)
comp.damage.mark_full()
let sg = comp.compose_scene().unwrap()
assert_true(ops_have_text(sg.panel_ops, "🐢"))
assert_true(ops_have_text(sg.panel_ops, "Connected to 🐢 (72%)"))
assert_true(ops_have_text(sg.panel_ops, "🐢 5G"))
let px = @renderer.render_scene(sg)
let slot = comp.shell.slot_of("network")
let btn = comp.shell.slot_rect(slot)
let pop = comp.shell.slot_popup_rect(slot)
assert_true(btn.w > 0 && pop.w > 0)
assert_true(has_turtle_pixels(px, btn))
assert_true(has_turtle_pixels(px, pop))
}