Skip to content

Commit 12034b2

Browse files
committed
Use tryPF in showactivity
1 parent 1678cc0 commit 12034b2

File tree

2 files changed

+148
-21
lines changed

2 files changed

+148
-21
lines changed

showactivity

Lines changed: 5 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
# o No longer show triggers of the leds (confusing)
1919
# 20141202 BL Set mmc0 trigger to outA for PF-leds
2020
# 20150114 BL adapt for kernel 3.16.7-ckt3-ev3dev1
21+
# 20150116 BL use /usr/local/bin/tryPF to add leds on outA
2122
#============================================================================
2223
#
2324
# set right green led to show I/O activity:
@@ -34,37 +35,20 @@ portletter="A"
3435
port="out${portletter}"
3536
# verify there is NO MOTOR on port outA
3637
findmotorctl "${port}"
37-
# echo "CURMOTOR=\"${CURMOTOR}\" SEENPORT=\"${SEENPORT}\""
38-
# if listcontains "outA" "${CURMOTOR}" ; then
3938
if listcontains "${SEENPORT}" "outA" ; then
4039
echo "Motor present on ${port}: no action"
4140
exit
4241
else
4342
if [ "${CURMOTOR}" == "???????" ]; then
4443
echo "OK, no motor on ${port}: is outA already \"led\"?"
4544
if [ ! -e /sys/class/leds/ev3\:\:outA/trigger ]; then
46-
echo "No outA trigger yet, Add PF led on port outA"
47-
tryPF outA led
48-
fi
49-
## currently /sys/devices/platform/legoev3-ports/lego-port/port4
50-
## /sys/class/lego-port/port4/outA:rcx-led/leds/ev3::outA
51-
# cd /sys/devices/platform/legoev3-ports/${port}
52-
#
53-
# motormode="rcx-led"
54-
# motordir="leds"
55-
# echo ${motormode} > /sys/devices/platform/legoev3-ports/${port}/mode
56-
# sleep 0.3s
57-
# controldir=`find /sys/class/${motordir} -name "*${port}*"`
58-
# if [ -d ${controldir} ]; then
59-
# echo mmc0 > ${controldir}/trigger
60-
# else
61-
# echo -e "Cannot find \"${controldir}\""
62-
# find /sys/class/${motordir} -name "*${port}*"
63-
# fi
45+
echo "Field trigger on outA does not exist yet: Add PF led on port outA"
46+
/usr/local/bin/tryPF outA led
47+
fi
6448
fi
6549
fi
6650

6751
if [ -w /sys/class/leds/ev3\:\:outA/trigger ]; then
68-
echo "set \"mmc0\" to \"/sys/class/leds/ev3\:\:outA/trigger\""
52+
echo "set \"/sys/class/leds/ev3\:\:outA/trigger\" to \"mmc0\" "
6953
echo mmc0 > /sys/class/leds/ev3\:\:outA/trigger
7054
fi

