Thread: Accessory port
View Single Post
Old 07-29-2012, 10:41 AM   #2
geekmaster
Carpe diem, c'est la vie.
geekmaster ought to be getting tired of karma fortunes by now.geekmaster ought to be getting tired of karma fortunes by now.geekmaster ought to be getting tired of karma fortunes by now.geekmaster ought to be getting tired of karma fortunes by now.geekmaster ought to be getting tired of karma fortunes by now.geekmaster ought to be getting tired of karma fortunes by now.geekmaster ought to be getting tired of karma fortunes by now.geekmaster ought to be getting tired of karma fortunes by now.geekmaster ought to be getting tired of karma fortunes by now.geekmaster ought to be getting tired of karma fortunes by now.geekmaster ought to be getting tired of karma fortunes by now.
 
geekmaster's Avatar
 
Posts: 6,433
Karma: 10773668
Join Date: Nov 2011
Location: Multiverse 6627A
Device: K1 to PW3
Quote:
Originally Posted by mmatej View Post
As the accessory port is being ignored as an output port here (I haven't found here it's used somewhere), I created script that sends text string to the port.
Spoiler:
acsend.sh:
Code:
#!/bin/sh
ac='/sys/devices/system/mx50_accessory/mx50_accessory0/mx50_accessory_state'
rate=10000
nullstop=$(expr 3 \* ${rate})

get_chcode()
{
echo $(printf '%d' "$'$1")
}
binconv()
{
padto=0
[ ${#2} -ne 0 ] && padto=${2}
bstr=''
d=0
num=${1}
while [ ${num} -ne 0 ]; do
d=$(expr ${d} + 1)
bit=$(expr ${num} % 2)
bstr="${bit}""${bstr}"
num=$(expr ${num} / 2)
done
while true; do
[ ${padto} -eq 0 ] && break
[ ${d} -ge ${padto} ] && break
padleft=$(expr ${padto} - ${d})
bnulls=''
for i in $(seq 1 ${padleft}); do
bnulls="${bnulls}"'0'
done
bstr="${bnulls}""${bstr}"
break
done
echo "${bstr}"
}

[ ${#1} -eq 0 ] && return 1
str=''
for i in $(seq 0 $(expr ${#1} - 1)); do
code=$(get_chcode "${1:${i}:1}")
[ ${i} -ne 0 ] && str="${str}"' '
str="${str}""$(binconv ${code} 8)"
done
str="${str}"' '
sto=$(expr ${#str} - 1)
chp=0
echo -n "${1:${chp}:1}"
for i in $(seq 0 ${sto}); do
state="${str:${i}:1}"
[ "${state}" == ' ' ] &&
{
echo 0 > ${ac}
usleep ${nullstop}
chp=$(expr ${chp} + 1)
[ ${i} -ne ${sto} ] && echo -n "${1:${chp}:1}"
continue
}
echo ${state} > ${ac}
usleep ${rate}
done
echo

Connect the LED to the port and try it with ./acsend.sh 'Hello World!'!
Timing is very unreliable because it's shell script, but it's not bad anyway.
Thanks! That has been on my "To Do" list for a long time (with no plans to do it any time soon). I am curious if the kindle can be charged through that port too -- if so you could also use it as an input port.

I was thinking of using the green and yellow power LEDs on a K4 to give it PWM stereo sound output (using photocells with color filters connected to an audio amplifier). Perhaps it would be easier to drive a speaker directly (with a current limiting resistor) if we PWM the accessory port output.

More karma for you!

EDIT: Not that it *really* matters when running programs from mmc (especially with this busybox that "short circuits" its own built-ins and ignores the "normal" load process), but the '[' conditional is a PROGRAM that loads and runs from the /bin folder (as I recall), but '[[' is an intrinsic that is executed directly by the shell. This really only makes a difference on non-busybox systems, but it is a good habit (even though it uses more characters on the line).

I love it when people take things off my "To Do" list:

2012-Mar-09:
Quote:
Originally Posted by geekmaster View Post
... Don't ask me "when" -- that project is WAY down on my "To Do" list. You can probably PWM the accessory power port (square metal pads on the bottom) to drive a speaker directly (with a current-limit resistor), if mono sound is okay. The pad just below the USB port is GND, and the other pad is +4V when enabled.
2012-Jun-11:
Quote:
Originally Posted by geekmaster View Post
... On the K4 and K5, the square pads on the back are ferrous so that you can connect to them with magnetic power connectors. To connect to these power pads, you could use tiny magnets taken from "magnetic stick and ball toys" (e.g. Magnetix brand), with wires attached, but then you would violate a patent for the obvious use of using magnets to attach a power connector (owned by Apple). On the K4 and K5, the ground pad is just above the USB jack, and power to the other jack is controlled by software (you can turn in on and off in diags). ...

Last edited by geekmaster; 07-29-2012 at 11:34 AM.
geekmaster is offline   Reply With Quote