From 2630563d5a886a22c24e39d355a0f60558c996ee Mon Sep 17 00:00:00 2001 From: Bernhard Tittelbach Date: Mon, 2 Dec 2013 23:30:21 +0000 Subject: [PATCH] raspberrypi_licht --- .../r3cam-steppermotor/r3cam-steppermotor.c | 36 +-- raspberrypi_gpio_relay_licht/index.html | 5 + raspberrypi_gpio_relay_licht/mswitch.cgi | 62 +++++ raspberrypi_gpio_relay_licht/rc.local | 39 +++ raspberrypi_gpio_relay_licht/switch.cgi | 250 ++++++++++++++++++++ 5 files changed, 374 insertions(+), 18 deletions(-) create mode 100644 raspberrypi_gpio_relay_licht/index.html create mode 100755 raspberrypi_gpio_relay_licht/mswitch.cgi create mode 100644 raspberrypi_gpio_relay_licht/rc.local create mode 100755 raspberrypi_gpio_relay_licht/switch.cgi diff --git a/avr-projects/r3cam-steppermotor/r3cam-steppermotor.c b/avr-projects/r3cam-steppermotor/r3cam-steppermotor.c index c0ce5f9..f9ab209 100644 --- a/avr-projects/r3cam-steppermotor/r3cam-steppermotor.c +++ b/avr-projects/r3cam-steppermotor/r3cam-steppermotor.c @@ -109,16 +109,16 @@ void motor_stop(void) ISR(TIMER0_OVF_vect) { - if (m_steps_to_go_ == 0) - { - if(m_steps_to_go_back_) - { - M_PORT ^= (1 << M_DIRECTION); - m_steps_to_go_=m_steps_to_go_back_; - m_steps_to_go_back_=0; - } else - motor_stop(); - } + //if (m_steps_to_go_ == 0) + //{ + //if(m_steps_to_go_back_) + //{ + // M_PORT ^= (1 << M_DIRECTION); + // m_steps_to_go_=m_steps_to_go_back_; + //m_steps_to_go_back_=0; + //} else + // motor_stop(); + //} if (m_clk_divisor_counter_ == 0) { m_clk_divisor_counter_ = m_clk_divisor_; @@ -184,14 +184,14 @@ void handle_cmd(uint8_t cmd) case 'r': reset2bootloader(); break; case 's': motor_stop(); break; case 'y': motor_run(30,0,20); break; - case 'x': motor_run(140,0,40); break; - case 'c': motor_run(60,0,20); break; - case 'v': motor_run(40,0,20); break; - case 'q': motor_run(140,1,40); break; - case 'w': motor_run(60,1,20); break; - case 'e': motor_run(40,1,20); break; - case 'C': motor_run(330,0,40); break; - case 'W': motor_run(330,1,40); break; + //case 'x': motor_run(140,0,40); break; + //case 'c': motor_run(60,0,20); break; + //case 'v': motor_run(40,0,20); break; + //case 'q': motor_run(140,1,40); break; + //case 'w': motor_run(60,1,20); break; + //case 'e': motor_run(40,1,20); break; + //case 'C': motor_run(330,0,40); break; + //case 'W': motor_run(330,1,40); break; case '+': motor_set_speed(++cur_speed); break; case '-': motor_set_speed(--cur_speed); break; default: CDC_Device_SendString(&VirtualSerial_CDC_Interface, "error\n\r"); return; diff --git a/raspberrypi_gpio_relay_licht/index.html b/raspberrypi_gpio_relay_licht/index.html new file mode 100644 index 0000000..634133b --- /dev/null +++ b/raspberrypi_gpio_relay_licht/index.html @@ -0,0 +1,5 @@ + + + + + diff --git a/raspberrypi_gpio_relay_licht/mswitch.cgi b/raspberrypi_gpio_relay_licht/mswitch.cgi new file mode 100755 index 0000000..dbfc79a --- /dev/null +++ b/raspberrypi_gpio_relay_licht/mswitch.cgi @@ -0,0 +1,62 @@ +#!/bin/sh + +VALID_ONOFF_IDS="4 17 18 21 22 23" +GPIOPATH=/sys/class/gpio/gpio + +for QUERY in `echo $QUERY_STRING | tr '&' ' '`; do + for VALIDID in $VALID_ONOFF_IDS; do + if [ "$QUERY" = "$VALIDID=1" ]; then + eval "GPIO_$VALIDID"=1 + elif [ "$QUERY" = "$VALIDID=0" ]; then + eval "GPIO_$VALIDID=0" + elif [ "$QUERY" = "$VALIDID=q" ]; then + eval "GPIO_$VALIDID=q" + fi + done + if [ "$QUERY" = "mobile=1" ]; then + MOBILE='1' + NOFLOAT='1' + elif [ "$QUERY" = "nofloat=1" ]; then + NOFLOAT='1' + fi +done + + +print_gpio_state() { + GPIOVALUE=$(cat "${GPIOPATH}${1}/value") + if [ "$GPIOVALUE" = "0" ]; then + echo -n "true" + else + echo -n "false" + fi +} + +gpio_is_on() { + GPIOVALUE=$(cat "${GPIOPATH}${1}/value") + [ "$GPIOVALUE" = "0" ] +} + +echo "Content-type: text/html" +echo "" + +echo "{" +for CHECKID in $VALID_ONOFF_IDS; do + VAL="" + VAL="$(eval echo \$GPIO_$CHECKID)" + [ -z $VAL ] && continue + if [ $VAL = 1 -o $VAL = 0 ]; then + [ $VAL = 1 ] && VAL=0 || VAL=1 + echo "$VAL" > "${GPIOPATH}${CHECKID}/value" + fi + echo -n "\"$CHECKID\":" + print_gpio_state $CHECKID + echo "," +done +echo "\"-1\":false}" +# echo "" +# echo "" +# echo "Realraum Relay Switch" +# echo '' +# echo "" +# exit 0 + diff --git a/raspberrypi_gpio_relay_licht/rc.local b/raspberrypi_gpio_relay_licht/rc.local new file mode 100644 index 0000000..918e217 --- /dev/null +++ b/raspberrypi_gpio_relay_licht/rc.local @@ -0,0 +1,39 @@ +#!/bin/sh -e +# +# rc.local +# +# This script is executed at the end of each multiuser runlevel. +# Make sure that the script will "exit 0" on success or any other +# value on error. +# +# In order to enable or disable this script just change the execution +# bits. +# +# By default this script does nothing. + +for gpio in 4 17 18 21 22 23; do + echo $gpio > /sys/class/gpio/export + echo out > /sys/class/gpio/gpio$gpio/direction + chown www-data /sys/class/gpio/gpio$gpio/value +done + + +# Print the IP address +_IP=$(hostname -I) || true +if [ "$_IP" ]; then + printf "My IP address is %s\n" "$_IP" +fi + +MAX_TRIES=20 +if ! ifconfig eth0 && ifconfig wlan0 ; then + sleep 6 + while ((MAX_TRIES-- > 0)) && ! /sbin/wpa_cli status | grep -q wpa_state=COMPLETED; do + /sbin/wpa_cli status + ifdown wlan0 + ifup wlan0 + done +fi + +su realraum -s /bin/sh -c "sleep 10 && /home/realraum/play-sound-status.py /home/realraum/play-sound-status.cfg &>/dev/null &" & + +exit 0 diff --git a/raspberrypi_gpio_relay_licht/switch.cgi b/raspberrypi_gpio_relay_licht/switch.cgi new file mode 100755 index 0000000..d6f152e --- /dev/null +++ b/raspberrypi_gpio_relay_licht/switch.cgi @@ -0,0 +1,250 @@ +#!/bin/sh + +for QUERY in `echo $QUERY_STRING | tr '&' ' '`; do + for VALUE in `echo $QUERY | tr '=' ' '`; do + if [ "$VALUE" = "id" ]; then + ID='?' + elif [ "$ID" = "?" ]; then + ID=$VALUE + elif [ "$VALUE" = "power" ]; then + POWER='?' + elif [ "$POWER" = "?" ]; then + POWER=$VALUE + elif [ "$VALUE" = "mobile" ]; then + MOBILE='1' + NOFLOAT='1' + elif [ "$VALUE" = "nofloat" ]; then + NOFLOAT='1' + fi + i=$i+1 + done +done + + +GPIOPATH=/sys/class/gpio/gpio +VALID_ONOFF_IDS="4 17 18 21 22 23" +VALID_SEND_IDS="" + +print_gpio_state() { + GPIOVALUE=$(cat "${GPIOPATH}${1}/value") + if [ "$GPIOVALUE" = "0" ]; then + echo "ON" + else + echo "Off" + fi +} + +gpio_is_on() { + GPIOVALUE=$(cat "${GPIOPATH}${1}/value") + [ "$GPIOVALUE" = "0" ] +} + +if [ "$POWER" = "1" -o "$POWER" = "0" ]; then + for CHECKID in $VALID_ONOFF_IDS ; do + if [ "$CHECKID" = "$ID" ]; then + [ $POWER = 1 ] && POWER=0 || POWER=1 + echo "$POWER" > "${GPIOPATH}${ID}/value" + echo "Content-type: text/html" + echo "" + echo "" + echo "" + echo "Realraum Relay Switch" + echo '' + echo "" + exit 0 + fi + done +fi + +DESC_23="Decke Links Leinwand" +DESC_4="Decke Rechts Leinwand" +DESC_18="Decke Eingang Mitte" +DESC_17="Decke Durchgang Mitte" +DESC_22="Decke Links Couch" +DESC_21="Decke Rechts Couch" + +echo "Content-type: text/html" +echo "" +echo "" +echo "" +echo "Realraum Relay Power" +echo '' +echo '' +echo "" +echo "" +#echo "

Realraum rf433ctl

" +#echo "
" +echo "
" +echo "
" +for DISPID in $VALID_ONOFF_IDS; do + NAME="$(eval echo -n \$DESC_$DISPID)" + [ -z "$NAME" ] && NAME=$DISPID + + echo "
" + echo "" + if gpio_is_on $DISPID; then + echo " " + echo " " + else + echo " " + echo " " + fi + echo "" + echo -n "
$NAME
" +# echo -n "
$NAME (" +# print_gpio_state $DISPID +# echo ")
" + echo "
" + + if [ "$NOFLOAT" = "1" ]; then + echo "
" + fi +done + +echo "
" +echo "" +echo -n " " +echo -n " " +echo "" +echo -n "
Alle
" +echo "
" +if [ "$NOFLOAT" = "1" ]; then + echo "
" +fi +echo "
" + +if [ "$MOBILE" != "1" -a -n "$VALID_SEND_IDS" ]; then + +echo "
" + +ITEMCOUNT=0 + +for DISPID in $VALID_SEND_IDS; do + ITEMCOUNT=$((ITEMCOUNT+1)) + NAME="$(eval echo \$DESC_$DISPID)" + [ -z "$NAME" ] && NAME=$DISPID + + echo "
" + echo "" + echo " " + echo "" + echo "
$NAME
" + echo "
" + if [ "$NOFLOAT" = "1" -a $((ITEMCOUNT % 2 )) -ne 1 ]; then + echo "
" + fi + +done +echo "
" +fi +echo "
" +echo "" +echo "" -- 1.7.10.4