-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
46 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
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)" |
This file contains 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