added fnweb: a webinterface to control your lights via browser/smartphone
This commit is contained in:
parent
93310dd1b9
commit
211e43950e
17 changed files with 1056 additions and 26 deletions
|
@ -152,6 +152,8 @@ FNPOM_DEPS_CFLAGS = @FNPOM_DEPS_CFLAGS@
|
|||
FNPOM_DEPS_LIBS = @FNPOM_DEPS_LIBS@
|
||||
FNVUM_DEPS_CFLAGS = @FNVUM_DEPS_CFLAGS@
|
||||
FNVUM_DEPS_LIBS = @FNVUM_DEPS_LIBS@
|
||||
FNWEB_DEPS_CFLAGS = @FNWEB_DEPS_CFLAGS@
|
||||
FNWEB_DEPS_LIBS = @FNWEB_DEPS_LIBS@
|
||||
GREP = @GREP@
|
||||
INSTALL = @INSTALL@
|
||||
INSTALL_DATA = @INSTALL_DATA@
|
||||
|
|
|
@ -1,5 +1,8 @@
|
|||
/* config.h.in. Generated from configure.ac by autoheader. */
|
||||
|
||||
/* Define to 1 if you have the `atoi' function. */
|
||||
#undef HAVE_ATOI
|
||||
|
||||
/* Define to 1 if you have the <dlfcn.h> header file. */
|
||||
#undef HAVE_DLFCN_H
|
||||
|
||||
|
|
129
configure
vendored
129
configure
vendored
|
@ -747,6 +747,8 @@ ac_subst_vars='am__EXEEXT_FALSE
|
|||
am__EXEEXT_TRUE
|
||||
LTLIBOBJS
|
||||
LIBOBJS
|
||||
FNWEB_DEPS_LIBS
|
||||
FNWEB_DEPS_CFLAGS
|
||||
FNPOM_DEPS_LIBS
|
||||
FNPOM_DEPS_CFLAGS
|
||||
FNVUM_DEPS_LIBS
|
||||
|
@ -885,7 +887,9 @@ PKG_CONFIG_LIBDIR
|
|||
FNVUM_DEPS_CFLAGS
|
||||
FNVUM_DEPS_LIBS
|
||||
FNPOM_DEPS_CFLAGS
|
||||
FNPOM_DEPS_LIBS'
|
||||
FNPOM_DEPS_LIBS
|
||||
FNWEB_DEPS_CFLAGS
|
||||
FNWEB_DEPS_LIBS'
|
||||
|
||||
|
||||
# Initialize some variables set by options.
|
||||
|
@ -1543,6 +1547,10 @@ Some influential environment variables:
|
|||
C compiler flags for FNPOM_DEPS, overriding pkg-config
|
||||
FNPOM_DEPS_LIBS
|
||||
linker flags for FNPOM_DEPS, overriding pkg-config
|
||||
FNWEB_DEPS_CFLAGS
|
||||
C compiler flags for FNWEB_DEPS, overriding pkg-config
|
||||
FNWEB_DEPS_LIBS
|
||||
linker flags for FNWEB_DEPS, overriding pkg-config
|
||||
|
||||
Use these variables to override the choices made by `configure' or to help
|
||||
it to find libraries and programs with nonstandard names/locations.
|
||||
|
@ -4674,13 +4682,13 @@ if test "${lt_cv_nm_interface+set}" = set; then :
|
|||
else
|
||||
lt_cv_nm_interface="BSD nm"
|
||||
echo "int some_variable = 0;" > conftest.$ac_ext
|
||||
(eval echo "\"\$as_me:4677: $ac_compile\"" >&5)
|
||||
(eval echo "\"\$as_me:4685: $ac_compile\"" >&5)
|
||||
(eval "$ac_compile" 2>conftest.err)
|
||||
cat conftest.err >&5
|
||||
(eval echo "\"\$as_me:4680: $NM \\\"conftest.$ac_objext\\\"\"" >&5)
|
||||
(eval echo "\"\$as_me:4688: $NM \\\"conftest.$ac_objext\\\"\"" >&5)
|
||||
(eval "$NM \"conftest.$ac_objext\"" 2>conftest.err > conftest.out)
|
||||
cat conftest.err >&5
|
||||
(eval echo "\"\$as_me:4683: output\"" >&5)
|
||||
(eval echo "\"\$as_me:4691: output\"" >&5)
|
||||
cat conftest.out >&5
|
||||
if $GREP 'External.*some_variable' conftest.out > /dev/null; then
|
||||
lt_cv_nm_interface="MS dumpbin"
|
||||
|
@ -5886,7 +5894,7 @@ ia64-*-hpux*)
|
|||
;;
|
||||
*-*-irix6*)
|
||||
# Find out which ABI we are using.
|
||||
echo '#line 5889 "configure"' > conftest.$ac_ext
|
||||
echo '#line 5897 "configure"' > conftest.$ac_ext
|
||||
if { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$ac_compile\""; } >&5
|
||||
(eval $ac_compile) 2>&5
|
||||
ac_status=$?
|
||||
|
@ -7411,11 +7419,11 @@ else
|
|||
-e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \
|
||||
-e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \
|
||||
-e 's:$: $lt_compiler_flag:'`
|
||||
(eval echo "\"\$as_me:7414: $lt_compile\"" >&5)
|
||||
(eval echo "\"\$as_me:7422: $lt_compile\"" >&5)
|
||||
(eval "$lt_compile" 2>conftest.err)
|
||||
ac_status=$?
|
||||
cat conftest.err >&5
|
||||
echo "$as_me:7418: \$? = $ac_status" >&5
|
||||
echo "$as_me:7426: \$? = $ac_status" >&5
|
||||
if (exit $ac_status) && test -s "$ac_outfile"; then
|
||||
# The compiler can only warn and ignore the option if not recognized
|
||||
# So say no if there are warnings other than the usual output.
|
||||
|
@ -7750,11 +7758,11 @@ else
|
|||
-e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \
|
||||
-e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \
|
||||
-e 's:$: $lt_compiler_flag:'`
|
||||
(eval echo "\"\$as_me:7753: $lt_compile\"" >&5)
|
||||
(eval echo "\"\$as_me:7761: $lt_compile\"" >&5)
|
||||
(eval "$lt_compile" 2>conftest.err)
|
||||
ac_status=$?
|
||||
cat conftest.err >&5
|
||||
echo "$as_me:7757: \$? = $ac_status" >&5
|
||||
echo "$as_me:7765: \$? = $ac_status" >&5
|
||||
if (exit $ac_status) && test -s "$ac_outfile"; then
|
||||
# The compiler can only warn and ignore the option if not recognized
|
||||
# So say no if there are warnings other than the usual output.
|
||||
|
@ -7855,11 +7863,11 @@ else
|
|||
-e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \
|
||||
-e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \
|
||||
-e 's:$: $lt_compiler_flag:'`
|
||||
(eval echo "\"\$as_me:7858: $lt_compile\"" >&5)
|
||||
(eval echo "\"\$as_me:7866: $lt_compile\"" >&5)
|
||||
(eval "$lt_compile" 2>out/conftest.err)
|
||||
ac_status=$?
|
||||
cat out/conftest.err >&5
|
||||
echo "$as_me:7862: \$? = $ac_status" >&5
|
||||
echo "$as_me:7870: \$? = $ac_status" >&5
|
||||
if (exit $ac_status) && test -s out/conftest2.$ac_objext
|
||||
then
|
||||
# The compiler can only warn and ignore the option if not recognized
|
||||
|
@ -7910,11 +7918,11 @@ else
|
|||
-e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \
|
||||
-e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \
|
||||
-e 's:$: $lt_compiler_flag:'`
|
||||
(eval echo "\"\$as_me:7913: $lt_compile\"" >&5)
|
||||
(eval echo "\"\$as_me:7921: $lt_compile\"" >&5)
|
||||
(eval "$lt_compile" 2>out/conftest.err)
|
||||
ac_status=$?
|
||||
cat out/conftest.err >&5
|
||||
echo "$as_me:7917: \$? = $ac_status" >&5
|
||||
echo "$as_me:7925: \$? = $ac_status" >&5
|
||||
if (exit $ac_status) && test -s out/conftest2.$ac_objext
|
||||
then
|
||||
# The compiler can only warn and ignore the option if not recognized
|
||||
|
@ -10294,7 +10302,7 @@ else
|
|||
lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
|
||||
lt_status=$lt_dlunknown
|
||||
cat > conftest.$ac_ext <<_LT_EOF
|
||||
#line 10297 "configure"
|
||||
#line 10305 "configure"
|
||||
#include "confdefs.h"
|
||||
|
||||
#if HAVE_DLFCN_H
|
||||
|
@ -10390,7 +10398,7 @@ else
|
|||
lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
|
||||
lt_status=$lt_dlunknown
|
||||
cat > conftest.$ac_ext <<_LT_EOF
|
||||
#line 10393 "configure"
|
||||
#line 10401 "configure"
|
||||
#include "confdefs.h"
|
||||
|
||||
#if HAVE_DLFCN_H
|
||||
|
@ -11634,6 +11642,95 @@ $as_echo "yes" >&6; }
|
|||
|
||||
fi
|
||||
|
||||
pkg_failed=no
|
||||
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for FNWEB_DEPS" >&5
|
||||
$as_echo_n "checking for FNWEB_DEPS... " >&6; }
|
||||
|
||||
if test -n "$FNWEB_DEPS_CFLAGS"; then
|
||||
pkg_cv_FNWEB_DEPS_CFLAGS="$FNWEB_DEPS_CFLAGS"
|
||||
elif test -n "$PKG_CONFIG"; then
|
||||
if test -n "$PKG_CONFIG" && \
|
||||
{ { $as_echo "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"json >= 0.9 libmicrohttpd >= 0.4.6\""; } >&5
|
||||
($PKG_CONFIG --exists --print-errors "json >= 0.9 libmicrohttpd >= 0.4.6") 2>&5
|
||||
ac_status=$?
|
||||
$as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
|
||||
test $ac_status = 0; }; then
|
||||
pkg_cv_FNWEB_DEPS_CFLAGS=`$PKG_CONFIG --cflags "json >= 0.9 libmicrohttpd >= 0.4.6" 2>/dev/null`
|
||||
else
|
||||
pkg_failed=yes
|
||||
fi
|
||||
else
|
||||
pkg_failed=untried
|
||||
fi
|
||||
if test -n "$FNWEB_DEPS_LIBS"; then
|
||||
pkg_cv_FNWEB_DEPS_LIBS="$FNWEB_DEPS_LIBS"
|
||||
elif test -n "$PKG_CONFIG"; then
|
||||
if test -n "$PKG_CONFIG" && \
|
||||
{ { $as_echo "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"json >= 0.9 libmicrohttpd >= 0.4.6\""; } >&5
|
||||
($PKG_CONFIG --exists --print-errors "json >= 0.9 libmicrohttpd >= 0.4.6") 2>&5
|
||||
ac_status=$?
|
||||
$as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
|
||||
test $ac_status = 0; }; then
|
||||
pkg_cv_FNWEB_DEPS_LIBS=`$PKG_CONFIG --libs "json >= 0.9 libmicrohttpd >= 0.4.6" 2>/dev/null`
|
||||
else
|
||||
pkg_failed=yes
|
||||
fi
|
||||
else
|
||||
pkg_failed=untried
|
||||
fi
|
||||
|
||||
|
||||
|
||||
if test $pkg_failed = yes; then
|
||||
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
|
||||
$as_echo "no" >&6; }
|
||||
|
||||
if $PKG_CONFIG --atleast-pkgconfig-version 0.20; then
|
||||
_pkg_short_errors_supported=yes
|
||||
else
|
||||
_pkg_short_errors_supported=no
|
||||
fi
|
||||
if test $_pkg_short_errors_supported = yes; then
|
||||
FNWEB_DEPS_PKG_ERRORS=`$PKG_CONFIG --short-errors --print-errors "json >= 0.9 libmicrohttpd >= 0.4.6" 2>&1`
|
||||
else
|
||||
FNWEB_DEPS_PKG_ERRORS=`$PKG_CONFIG --print-errors "json >= 0.9 libmicrohttpd >= 0.4.6" 2>&1`
|
||||
fi
|
||||
# Put the nasty error message in config.log where it belongs
|
||||
echo "$FNWEB_DEPS_PKG_ERRORS" >&5
|
||||
|
||||
as_fn_error $? "Package requirements (json >= 0.9 libmicrohttpd >= 0.4.6) were not met:
|
||||
|
||||
$FNWEB_DEPS_PKG_ERRORS
|
||||
|
||||
Consider adjusting the PKG_CONFIG_PATH environment variable if you
|
||||
installed software in a non-standard prefix.
|
||||
|
||||
Alternatively, you may set the environment variables FNWEB_DEPS_CFLAGS
|
||||
and FNWEB_DEPS_LIBS to avoid the need to call pkg-config.
|
||||
See the pkg-config man page for more details." "$LINENO" 5
|
||||
elif test $pkg_failed = untried; then
|
||||
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
|
||||
$as_echo "no" >&6; }
|
||||
{ { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5
|
||||
$as_echo "$as_me: error: in \`$ac_pwd':" >&2;}
|
||||
as_fn_error $? "The pkg-config script could not be found or is too old. Make sure it
|
||||
is in your PATH or set the PKG_CONFIG environment variable to the full
|
||||
path to pkg-config.
|
||||
|
||||
Alternatively, you may set the environment variables FNWEB_DEPS_CFLAGS
|
||||
and FNWEB_DEPS_LIBS to avoid the need to call pkg-config.
|
||||
See the pkg-config man page for more details.
|
||||
|
||||
To get pkg-config, see <http://pkg-config.freedesktop.org/>.
|
||||
See \`config.log' for more details" "$LINENO" 5 ; }
|
||||
else
|
||||
FNWEB_DEPS_CFLAGS=$pkg_cv_FNWEB_DEPS_CFLAGS
|
||||
FNWEB_DEPS_LIBS=$pkg_cv_FNWEB_DEPS_LIBS
|
||||
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
|
||||
$as_echo "yes" >&6; }
|
||||
|
||||
fi
|
||||
|
||||
# Checks for header files.
|
||||
for ac_header in fcntl.h netdb.h stdint.h stdlib.h string.h sys/ioctl.h sys/socket.h termios.h unistd.h
|
||||
do :
|
||||
|
@ -11792,7 +11889,7 @@ $as_echo "#define malloc rpl_malloc" >>confdefs.h
|
|||
fi
|
||||
|
||||
|
||||
for ac_func in memset pow socket sqrt strrchr
|
||||
for ac_func in memset pow socket sqrt strrchr atoi
|
||||
do :
|
||||
as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh`
|
||||
ac_fn_c_check_func "$LINENO" "$ac_func" "$as_ac_var"
|
||||
|
|
|
@ -15,6 +15,7 @@ AC_PROG_CC
|
|||
AC_CHECK_LIB([m], [abs])
|
||||
PKG_CHECK_MODULES([FNVUM_DEPS], [sdl >= 1.2.14 fftw3 >= 3.2.2 libpulse-simple >= 0.9.21])
|
||||
PKG_CHECK_MODULES([FNPOM_DEPS], [json >= 0.9])
|
||||
PKG_CHECK_MODULES([FNWEB_DEPS], [json >= 0.9 libmicrohttpd >= 0.4.6])
|
||||
|
||||
# Checks for header files.
|
||||
AC_CHECK_HEADERS([fcntl.h netdb.h stdint.h stdlib.h string.h sys/ioctl.h sys/socket.h termios.h unistd.h])
|
||||
|
@ -29,7 +30,7 @@ AC_TYPE_UINT8_T
|
|||
|
||||
# Checks for library functions.
|
||||
AC_FUNC_MALLOC
|
||||
AC_CHECK_FUNCS([memset pow socket sqrt strrchr])
|
||||
AC_CHECK_FUNCS([memset pow socket sqrt strrchr atoi])
|
||||
|
||||
AC_CONFIG_FILES([Makefile src/Makefile fn.pc])
|
||||
AC_OUTPUT
|
||||
|
|
11
debian/control
vendored
11
debian/control
vendored
|
@ -2,7 +2,7 @@ Source: libfn
|
|||
Priority: extra
|
||||
Maintainer: Steffen Vogel <info@steffenvogel.de>
|
||||
Build-Depends: debhelper (>= 7.0.50~), autotools-dev
|
||||
Standards-Version: 3.8.4
|
||||
Standards-Version: 3.9.1
|
||||
Section: libs
|
||||
Homepage: https://github.com/fd0/fnordlicht/
|
||||
Vcs-Git: git://github.com/stv0g/libfn.git
|
||||
|
@ -22,7 +22,8 @@ Architecture: any
|
|||
Depends: ${shlibs:Depends}, ${misc:Depends}
|
||||
Description: Library for interfacing fnordlichts
|
||||
This Package includes some quite helpful utilities:
|
||||
libfn is a simple c lib for controlling your fnordlichts
|
||||
fnctl is a sample programm which uses libfn
|
||||
fnvum is a vu meter to use your fnordlichts as a calvilux
|
||||
fnpom is a program to visualize measurements from a volkszaehler.org middleware
|
||||
libfn is a simple c lib for controlling your fnordlichts
|
||||
fnctl is a sample program which uses libfn
|
||||
fnvum is a vu meter to use your fnordlichts as a calvilux
|
||||
fnpom is a program to visualize measurements from volkszaehler.org
|
||||
fnweb is a web interface to control your fnordlichts
|
||||
|
|
51
share/web/css/farbtastic.css
Normal file
51
share/web/css/farbtastic.css
Normal file
|
@ -0,0 +1,51 @@
|
|||
/**
|
||||
* Farbtastic Color Picker 1.2
|
||||
* © 2008 Steven Wittens
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
.farbtastic {
|
||||
position: relative;
|
||||
}
|
||||
.farbtastic * {
|
||||
position: absolute;
|
||||
cursor: crosshair;
|
||||
}
|
||||
.farbtastic, .farbtastic .wheel {
|
||||
width: 195px;
|
||||
height: 195px;
|
||||
}
|
||||
.farbtastic .color, .farbtastic .overlay {
|
||||
top: 47px;
|
||||
left: 47px;
|
||||
width: 101px;
|
||||
height: 101px;
|
||||
}
|
||||
.farbtastic .wheel {
|
||||
background: url(../img/wheel.png) no-repeat;
|
||||
width: 195px;
|
||||
height: 195px;
|
||||
}
|
||||
.farbtastic .overlay {
|
||||
background: url(../img/mask.png) no-repeat;
|
||||
}
|
||||
.farbtastic .marker {
|
||||
width: 17px;
|
||||
height: 17px;
|
||||
margin: -8px 0 0 -8px;
|
||||
overflow: hidden;
|
||||
background: url(../img/marker.png) no-repeat;
|
||||
}
|
||||
|
34
share/web/css/style.css
Normal file
34
share/web/css/style.css
Normal file
|
@ -0,0 +1,34 @@
|
|||
body {
|
||||
font-family: sans-serif;
|
||||
}
|
||||
|
||||
#wrapper {
|
||||
width: 295px;
|
||||
text-align: center;
|
||||
margin: 40px auto;
|
||||
}
|
||||
|
||||
#picker {
|
||||
padding-left: 50px;
|
||||
}
|
||||
|
||||
#details {
|
||||
border: 1px solid grey;
|
||||
padding: 3px;
|
||||
font-size: 0.85em;
|
||||
}
|
||||
|
||||
#details input {
|
||||
border: 1px solid grey;
|
||||
margin: 1px;
|
||||
}
|
||||
|
||||
#mask input {
|
||||
margin: 2px;
|
||||
}
|
||||
|
||||
#show_details {
|
||||
font-weight: bold;
|
||||
margin: 30px 0 4px;
|
||||
cursor: pointer;
|
||||
}
|
29
share/web/fade.php
Normal file
29
share/web/fade.php
Normal file
|
@ -0,0 +1,29 @@
|
|||
<?php
|
||||
$count = 10;
|
||||
|
||||
$params = array(
|
||||
'color' => (isset($_REQUEST['color'])) ? substr($_REQUEST['color'], 1) : 'ffffff',
|
||||
'delay' => (isset($_REQUEST['delay'])) ? $_REQUEST['delay'] : 0,
|
||||
'step' => (isset($_REQUEST['step'])) ? $_REQUEST['step'] : 255,
|
||||
'mask' => (isset($_REQUEST['mask'])) ? $_REQUEST['mask'] : str_repeat('1', $count),
|
||||
'port' => '/dev/ttyUSB0'
|
||||
);
|
||||
|
||||
$cmd = '../../src/fnctl fade';
|
||||
foreach ($params as $param => $value) {
|
||||
$cmd .= ' --' . $param . '=' . $value;
|
||||
}
|
||||
|
||||
$return;
|
||||
$output = passthru($cmd, $return);
|
||||
|
||||
$json = array(
|
||||
'code' => $return,
|
||||
'output' => $output,
|
||||
'cmd' => $cmd,
|
||||
'params' => $params
|
||||
);
|
||||
|
||||
header('Content-type: application/json');
|
||||
echo json_encode($json);
|
||||
?>
|
BIN
share/web/img/marker.png
Executable file
BIN
share/web/img/marker.png
Executable file
Binary file not shown.
After Width: | Height: | Size: 652 B |
BIN
share/web/img/mask.png
Normal file
BIN
share/web/img/mask.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 2 KiB |
BIN
share/web/img/wheel.png
Normal file
BIN
share/web/img/wheel.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 12 KiB |
134
share/web/index.html
Normal file
134
share/web/index.html
Normal file
|
@ -0,0 +1,134 @@
|
|||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
|
||||
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
|
||||
<html>
|
||||
<head>
|
||||
<title>fnordlichts</title>
|
||||
<script type="text/javascript" src="js/jquery-1.7.1.min.js"></script>
|
||||
<script type="text/javascript" src="js/farbtastic.js"></script>
|
||||
<link rel="stylesheet" href="css/farbtastic.css" type="text/css" />
|
||||
<link rel="stylesheet" href="css/style.css" type="text/css" />
|
||||
<script type="text/javascript" charset="utf-8">
|
||||
var locked = false;
|
||||
var count; /* count of lamps */
|
||||
var color; /* last color */
|
||||
|
||||
function stop() {
|
||||
if (!locked) {
|
||||
locked = true;
|
||||
$.ajax({
|
||||
type: 'POST',
|
||||
url: 'stop',
|
||||
success: function(data) {
|
||||
locked = false;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
function start(script) {
|
||||
var mask = get_mask();
|
||||
var data = {
|
||||
script : script
|
||||
};
|
||||
|
||||
if (mask.indexOf('0') != -1) {
|
||||
data.mask = mask;
|
||||
}
|
||||
|
||||
if (!locked) {
|
||||
locked = true;
|
||||
$.ajax({
|
||||
type: 'POST',
|
||||
url: 'start?' + $.param(data),
|
||||
success: function(data) {
|
||||
locked = false;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
function get_mask() {
|
||||
var mask = new String;
|
||||
for (var i=0; i < count; i++) {
|
||||
mask += ($('#lamp_' + i).attr('checked')) ? '1' : '0';
|
||||
}
|
||||
return mask;
|
||||
}
|
||||
|
||||
function fade(hex) {
|
||||
color = (hex == undefined) ? $.farbtastic('#picker').color.substr(1) : hex.substr(1);
|
||||
|
||||
var mask = get_mask();
|
||||
var data = {
|
||||
color: color,
|
||||
step: $('#step').val(),
|
||||
delay: $('#delay').val(),
|
||||
}
|
||||
|
||||
if (mask.indexOf('0') != -1) {
|
||||
data.mask = mask;
|
||||
}
|
||||
|
||||
if (!locked) {
|
||||
locked = true;
|
||||
$.ajax({
|
||||
type: 'POST',
|
||||
url: 'fade?' + $.param(data),
|
||||
success: function(data) {
|
||||
locked = false;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
$(document).ready(function() {
|
||||
|
||||
/* draw mask boxes */
|
||||
$.get('count', function(data) {
|
||||
count = parseInt(data);
|
||||
|
||||
for (var i=0; i < count; i++) {
|
||||
$('#mask').append(
|
||||
$('<input>')
|
||||
.attr('type', 'checkbox')
|
||||
.attr('id', 'lamp_' + i)
|
||||
.attr('checked', true)
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
/* get current color */
|
||||
$.get('color', function(data) {
|
||||
color = data;
|
||||
$.farbtastic('#picker').setColor('#' + color);
|
||||
});
|
||||
|
||||
$('#picker').farbtastic(fade);
|
||||
//$('input').bind('click change keypress', fade);
|
||||
|
||||
$('#details').hide();
|
||||
$('#show_details').click(function() { $('#details').slideToggle(); });
|
||||
});
|
||||
</script>
|
||||
</head>
|
||||
<body>
|
||||
<div id="wrapper">
|
||||
<div id="picker"></div>
|
||||
<p id="show_details">more..</p>
|
||||
<div id="details">
|
||||
<table>
|
||||
<tr><td><label>Verzögerung</label></td><td><input type="text" id="delay" value="3"/></td></tr>
|
||||
<tr><td><label>Schrittweite</label></td><td><input type="text" id="step" value="20" /></td></tr>
|
||||
<tr><td><label>Lampen</label></td><td><div id="mask" /></td></tr>
|
||||
<tr><td></td><td>
|
||||
<input type="button" onclick="stop()" value="Stop" />
|
||||
<input type="button" onclick="start(1)" value="Party" />
|
||||
<input type="button" onclick="start(0)" value="Farbrad" />
|
||||
</td></tr>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
</body>
|
||||
</html>
|
345
share/web/js/farbtastic.js
Normal file
345
share/web/js/farbtastic.js
Normal file
|
@ -0,0 +1,345 @@
|
|||
/**
|
||||
* Farbtastic Color Picker 1.2
|
||||
* © 2008 Steven Wittens
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
jQuery.fn.farbtastic = function (callback) {
|
||||
$.farbtastic(this, callback);
|
||||
return this;
|
||||
};
|
||||
|
||||
jQuery.farbtastic = function (container, callback) {
|
||||
var container = $(container).get(0);
|
||||
return container.farbtastic || (container.farbtastic = new jQuery._farbtastic(container, callback));
|
||||
}
|
||||
|
||||
jQuery._farbtastic = function (container, callback) {
|
||||
// Store farbtastic object
|
||||
var fb = this;
|
||||
|
||||
// Insert markup
|
||||
$(container).html('<div class="farbtastic"><div class="color"></div><div class="wheel"></div><div class="overlay"></div><div class="h-marker marker"></div><div class="sl-marker marker"></div></div>');
|
||||
var e = $('.farbtastic', container);
|
||||
fb.wheel = $('.wheel', container).get(0);
|
||||
// Dimensions
|
||||
fb.radius = 84;
|
||||
fb.square = 100;
|
||||
fb.width = 194;
|
||||
|
||||
// Fix background PNGs in IE6
|
||||
if (navigator.appVersion.match(/MSIE [0-6]\./)) {
|
||||
$('*', e).each(function () {
|
||||
if (this.currentStyle.backgroundImage != 'none') {
|
||||
var image = this.currentStyle.backgroundImage;
|
||||
image = this.currentStyle.backgroundImage.substring(5, image.length - 2);
|
||||
$(this).css({
|
||||
'backgroundImage': 'none',
|
||||
'filter': "progid:DXImageTransform.Microsoft.AlphaImageLoader(enabled=true, sizingMethod=crop, src='" + image + "')"
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Link to the given element(s) or callback.
|
||||
*/
|
||||
fb.linkTo = function (callback) {
|
||||
// Unbind previous nodes
|
||||
if (typeof fb.callback == 'object') {
|
||||
$(fb.callback).unbind('keyup', fb.updateValue);
|
||||
}
|
||||
|
||||
// Reset color
|
||||
fb.color = null;
|
||||
|
||||
// Bind callback or elements
|
||||
if (typeof callback == 'function') {
|
||||
fb.callback = callback;
|
||||
}
|
||||
else if (typeof callback == 'object' || typeof callback == 'string') {
|
||||
fb.callback = $(callback);
|
||||
fb.callback.bind('keyup', fb.updateValue);
|
||||
if (fb.callback.get(0).value) {
|
||||
fb.setColor(fb.callback.get(0).value);
|
||||
}
|
||||
}
|
||||
return this;
|
||||
}
|
||||
fb.updateValue = function (event) {
|
||||
if (this.value && this.value != fb.color) {
|
||||
fb.setColor(this.value);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Change color with HTML syntax #123456
|
||||
*/
|
||||
fb.setColor = function (color) {
|
||||
var unpack = fb.unpack(color);
|
||||
if (fb.color != color && unpack) {
|
||||
fb.color = color;
|
||||
fb.rgb = unpack;
|
||||
fb.hsl = fb.RGBToHSL(fb.rgb);
|
||||
fb.updateDisplay();
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Change color with HSL triplet [0..1, 0..1, 0..1]
|
||||
*/
|
||||
fb.setHSL = function (hsl) {
|
||||
fb.hsl = hsl;
|
||||
fb.rgb = fb.HSLToRGB(hsl);
|
||||
fb.color = fb.pack(fb.rgb);
|
||||
fb.updateDisplay();
|
||||
return this;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////
|
||||
|
||||
/**
|
||||
* Retrieve the coordinates of the given event relative to the center
|
||||
* of the widget.
|
||||
*/
|
||||
fb.widgetCoords = function (event) {
|
||||
var x, y;
|
||||
var el = event.target || event.srcElement;
|
||||
var reference = fb.wheel;
|
||||
|
||||
if (typeof event.offsetX != 'undefined') {
|
||||
// Use offset coordinates and find common offsetParent
|
||||
var pos = { x: event.offsetX, y: event.offsetY };
|
||||
|
||||
// Send the coordinates upwards through the offsetParent chain.
|
||||
var e = el;
|
||||
while (e) {
|
||||
e.mouseX = pos.x;
|
||||
e.mouseY = pos.y;
|
||||
pos.x += e.offsetLeft;
|
||||
pos.y += e.offsetTop;
|
||||
e = e.offsetParent;
|
||||
}
|
||||
|
||||
// Look for the coordinates starting from the wheel widget.
|
||||
var e = reference;
|
||||
var offset = { x: 0, y: 0 }
|
||||
while (e) {
|
||||
if (typeof e.mouseX != 'undefined') {
|
||||
x = e.mouseX - offset.x;
|
||||
y = e.mouseY - offset.y;
|
||||
break;
|
||||
}
|
||||
offset.x += e.offsetLeft;
|
||||
offset.y += e.offsetTop;
|
||||
e = e.offsetParent;
|
||||
}
|
||||
|
||||
// Reset stored coordinates
|
||||
e = el;
|
||||
while (e) {
|
||||
e.mouseX = undefined;
|
||||
e.mouseY = undefined;
|
||||
e = e.offsetParent;
|
||||
}
|
||||
}
|
||||
else {
|
||||
// Use absolute coordinates
|
||||
var pos = fb.absolutePosition(reference);
|
||||
x = (event.pageX || 0*(event.clientX + $('html').get(0).scrollLeft)) - pos.x;
|
||||
y = (event.pageY || 0*(event.clientY + $('html').get(0).scrollTop)) - pos.y;
|
||||
}
|
||||
// Subtract distance to middle
|
||||
return { x: x - fb.width / 2, y: y - fb.width / 2 };
|
||||
}
|
||||
|
||||
/**
|
||||
* Mousedown handler
|
||||
*/
|
||||
fb.mousedown = function (event) {
|
||||
// Capture mouse
|
||||
if (!document.dragging) {
|
||||
$(document).bind('mousemove', fb.mousemove).bind('mouseup', fb.mouseup);
|
||||
document.dragging = true;
|
||||
}
|
||||
|
||||
// Check which area is being dragged
|
||||
var pos = fb.widgetCoords(event);
|
||||
fb.circleDrag = Math.max(Math.abs(pos.x), Math.abs(pos.y)) * 2 > fb.square;
|
||||
|
||||
// Process
|
||||
fb.mousemove(event);
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Mousemove handler
|
||||
*/
|
||||
fb.mousemove = function (event) {
|
||||
// Get coordinates relative to color picker center
|
||||
var pos = fb.widgetCoords(event);
|
||||
|
||||
// Set new HSL parameters
|
||||
if (fb.circleDrag) {
|
||||
var hue = Math.atan2(pos.x, -pos.y) / 6.28;
|
||||
if (hue < 0) hue += 1;
|
||||
fb.setHSL([hue, fb.hsl[1], fb.hsl[2]]);
|
||||
}
|
||||
else {
|
||||
var sat = Math.max(0, Math.min(1, -(pos.x / fb.square) + .5));
|
||||
var lum = Math.max(0, Math.min(1, -(pos.y / fb.square) + .5));
|
||||
fb.setHSL([fb.hsl[0], sat, lum]);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Mouseup handler
|
||||
*/
|
||||
fb.mouseup = function () {
|
||||
// Uncapture mouse
|
||||
$(document).unbind('mousemove', fb.mousemove);
|
||||
$(document).unbind('mouseup', fb.mouseup);
|
||||
document.dragging = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the markers and styles
|
||||
*/
|
||||
fb.updateDisplay = function () {
|
||||
// Markers
|
||||
var angle = fb.hsl[0] * 6.28;
|
||||
$('.h-marker', e).css({
|
||||
left: Math.round(Math.sin(angle) * fb.radius + fb.width / 2) + 'px',
|
||||
top: Math.round(-Math.cos(angle) * fb.radius + fb.width / 2) + 'px'
|
||||
});
|
||||
|
||||
$('.sl-marker', e).css({
|
||||
left: Math.round(fb.square * (.5 - fb.hsl[1]) + fb.width / 2) + 'px',
|
||||
top: Math.round(fb.square * (.5 - fb.hsl[2]) + fb.width / 2) + 'px'
|
||||
});
|
||||
|
||||
// Saturation/Luminance gradient
|
||||
$('.color', e).css('backgroundColor', fb.pack(fb.HSLToRGB([fb.hsl[0], 1, 0.5])));
|
||||
|
||||
// Linked elements or callback
|
||||
if (typeof fb.callback == 'object') {
|
||||
// Set background/foreground color
|
||||
$(fb.callback).css({
|
||||
backgroundColor: fb.color,
|
||||
color: fb.hsl[2] > 0.5 ? '#000' : '#fff'
|
||||
});
|
||||
|
||||
// Change linked value
|
||||
$(fb.callback).each(function() {
|
||||
if (this.value && this.value != fb.color) {
|
||||
this.value = fb.color;
|
||||
}
|
||||
});
|
||||
}
|
||||
else if (typeof fb.callback == 'function') {
|
||||
fb.callback.call(fb, fb.color);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get absolute position of element
|
||||
*/
|
||||
fb.absolutePosition = function (el) {
|
||||
var r = { x: el.offsetLeft, y: el.offsetTop };
|
||||
// Resolve relative to offsetParent
|
||||
if (el.offsetParent) {
|
||||
var tmp = fb.absolutePosition(el.offsetParent);
|
||||
r.x += tmp.x;
|
||||
r.y += tmp.y;
|
||||
}
|
||||
return r;
|
||||
};
|
||||
|
||||
/* Various color utility functions */
|
||||
fb.pack = function (rgb) {
|
||||
var r = Math.round(rgb[0] * 255);
|
||||
var g = Math.round(rgb[1] * 255);
|
||||
var b = Math.round(rgb[2] * 255);
|
||||
return '#' + (r < 16 ? '0' : '') + r.toString(16) +
|
||||
(g < 16 ? '0' : '') + g.toString(16) +
|
||||
(b < 16 ? '0' : '') + b.toString(16);
|
||||
}
|
||||
|
||||
fb.unpack = function (color) {
|
||||
if (color.length == 7) {
|
||||
return [parseInt('0x' + color.substring(1, 3)) / 255,
|
||||
parseInt('0x' + color.substring(3, 5)) / 255,
|
||||
parseInt('0x' + color.substring(5, 7)) / 255];
|
||||
}
|
||||
else if (color.length == 4) {
|
||||
return [parseInt('0x' + color.substring(1, 2)) / 15,
|
||||
parseInt('0x' + color.substring(2, 3)) / 15,
|
||||
parseInt('0x' + color.substring(3, 4)) / 15];
|
||||
}
|
||||
}
|
||||
|
||||
fb.HSLToRGB = function (hsl) {
|
||||
var m1, m2, r, g, b;
|
||||
var h = hsl[0], s = hsl[1], l = hsl[2];
|
||||
m2 = (l <= 0.5) ? l * (s + 1) : l + s - l*s;
|
||||
m1 = l * 2 - m2;
|
||||
return [this.hueToRGB(m1, m2, h+0.33333),
|
||||
this.hueToRGB(m1, m2, h),
|
||||
this.hueToRGB(m1, m2, h-0.33333)];
|
||||
}
|
||||
|
||||
fb.hueToRGB = function (m1, m2, h) {
|
||||
h = (h < 0) ? h + 1 : ((h > 1) ? h - 1 : h);
|
||||
if (h * 6 < 1) return m1 + (m2 - m1) * h * 6;
|
||||
if (h * 2 < 1) return m2;
|
||||
if (h * 3 < 2) return m1 + (m2 - m1) * (0.66666 - h) * 6;
|
||||
return m1;
|
||||
}
|
||||
|
||||
fb.RGBToHSL = function (rgb) {
|
||||
var min, max, delta, h, s, l;
|
||||
var r = rgb[0], g = rgb[1], b = rgb[2];
|
||||
min = Math.min(r, Math.min(g, b));
|
||||
max = Math.max(r, Math.max(g, b));
|
||||
delta = max - min;
|
||||
l = (min + max) / 2;
|
||||
s = 0;
|
||||
if (l > 0 && l < 1) {
|
||||
s = delta / (l < 0.5 ? (2 * l) : (2 - 2 * l));
|
||||
}
|
||||
h = 0;
|
||||
if (delta > 0) {
|
||||
if (max == r && max != g) h += (g - b) / delta;
|
||||
if (max == g && max != b) h += (2 + (b - r) / delta);
|
||||
if (max == b && max != r) h += (4 + (r - g) / delta);
|
||||
h /= 6;
|
||||
}
|
||||
return [h, s, l];
|
||||
}
|
||||
|
||||
// Install mousedown handler (the others are set on the document on-demand)
|
||||
$('*', e).mousedown(fb.mousedown);
|
||||
|
||||
// Init color
|
||||
fb.setColor('#000000');
|
||||
|
||||
// Set linked elements/callback
|
||||
if (callback) {
|
||||
fb.linkTo(callback);
|
||||
}
|
||||
}
|
4
share/web/js/jquery-1.7.1.min.js
vendored
Normal file
4
share/web/js/jquery-1.7.1.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
|
@ -1,7 +1,7 @@
|
|||
AM_CFLAGS= -Wall $(FNVUM_DEPS_CFLAGS) $(FNPOM_DEPS_CFLAGS)
|
||||
AM_LDFLAGS=
|
||||
|
||||
bin_PROGRAMS = fnctl fnvum fnpom
|
||||
bin_PROGRAMS = fnctl fnvum fnpom fnweb
|
||||
lib_LTLIBRARIES = libfn.la
|
||||
include_HEADERS = libfn.h
|
||||
|
||||
|
@ -15,3 +15,6 @@ fnpom_LDADD = -lfn $(FNPOM_DEPS_LIBS)
|
|||
|
||||
fnvum_SOURCES = fnvum.c
|
||||
fnvum_LDADD = -lfn $(FNVUM_DEPS_LIBS)
|
||||
|
||||
fnweb_SOURCES = fnweb.c
|
||||
fnweb_LDADD = -lfn $(FNWEB_DEPS_LIBS)
|
||||
|
|
|
@ -36,7 +36,8 @@ PRE_UNINSTALL = :
|
|||
POST_UNINSTALL = :
|
||||
build_triplet = @build@
|
||||
host_triplet = @host@
|
||||
bin_PROGRAMS = fnctl$(EXEEXT) fnvum$(EXEEXT) fnpom$(EXEEXT)
|
||||
bin_PROGRAMS = fnctl$(EXEEXT) fnvum$(EXEEXT) fnpom$(EXEEXT) \
|
||||
fnweb$(EXEEXT)
|
||||
subdir = src
|
||||
DIST_COMMON = $(include_HEADERS) $(srcdir)/Makefile.am \
|
||||
$(srcdir)/Makefile.in
|
||||
|
@ -86,6 +87,9 @@ fnpom_DEPENDENCIES = $(am__DEPENDENCIES_1)
|
|||
am_fnvum_OBJECTS = fnvum.$(OBJEXT)
|
||||
fnvum_OBJECTS = $(am_fnvum_OBJECTS)
|
||||
fnvum_DEPENDENCIES = $(am__DEPENDENCIES_1)
|
||||
am_fnweb_OBJECTS = fnweb.$(OBJEXT)
|
||||
fnweb_OBJECTS = $(am_fnweb_OBJECTS)
|
||||
fnweb_DEPENDENCIES = $(am__DEPENDENCIES_1)
|
||||
DEFAULT_INCLUDES = -I.@am__isrc@ -I$(top_builddir)
|
||||
depcomp = $(SHELL) $(top_srcdir)/depcomp
|
||||
am__depfiles_maybe = depfiles
|
||||
|
@ -100,9 +104,9 @@ LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \
|
|||
--mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) $(AM_LDFLAGS) \
|
||||
$(LDFLAGS) -o $@
|
||||
SOURCES = $(libfn_la_SOURCES) $(fnctl_SOURCES) $(fnpom_SOURCES) \
|
||||
$(fnvum_SOURCES)
|
||||
$(fnvum_SOURCES) $(fnweb_SOURCES)
|
||||
DIST_SOURCES = $(libfn_la_SOURCES) $(fnctl_SOURCES) $(fnpom_SOURCES) \
|
||||
$(fnvum_SOURCES)
|
||||
$(fnvum_SOURCES) $(fnweb_SOURCES)
|
||||
HEADERS = $(include_HEADERS)
|
||||
ETAGS = etags
|
||||
CTAGS = ctags
|
||||
|
@ -134,6 +138,8 @@ FNPOM_DEPS_CFLAGS = @FNPOM_DEPS_CFLAGS@
|
|||
FNPOM_DEPS_LIBS = @FNPOM_DEPS_LIBS@
|
||||
FNVUM_DEPS_CFLAGS = @FNVUM_DEPS_CFLAGS@
|
||||
FNVUM_DEPS_LIBS = @FNVUM_DEPS_LIBS@
|
||||
FNWEB_DEPS_CFLAGS = @FNWEB_DEPS_CFLAGS@
|
||||
FNWEB_DEPS_LIBS = @FNWEB_DEPS_LIBS@
|
||||
GREP = @GREP@
|
||||
INSTALL = @INSTALL@
|
||||
INSTALL_DATA = @INSTALL_DATA@
|
||||
|
@ -236,6 +242,8 @@ fnpom_SOURCES = fnpom.c
|
|||
fnpom_LDADD = -lfn $(FNPOM_DEPS_LIBS)
|
||||
fnvum_SOURCES = fnvum.c
|
||||
fnvum_LDADD = -lfn $(FNVUM_DEPS_LIBS)
|
||||
fnweb_SOURCES = fnweb.c
|
||||
fnweb_LDADD = -lfn $(FNWEB_DEPS_LIBS)
|
||||
all: all-am
|
||||
|
||||
.SUFFIXES:
|
||||
|
@ -355,6 +363,9 @@ fnpom$(EXEEXT): $(fnpom_OBJECTS) $(fnpom_DEPENDENCIES)
|
|||
fnvum$(EXEEXT): $(fnvum_OBJECTS) $(fnvum_DEPENDENCIES)
|
||||
@rm -f fnvum$(EXEEXT)
|
||||
$(LINK) $(fnvum_OBJECTS) $(fnvum_LDADD) $(LIBS)
|
||||
fnweb$(EXEEXT): $(fnweb_OBJECTS) $(fnweb_DEPENDENCIES)
|
||||
@rm -f fnweb$(EXEEXT)
|
||||
$(LINK) $(fnweb_OBJECTS) $(fnweb_LDADD) $(LIBS)
|
||||
|
||||
mostlyclean-compile:
|
||||
-rm -f *.$(OBJEXT)
|
||||
|
@ -365,6 +376,7 @@ distclean-compile:
|
|||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/fnctl.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/fnpom.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/fnvum.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/fnweb.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libfn.Plo@am__quote@
|
||||
|
||||
.c.o:
|
||||
|
|
314
src/fnweb.c
Normal file
314
src/fnweb.c
Normal file
|
@ -0,0 +1,314 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include <errno.h>
|
||||
#include <signal.h>
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
#include <microhttpd.h>
|
||||
#include <time.h>
|
||||
|
||||
#include "libfn.h"
|
||||
|
||||
volatile bool shutdown = false; /* will be set to TRUE in our signal handler */
|
||||
char *httpd_root; /* where static HTML content is located */
|
||||
int httpd_port; /* TCP port the webserver should listen to */
|
||||
int fnordlicht_fd; /* file descriptor for serial port */
|
||||
|
||||
struct rgb_color_t parse_color(const char *identifier) {
|
||||
struct rgb_color_t color;
|
||||
if (strlen(identifier) != 6) {
|
||||
fprintf(stderr, "Invalid color definition: %s", identifier);
|
||||
}
|
||||
|
||||
unsigned short int red, green, blue;
|
||||
|
||||
sscanf(identifier, "%2hX%2hX%2hX", &red, &green, &blue);
|
||||
|
||||
color.red = red;
|
||||
color.green = green;
|
||||
color.blue = blue;
|
||||
|
||||
return color;
|
||||
}
|
||||
|
||||
void quit(int sig) {
|
||||
shutdown = true;
|
||||
}
|
||||
|
||||
const char * get_filename_ext(char *filename) {
|
||||
const char *dot = strrchr(filename, '.');
|
||||
|
||||
if (!dot || dot == filename) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return dot + 1;
|
||||
}
|
||||
|
||||
const char * get_content_type(char *filename) {
|
||||
const char *ext = get_filename_ext(filename);
|
||||
|
||||
if (strcmp(ext, "html") == 0) return "text/html";
|
||||
else if (strcmp(ext, "js") == 0) return "text/javascript";
|
||||
else if (strcmp(ext, "css") == 0) return "text/css";
|
||||
else if (strcmp(ext, "png") == 0) return "image/png";
|
||||
else return "text/plain";
|
||||
}
|
||||
|
||||
void print_cmd(void *data, size_t n) {
|
||||
printf("Command sent: ");
|
||||
int i;
|
||||
for (i = 0; i < n; i++) {
|
||||
printf("%02X", *((uint8_t *) data+i));
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
int load_file(const char *filename, char **result) {
|
||||
int size = 0;
|
||||
FILE *f = fopen(filename, "rb");
|
||||
if (f == NULL) {
|
||||
*result = NULL;
|
||||
return -1; /* failed to open file */
|
||||
}
|
||||
|
||||
fseek(f, 0, SEEK_END);
|
||||
size = ftell(f);
|
||||
fseek(f, 0, SEEK_SET);
|
||||
|
||||
*result = (char *) malloc(size+1);
|
||||
if (*result == NULL) {
|
||||
return -3; /* failed to allocate memory */
|
||||
}
|
||||
|
||||
if (size != fread(*result, sizeof(char), size, f)) {
|
||||
free(*result);
|
||||
return -2; /* failed to read file */
|
||||
}
|
||||
|
||||
fclose(f);
|
||||
|
||||
(*result)[size] = '\0'; /* zero terminated */
|
||||
|
||||
return size;
|
||||
}
|
||||
|
||||
int handle_request(void *cls, struct MHD_Connection *connection, const char *url, const char *method,
|
||||
const char *version, const char *upload_data, size_t *upload_data_size, void **con_cls) {
|
||||
|
||||
static struct rgb_color_t current = {{{0, 0, 0}}}; /* start with black */
|
||||
|
||||
if (strcasecmp(method, "get") == 0) {
|
||||
struct MHD_Response *response;
|
||||
char *filename = malloc(1024); /* max path length */
|
||||
|
||||
if (strcmp(url+1, "color") == 0) {
|
||||
char *color_str = malloc(8);
|
||||
snprintf(color_str, 7, "%02x%02x%02x\n", current.red, current.green, current.blue);
|
||||
response = MHD_create_response_from_data(strlen(color_str), (void *) color_str, 1, 0);
|
||||
MHD_add_response_header(response, "Content-type", "text/plain");
|
||||
}
|
||||
else if (strcmp(url+1, "count") == 0) {
|
||||
char *count_str = malloc(5);
|
||||
snprintf(count_str, 4, "%i\n", fn_count_devices(fnordlicht_fd));
|
||||
response = MHD_create_response_from_data(strlen(count_str), (void *) count_str, 1, 0);
|
||||
MHD_add_response_header(response, "Content-type", "text/plain");
|
||||
}
|
||||
else { /* get file from disk */
|
||||
/* construct filename */
|
||||
filename = getcwd(filename, 1024);
|
||||
filename = strncat(filename, httpd_root, 1024);
|
||||
filename = strncat(filename, (strlen(url) > 1) ? url : "/index.html", 1024);
|
||||
|
||||
/* try to open file */
|
||||
char *response_str;
|
||||
int resonse_size = load_file(filename, &response_str);
|
||||
if (resonse_size > 0) {
|
||||
response = MHD_create_response_from_data(resonse_size, (void *) response_str, 1, 0);
|
||||
MHD_add_response_header(response, "Content-type", get_content_type(filename));
|
||||
}
|
||||
else {
|
||||
const char *error_str = "<html><body><h2>File not found!</h2></body></html>";
|
||||
fprintf(stderr, "Failed to open file: %s\n", filename);
|
||||
response = MHD_create_response_from_data(strlen (error_str), (void *) error_str, 0, 0);
|
||||
}
|
||||
}
|
||||
|
||||
if (response) {
|
||||
int ret = MHD_queue_response(connection, MHD_HTTP_OK, response);
|
||||
MHD_destroy_response(response);
|
||||
return ret;
|
||||
}
|
||||
else {
|
||||
return MHD_NO;
|
||||
}
|
||||
}
|
||||
else if (strcasecmp(method, "post") == 0) {
|
||||
struct remote_msg_t msg;
|
||||
|
||||
struct MHD_Response *response;
|
||||
const char *response_str;
|
||||
|
||||
memset(&msg, 0, sizeof(struct remote_msg_t));
|
||||
|
||||
const char *address = MHD_lookup_connection_value(connection, MHD_GET_ARGUMENT_KIND, "address");
|
||||
const char *mask = MHD_lookup_connection_value(connection, MHD_GET_ARGUMENT_KIND, "mask");
|
||||
|
||||
msg.address = (address) ? atoi(address) : REMOTE_ADDR_BROADCAST;
|
||||
|
||||
if (strcmp(url+1, "fade") == 0) {
|
||||
const char *color = MHD_lookup_connection_value(connection, MHD_GET_ARGUMENT_KIND, "color");
|
||||
const char *step = MHD_lookup_connection_value(connection, MHD_GET_ARGUMENT_KIND, "step");
|
||||
const char *delay = MHD_lookup_connection_value(connection, MHD_GET_ARGUMENT_KIND, "delay");
|
||||
|
||||
if (color == NULL) {
|
||||
return MHD_NO;
|
||||
}
|
||||
|
||||
current = parse_color(color); /* parse and updating current color */
|
||||
printf("Fading to color: #%02x%02x%02x\n", current.red, current.green, current.blue);
|
||||
|
||||
msg.cmd = REMOTE_CMD_FADE_RGB;
|
||||
msg.fade_rgb.step = (step) ? atoi(step) : 255;
|
||||
msg.fade_rgb.delay = (delay) ? atoi(delay) : 0;
|
||||
msg.fade_rgb.color = current;
|
||||
}
|
||||
else if (strcmp(url+1, "start") == 0) { // TODO not working: padding bytes in program_params_t?
|
||||
const char *script = MHD_lookup_connection_value(connection, MHD_GET_ARGUMENT_KIND, "script");
|
||||
union program_params_t params;
|
||||
|
||||
switch (atoi(script)) {
|
||||
case 0:
|
||||
printf("Start program: colorwheel\n");
|
||||
params.colorwheel.hue_start = 0;
|
||||
params.colorwheel.hue_step = 60;
|
||||
params.colorwheel.add_addr = 0;
|
||||
params.colorwheel.saturation = 255;
|
||||
params.colorwheel.value = 255;
|
||||
|
||||
params.colorwheel.fade_step = 1;
|
||||
params.colorwheel.fade_delay = 2;
|
||||
params.colorwheel.fade_sleep = 0;
|
||||
break;
|
||||
|
||||
case 1:
|
||||
printf("Start program: random\n");
|
||||
params.random.seed = (uint16_t) (rand() % 0xffff);
|
||||
params.random.use_address = 0;
|
||||
params.random.wait_for_fade = 1;
|
||||
params.random.min_distance = 60;
|
||||
|
||||
params.random.saturation = 255;
|
||||
params.random.value = 255;
|
||||
|
||||
params.random.fade_step = 1;
|
||||
params.random.fade_delay = 3;
|
||||
params.random.fade_sleep = 100;
|
||||
break;
|
||||
|
||||
default:
|
||||
return MHD_NO;
|
||||
}
|
||||
|
||||
msg.cmd = REMOTE_CMD_START_PROGRAM;
|
||||
msg.start_program.script = atoi(script);
|
||||
msg.start_program.params = params;
|
||||
|
||||
memset(&msg.start_program.params, 0xff, 3);
|
||||
}
|
||||
else if (strcmp(url+1, "stop") == 0) {
|
||||
msg.cmd = REMOTE_CMD_STOP;
|
||||
printf("Stop fading\n");
|
||||
}
|
||||
else if (strcmp(url+1, "shutdown") == 0) {
|
||||
msg.cmd = REMOTE_CMD_POWERDOWN;
|
||||
printf("Shutdown fnordlichts\n");
|
||||
}
|
||||
else {
|
||||
return MHD_NO;
|
||||
}
|
||||
|
||||
/* send command */
|
||||
int p = (mask) ? fn_send_mask(fnordlicht_fd, mask, &msg) : fn_send(fnordlicht_fd, &msg);
|
||||
|
||||
print_cmd(&msg, sizeof(msg));
|
||||
printf("Sent %i bytes to fnordlichts\n", p);
|
||||
|
||||
response_str = (p > 0) ? "success" : "failed";
|
||||
response = MHD_create_response_from_data(strlen(response_str), (void *) response_str, 1, 1);
|
||||
|
||||
int ret = MHD_queue_response(connection, (p > 0) ? MHD_HTTP_OK : MHD_HTTP_INTERNAL_SERVER_ERROR, response);
|
||||
MHD_destroy_response(response);
|
||||
return ret;
|
||||
}
|
||||
else {
|
||||
return MHD_NO;
|
||||
}
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
/* bind signals */
|
||||
struct sigaction action;
|
||||
sigemptyset(&action.sa_mask);
|
||||
action.sa_flags = 0;
|
||||
action.sa_handler = quit;
|
||||
|
||||
sigaction(SIGINT, &action, NULL); /* catch ctrl-c from terminal */
|
||||
sigaction(SIGHUP, &action, NULL); /* catch hangup signal */
|
||||
sigaction(SIGTERM, &action, NULL); /* catch kill signal */
|
||||
|
||||
if (argc < 3 || argc > 4) {
|
||||
fprintf(stderr, "usage: fnweb SERIAL-PORT WEB-DIRECTORY [HTTPD-PORT]\n");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
/* connect to fnordlichts */
|
||||
fnordlicht_fd = open(argv[1], O_RDWR | O_NOCTTY);
|
||||
if (fnordlicht_fd < 0) {
|
||||
fprintf(stderr, "Failed to open fnordlichts: %s\n", strerror(errno));
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
struct termios oldtio = fn_init(fnordlicht_fd);
|
||||
int p = fn_sync(fnordlicht_fd);
|
||||
if (p <= 0) {
|
||||
fprintf(stderr, "Failed to initialize fnordlichts!\n");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
/* seed PNRG for random program */
|
||||
srand(time(0));
|
||||
|
||||
/* start embedded HTTPd */
|
||||
httpd_port = (argc == 4) ? atoi(argv[3]) : 80; /* default port */
|
||||
httpd_root = argv[2];
|
||||
printf("Starting HTTPd on port: %i with root dir: %s\n", httpd_port, httpd_root);
|
||||
|
||||
struct MHD_Daemon *httpd = MHD_start_daemon(
|
||||
MHD_USE_THREAD_PER_CONNECTION | MHD_USE_DEBUG,
|
||||
httpd_port,
|
||||
NULL, NULL,
|
||||
&handle_request, NULL,
|
||||
//MHD_OPTION_CONNECTION_LIMIT, 1,
|
||||
MHD_OPTION_END
|
||||
);
|
||||
|
||||
if (httpd == NULL) {
|
||||
fprintf(stderr, "Failed to start HTTPd\n");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
/* busy loop */
|
||||
while (!shutdown) { }
|
||||
|
||||
/* stop embedded HTTPd */
|
||||
MHD_stop_daemon(httpd);
|
||||
|
||||
/* reset and close connection */
|
||||
tcsetattr(fnordlicht_fd, TCSANOW, &oldtio);
|
||||
close(fnordlicht_fd);
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
Loading…
Add table
Reference in a new issue