tryPF

Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
1+
#!/bin/bash -ue
2+
# Script_name : tryPF
3+
# Author : Bert Lindeman
4+
# Description : Set an output port for Power-Functions led or motor
5+
# Version : v1.3
6+
# Date : 2015-01-16
7+
# Usage : tryPF <portletter> <led | motor>
8+
# default is "tryPF A led"
9+
#
10+
# Notes : This script is used by showactivity
11+
#
12+
# Copyright : 2015 Bert Lindeman
13+
# License : GPL-3.0+
14+
#
15+
#
16+
#
17+
# Changelog
18+
# Date By Description
19+
#
20+
#
21+
#
22+
. /usr/local/bin/bert_ev3dev_functions
23+
#
24+
showattr() {
25+
for f in ${1}
26+
do
27+
attr=`cat $f` # get the field and then do echo to get uevent on one line
28+
printf "%10s %-20s %s\n" " " "`basename $f`" "`echo ${attr}`"
29+
done
30+
}
31+
32+
showmotor_attr() {
33+
ctlpath=${1:-"??"}
34+
set +x
35+
36+
echo -en " Current directory: `pwd`; "
37+
echo -e " Potential mode: `cat modes`"
38+
39+
# printf format to ESCAPE a string:
40+
# %q quote the argument in a way that can be reused as shell input
41+
echo " Switch to ctlpath \"${ctlpath}\""
42+
cd `printf "%q" "${ctlpath}"`
43+
echo -e " Port:${port} ${motordir} controldir: ${controldir}"
44+
echo -e " attributes:"
45+
attr=`find ${controldir}/ -maxdepth 1 -type f`
46+
showattr "$attr"
47+
}
48+
49+
findPortnumber () {
50+
# find on which port* the port_name is controlled
51+
local port portctl
52+
local port_name
53+
local intl_port_dir intl_port_name
54+
local curmodes wantmode
55+
port="${1}"
56+
portctl=/sys/class/lego-port/port*/port_name
57+
CTL_PATH=""
58+
# set -x
59+
for IOPORT in ${portctl}
60+
do
61+
port_name="`cat \"${IOPORT}\"`"
62+
intl_port_dir="`dirname ${IOPORT}`"
63+
intl_port_name="`basename ${intl_port_dir}`"
64+
if [ "${port_name}" == "${port}" ]; then
65+
echo "port \"${port}\" found on \"${intl_port_name}\""
66+
# ls -l ${intl_port_dir}/
67+
curmodes=`cat ${intl_port_dir}/modes`
68+
wantmode="rcx-motor"
69+
if listcontains "$curmodes" "$wantmode" ; then
70+
CTL_PATH="${intl_port_dir}"
71+
fi
72+
break
73+
fi
74+
done
75+
76+
}
77+
78+
################# mainline #################
79+
port="${1:-outA}"
80+
type="${2:-led}" # led or motor
81+
82+
# set -x
83+
if [ "$type" == "motor" ]; then
84+
echo "# PF-motor ###################################################################"
85+
86+
findPortnumber ${port}
87+
cd ${CTL_PATH}
88+
motorbase="`basename ${CTL_PATH}`"
89+
# echo -e "currentdir=`pwd`"
90+
91+
motormode="rcx-motor"
92+
motordir="dc-motor"
93+
94+
echo ${motormode} > mode
95+
# sleep 0.75s
96+
found=0
97+
98+
while : ; do
99+
[[ -e `find /sys/devices/platform/legoev3-ports/lego-port/${motorbase}/${port}*/${motordir} -name "motor*"` ]] && found=1 && break
100+
echo "Pausing until led / motor directory exists."
101+
sleep 1
102+
done
103+
104+
# realpath:
105+
# /sys/devices/platform/legoev3-ports/lego-port/port6/outC:rcx-motor/dc-motor/motor10
106+
controldir=`find /sys/devices/platform/legoev3-ports/lego-port/${motorbase}/${port}*/${motordir} -name "motor*"`
107+
108+
if [ ${found} == 1 ] && [ -d ${controldir} ]; then
109+
showmotor_attr ${controldir}
110+
else
111+
echo -e "Cannot find \"${controldir}\""
112+
find /sys/class/${motordir} -name "motor*"
113+
fi
114+
set _x
115+
elif [ "$type" == "led" ]; then
116+
echo "# PF-led ###################################################################"
117+
118+
findPortnumber ${port}
119+
cd ${CTL_PATH}
120+
121+
motormode="rcx-led"
122+
motordir="leds"
123+
124+
echo ${motormode} > mode
125+
#sleep 0.75s
126+
found=0
127+
128+
while : ; do
129+
[[ -e `find /sys/class/${motordir} -name "*${port}*"` ]] && found=1 && break
130+
echo "Pausing until led / motor directory exists."
131+
sleep 1
132+
done
133+
134+
controldir=`find /sys/class/${motordir} -name "*${port}*"`
135+
if [ ${found} == 1 ] && [ -d ${controldir} ]; then
136+
showmotor_attr ${controldir}
137+
else
138+
echo -e "Cannot find \"${controldir}\""
139+
find /sys/class/${motordir} -name "*${port}*"
140+
fi
141+
fi
142+
#
143+
exit

0 commit comments

Comments
 (0)