Add BodyEmulator sketch; refactor shared code into lib/#4
Draft
jenogc wants to merge 1 commit intoLexOptical:masterfrom
Draft
Add BodyEmulator sketch; refactor shared code into lib/#4jenogc wants to merge 1 commit intoLexOptical:masterfrom
jenogc wants to merge 1 commit intoLexOptical:masterfrom
Conversation
Restructures the project into three components that maximise code reuse:
lib/
Shared protocol library used by both sketches:
- Constants.h pin assignments, protocol constants, lens response payloads
- DebugTools.h generic writeSerialDebugable(port, ...) replacing the
Serial1-specific writeSerial1Debuggable; fixes latent bug
where flushDebugOutputBuffer checked debugInputBufferPosition
instead of debugOutputBufferPosition
- Message.h/.cpp, Message05.h/.cpp unchanged from original
LensEmulator/
Former E-Mount.ino updated to use lib/ includes, the new debug helper
signatures, and the named pin constants from Constants.h. LISTEN_ONLY
and emulation modes work as before.
BodyEmulator/
New sketch that emulates a Sony E-Mount camera body:
- Generates a 60 Hz VD clock on PIN4 via Teensy IntervalTimer
- Drives BODY_CS_LENS (PIN3) and monitors LENS_CS_BODY (PIN2)
- Sends body->lens messages on Serial2 TX (PIN10)
- Receives lens->body responses on Serial1 RX (PIN0)
- State machine: CS handshake -> init sequence (0x01..0x10) ->
normal mode with periodic 0x04 queries
- Public API: requestAF(position), requestAperture(value)
- Parses 0x05 responses for aperture and AF position
README updated with repo layout, mode comparison table, and per-mode
pin assignment table.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Author
|
I haven't tested any of this on hardware yet. The idea is to emulate both camera and lens and move all common code shared between the emulators to a shared location. PR will remain in draft form until I have time to build the hardware and test this PR |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
lib/(Constants, DebugTools, Message, Message05) so both sketches stay in sync automaticallyLensEmulator/— the original sketch updated to uselib/and named pin constantsBodyEmulator/— new sketch that emulates a camera bodyBodyEmulator details
Wiring (Teensy 3.5):
Behaviour:
IntervalTimer0x01, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0D, 0x10in sequence; state machine advances on each lens response0x04lens-data queries each VD windowrequestAF(position)andrequestAperture(value)queue a0x03command for the next window0x05responses and logs aperture value and AF position bytes to SerialAlso fixes a latent bug in
DebugTools.hwhereflushDebugOutputBuffercheckeddebugInputBufferPosition(always 0) instead ofdebugOutputBufferPosition, causing it to always print "no message".Test plan
requestAF()produces a 0x03 message on the wirerequestAperture()via packet capture and update TODO comment🤖 Generated with Claude Code