Skip to content

MOB-15: torch / flashlight support in core (Mob.Torch) - #61

Merged
GenericJam merged 2 commits into
masterfrom
MOB-15-torch
Jul 5, 2026
Merged

MOB-15: torch / flashlight support in core (Mob.Torch)#61
GenericJam merged 2 commits into
masterfrom
MOB-15-torch

Conversation

@GenericJam

Copy link
Copy Markdown
Owner

What

Adds Mob.Torch — a rear-camera torch (flashlight) on/off toggle in core mob. This is the mob half; the Kotlin MobBridge.torch method is the paired GenericJam/mob_new PR.

Linear: MOB-15 (Tier-2 hardware gap from the capability audit).

Mob.Torch.on(socket)# or .off(socket), or .set(socket, bool)

Design decisions (flagging for review — see decisions/2026-07-04-torch.md)

  1. Core, not mob_camera. Both platforms toggle the torch without a capture session and without the camera permission (iOS AVCaptureDevice.lockForConfiguration + torchMode; Android CameraManager.setTorchMode). So it has no camera-plugin dependency and belongs with the other lightweight permission-free outputs like Mob.Haptic. Easy to move into mob_camera instead if you'd rather — say the word.
  2. On/off only for v1. iOS supports a brightness level (setTorchModeOnWithLevel:) but Android setTorchMode is binary (per-torch strength is API 33+ only). A cross-platform level: option would be honored on one side and clamped on the other, so it's deferred to keep the contract honest. v1 drives iOS at max level.
  3. Fire-and-forget, no-op when absent. Mirrors Mob.Haptic.trigger/2 — returns the socket unchanged; a device with no flash unit (tablets, the simulator) is a no-op, not an error (both native sides guard on hardware presence).

Layers

  • lib/mob/torch.exon/1, off/1, set/2; pure state_atom/1 mapping extracted for host-testing (the MOB-6 pattern).
  • src/mob_nif.erltorch/1 NIF declaration + stub.
  • ios/mob_nif.mnif_torch + array entry.
  • android/jni/mob_nif.zignif_torchMobBridge.torch(String) via the cached-method seam (field + export + cacheRequired + NIF table entry).
  • test/mob/torch_test.exs, decisions/2026-07-04-torch.md, and a Torch row in guides/mobile_surface_matrix.md.

Tests / checks

972 pass (3 new). mix format, mix credo --strict, mix erlfmt --check src/, xcrun clang-format, and zig fmt --check all clean.

Merge coupling & verification

  • Cross-repo: merge this and release mob before an app regenerates its bridge (the generated Kotlin calls MobBridge.torch, and the zig CallStaticVoidMethod needs the method present). Same ordering as MOB-6.
  • Not device-verified — the simulator has no torch. On-hardware verification (torch actually lights on a real iPhone + Android) is the remaining gate, flagged like MOB-6 was.

🤖 Generated with Claude Code

GenericJamand others added 2 commits July 4, 2026 20:07
New Mob.Torch (on/1, off/1, set/2) toggles the rear-camera torch with no
camera session and no permission, so it's a lightweight core capability
alongside Mob.Haptic rather than part of mob_camera.
- lib/mob/torch.ex — on/off API; pure state_atom/1 mapping (host-testable)
- src/mob_nif.erl — torch/1 NIF declaration + stub
- ios/mob_nif.m — nif_torch: AVCaptureDevice torchMode, hasTorch guard,
setTorchModeOnWithLevel: at max; no-op without a torch
- android/jni/mob_nif.zig — nif_torch -> MobBridge.torch(String) via the
cached-method seam (Kotlin half is the paired mob_new change)
- test/mob/torch_test.exs — state_atom mapping + boolean guard
- decisions/2026-07-04-torch.md — core-vs-plugin + on/off-only rationale
- guides/mobile_surface_matrix.md — Torch row
On/off only for v1 (iOS supports brightness levels, Android setTorchMode is
binary — level is a follow-up). Device verification pending (no torch on the
simulator).
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Both platforms physically lit the rear flash on and off — Android via
:mob_nif.torch/1 over dist, iOS via an on-device Mob.Torch.set/2 button.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@GenericJam
GenericJam merged commit 3d6219e into masterJul 5, 2026
4 checks passed
GenericJam added a commit that referenced this pull request Jul 5, 2026
Ships MOB-15 (#61): Mob.Torch.on/off/set toggles the rear-camera torch with
no capture session and no permission. Device-verified on moto g power (2021)
and iPhone SE (3rd gen). Android Kotlin bridge ships via mob_new 0.4.17+.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

@GenericJam