Skip to content

Commit

Permalink
motors: add dw9714 control script
Browse files Browse the repository at this point in the history
  • Loading branch information
gtxaspec committed Nov 30, 2024
1 parent 233be0f commit fd7e7f7
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 0 deletions.
5 changes: 5 additions & 0 deletions package/motors/Config.in
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,8 @@ config BR2_PACKAGE_MOTORS
select BR2_MOTORS_TCU if !BR2_MOTORS_MS419XX
help
Userspace programs to manage motor hardware

config BR2_PACKAGE_MOTORS_DW9714_ONLY
bool "DW9714 Focus Control"
help
Enable support for DW9714 VCM, includes control script
33 changes: 33 additions & 0 deletions package/motors/files/dw9714-ctrl
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/bin/sh

# Script to control the DW9714 VCM focus using BusyBox i2c commands
# Takes an argument from 0 to 100 to set the focus position percentage

if [ "$#" -ne 1 ]; then
echo "Usage: $0 <focus_percentage>"
echo "<focus_percentage> should be an integer from 0 to 100"
exit 1
fi

FOCUS_PERCENTAGE=$1

# Validate input
if [ "$FOCUS_PERCENTAGE" -lt 0 ] || [ "$FOCUS_PERCENTAGE" -gt 100 ]; then
echo "Error: focus_percentage must be between 0 and 100."
exit 1
fi

# Translate focus percentage from 0-100 to 0-50
TRANSLATED_FOCUS=$((FOCUS_PERCENTAGE * 50 / 100))

# Convert translated percentage to DAC value (0-511)
DAC_VALUE=$((TRANSLATED_FOCUS * 511 / 50))

# Construct the 16-bit value to send to the DAC
HIGH_BYTE=$(( (DAC_VALUE >> 4) & 0xFF ))
LOW_BYTE=$(( (DAC_VALUE << 4) & 0xF0 ))

# Send the value using i2cset (assumes I2C bus 0 and address 0x0c)
i2cset -y 0 0x0c $HIGH_BYTE $LOW_BYTE i

echo "Focus set to $FOCUS_PERCENTAGE% (Translated to: $TRANSLATED_FOCUS%, DAC value: $DAC_VALUE)"
8 changes: 8 additions & 0 deletions package/motors/motors.mk
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ MOTORS_VERSION = $(shell git ls-remote $(MOTORS_SITE) $(MOTORS_SITE_BRANCH) | he
MOTORS_LICENSE = MIT
MOTORS_LICENSE_FILES = LICENSE

ifeq ($(BR2_PACKAGE_MOTORS_DW9714_ONLY),y)
define MOTORS_INSTALL_TARGET_CMDS
$(INSTALL) -m 755 -d $(TARGET_DIR)/usr/sbin
$(INSTALL) -m 755 $(MOTORS_PKGDIR)/files/dw9714-ctrl -t $(TARGET_DIR)/usr/sbin
endef
else
define MOTORS_BUILD_CMDS
$(TARGET_CC) $(TARGET_LDFLAGS) -Os -s $(@D)/motor.c -o $(@D)/motors
$(TARGET_CC) $(TARGET_LDFLAGS) -Os -s $(@D)/motor-daemon.c -o $(@D)/motors-daemon
Expand All @@ -20,8 +26,10 @@ define MOTORS_INSTALL_TARGET_CMDS

$(INSTALL) -m 755 -d $(TARGET_DIR)/usr/sbin/
$(INSTALL) -m 755 -t $(TARGET_DIR)/usr/sbin $(MOTORS_PKGDIR)/files/ptz_presets

$(INSTALL) -m 755 -d $(TARGET_DIR)/etc
$(INSTALL) -m 644 -t $(TARGET_DIR)/etc $(MOTORS_PKGDIR)/files/ptz_presets.conf
endef
endif

$(eval $(generic-package))

0 comments on commit fd7e7f7

Please sign in to comment.