I forgot to update the description of the TS-41x config file, so the
following change is needed:

--- p.old       2009-11-14 10:45:26.000000000 +0000
+++ p   2009-11-14 10:41:31.000000000 +0000
@@ -4,7 +4,7 @@
 @@ -0,0 +1,39 @@
 +--[[
 +      Debian configuration file for qcontrol (LUA syntax)
-+      Supports QNAP TS-409.
++      Supports QNAP TS-410, TS-410U, TS-419P and TS-419U.
 +--]]
 +
 +register("ts41x")

Here's an new patch:

diff -urN 1/debian/configs/ts41x.lua qcontrol-0.4.2/debian/configs/ts41x.lua
--- 1/debian/configs/ts41x.lua  1970-01-01 01:00:00.000000000 +0100
+++ qcontrol-0.4.2/debian/configs/ts41x.lua     2009-11-14 10:29:55.000000000 
+0000
@@ -0,0 +1,39 @@
+--[[
+       Debian configuration file for qcontrol (LUA syntax)
+       Supports QNAP TS-410, TS-410U, TS-419P and TS-419U.
+--]]
+
+register("ts41x")
+
+-- Requires CONFIG_KEYBOARD_GPIO enabled in the kernel and
+-- the kernel module gpio_keys to be loaded.
+register("evdev", "/dev/input/by-path/platform-gpio-keys-event",
+       408, "restart_button",
+       133, "media_button")
+
+function power_button( time )
+       os.execute("poweroff")
+end
+
+function restart_button( time )
+       os.execute("reboot")
+end
+
+function media_button( time )
+       piccmd("usbled", "8hz")
+end
+
+--[[
+       Fan and temperature control are left disabled until qcontrol
+       gets a proper daemon mode.
+       Empty functions are needed to avoid errors.
+--]]
+function fan_error(  )
+end
+
+function fan_normal(  )
+end
+
+function temp( temp )
+       print("ts41x temperature:", temp)
+end
diff -urN 1/debian/control qcontrol-0.4.2/debian/control
--- 1/debian/control    2009-11-14 10:18:59.000000000 +0000
+++ qcontrol-0.4.2/debian/control       2009-11-14 10:28:06.000000000 +0000
@@ -20,7 +20,7 @@
  configuration file.
  .
  Supported devices at this time are the QNAP TS-109, TS-119, TS-209
- TS-219, TS-409 and TS-409U.
+ TS-219, TS-409, TS-409U, TS-410, TS-410U, TS-419P and TS-419U
  but the code is extensible so more devices may be added in future
  releases.
  .
diff -urN 1/debian/init.d qcontrol-0.4.2/debian/init.d
--- 1/debian/init.d     2009-11-14 10:18:59.000000000 +0000
+++ qcontrol-0.4.2/debian/init.d        2009-11-14 10:29:15.000000000 +0000
@@ -8,7 +8,7 @@
 # Should-Stop:       
 # Default-Start:     2 3 4 5
 # Default-Stop:      0 6
-# Short-Description: Change status leds for QNAP 
TS-109/TS-119/TS-209/TS-219/TS-409
+# Short-Description: Change status leds for QNAP Turbo Station devices
 ### END INIT INFO
 
 PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
@@ -86,7 +86,7 @@
                        rm -f $SOCKET
                fi
                ;;
-           "QNAP TS-409")
+           "QNAP TS-409" | "QNAP TS-41x")
                test_event_dev || exit 0
                if pid=$(qcontrol_start); then
                        log_action_msg "System boot completed"
@@ -127,7 +127,7 @@
                        rm -f $SOCKET
                fi
                ;;
-           "QNAP TS-409")
+           "QNAP TS-409" | "QNAP TS-41x")
                test_event_dev || exit 0
                if pid=$(qcontrol_start); then
                        log_action_msg "Preparing for shutdown"
diff -urN 1/debian/patches/005_Add_support_for_ts-41x.patch 
qcontrol-0.4.2/debian/patches/005_Add_support_for_ts-41x.patch
--- 1/debian/patches/005_Add_support_for_ts-41x.patch   1970-01-01 
01:00:00.000000000 +0100
+++ qcontrol-0.4.2/debian/patches/005_Add_support_for_ts-41x.patch      
2009-11-14 10:24:46.000000000 +0000
@@ -0,0 +1,398 @@
+diff -urN 1/Makefile qcontrol-0.4.2/Makefile
+--- a/Makefile 2009-11-14 10:18:59.000000000 +0000
++++ b/Makefile 2009-11-14 10:19:39.000000000 +0000
+@@ -1,7 +1,7 @@
+ CFLAGS=-Os -Wall -I /usr/include/lua5.1
+ LDFLAGS=-llua5.1 -lpthread
+ LDFLAGS_UDEB=-lpthread -lm -ldl
+-SOURCES=qcontrol.c ts209.c ts219.c ts409.c evdev.c
++SOURCES=qcontrol.c ts209.c ts219.c ts409.c ts41x.c evdev.c
+ OBJECTS=$(SOURCES:.c=.o)
+ EXECUTABLE=qcontrol
+ 
+diff -urN 1/qcontrol.c qcontrol-0.4.2/qcontrol.c
+--- a/qcontrol.c       2009-11-14 10:18:59.000000000 +0000
++++ b/qcontrol.c       2009-11-14 10:19:58.000000000 +0000
+@@ -56,12 +56,14 @@
+ extern struct picmodule ts209_module;
+ extern struct picmodule ts219_module;
+ extern struct picmodule ts409_module;
++extern struct picmodule ts41x_module;
+ extern struct picmodule evdev_module;
+ 
+ struct picmodule *modules[] = {
+       &ts209_module,
+       &ts219_module,
+       &ts409_module,
++      &ts41x_module,
+       &evdev_module,
+       NULL
+ };
+diff -urN 1/ts41x.c qcontrol-0.4.2/ts41x.c
+--- a/ts41x.c  1970-01-01 01:00:00.000000000 +0100
++++ b/ts41x.c  2009-11-14 10:20:22.000000000 +0000
+@@ -0,0 +1,364 @@
++/*
++ * Copyright (C) 2007-2008  Byron Bradley ([email protected])
++ * Copyright (C) 2008, 2009  Martin Michlmayr ([email protected])
++ *
++ * 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, see <http://www.gnu.org/licenses/>.
++ */
++
++#include <fcntl.h>
++#include <lua.h>
++#include <lualib.h>
++#include <lauxlib.h>
++#include <pthread.h>
++#include <stdio.h>
++#include <stdlib.h>
++#include <string.h>
++#include <termios.h>
++#include <unistd.h>
++#include <linux/input.h>
++
++#include "picmodule.h"
++
++static int serial;
++static struct termios oldtio, newtio;
++static pthread_t ts41x_thread;
++
++static int serial_read(char *buf, int len)
++{
++      int err;
++
++      err = read(serial, buf, len);
++      buf[err] = 0;
++
++      return err;
++}
++
++static int serial_write(char *buf, int len)
++{
++      int err;
++
++      err = write(serial, buf, len);
++
++      return err;
++}
++
++int ts41x_read_serial_events()
++{
++      char buf[100];
++      int err = serial_read(buf, 100);
++      if (err < 0)
++              return err;
++      switch (buf[0]) {
++      case 0x40:
++              call_function("power_button", "%d", 3);
++              break;
++      case 0x73:
++      case 0x75:
++      case 0x77:
++      case 0x79:
++              call_function("fan_error", "");
++              break;
++      case 0x74:
++      case 0x76:
++      case 0x78:
++      case 0x7a:
++              call_function("fan_normal", "");
++              break;
++      case 0x80 ... 0x8f: /*  0 - 15 */
++      case 0x90 ... 0x9f: /* 16 - 31 */
++      case 0xa0 ... 0xaf: /* 32 - 47 */
++      case 0xb0 ... 0xbf: /* 48 - 63 */
++      case 0xc0 ... 0xc6: /* 64 - 70 */
++              call_function("temp", "%d", buf[0] - 128);
++              break;
++      case 0x38: /* 71 - 79 */
++              call_function("temp", "%d", 75);
++              break;
++      case 0x39: /* 80 or higher */
++              call_function("temp", "%d", 80);
++              break;
++      default:
++              fprintf(stderr, "(PIC 0x%x) unknown command from PIC\n", 
buf[0]);
++      }
++
++      return -1;
++}
++
++static void *serial_poll(void *tmp)
++{
++      int err;
++      fd_set rset;
++
++      FD_ZERO(&rset);
++      FD_SET(serial, &rset);
++
++      for (;;) {
++              err = select(serial + 1, &rset, NULL, NULL, NULL);
++              if (err <= 0) {
++                      FD_SET(serial, &rset);
++                      continue;
++              }
++              ts41x_read_serial_events();
++              FD_SET(serial, &rset);
++      }
++
++      return NULL;
++}
++
++static int set_nonblock(int fd)
++{
++      int flags = fcntl(fd, F_GETFL, 0);
++      if (flags < 0)
++              flags = 0;
++      return fcntl(fd, F_SETFL, flags | O_NONBLOCK);
++}
++
++static int serial_open(char *device)
++{
++      char buf[100];
++      int err;
++
++      if ((serial = open(device , O_RDWR)) < 0) {
++              sprintf(buf, "Failed to open %s", device);
++              perror(buf);
++              return -1;
++      }
++      err = set_nonblock(serial);
++      if (err < 0) {
++              perror("Error setting nonblock");
++              return -1;
++      }
++
++      tcgetattr(serial, &oldtio);
++      memset(&newtio, 0, sizeof(newtio));
++
++      newtio.c_iflag |= IGNBRK;
++      newtio.c_lflag &= ~(ISIG | ICANON | ECHO);
++      newtio.c_cflag = B19200 | CS8 | CLOCAL | CREAD;
++      newtio.c_cc[VMIN] = 1;
++      newtio.c_cc[VTIME] = 0;
++      cfsetospeed(&newtio, B19200);
++      cfsetispeed(&newtio, B19200);
++
++      err = tcsetattr(serial, TCSANOW, &newtio);
++      if (err < 0) {
++              sprintf(buf, "Failed to set attributes for %s", device);
++              perror(buf);
++              return -1;
++      }
++
++      return 0;
++}
++
++static void serial_close()
++{
++      tcsetattr(serial, TCSANOW, &oldtio);
++      close(serial);
++}
++
++static int ts41x_powerled(int argc, const char **argv)
++{
++      char code = 0;
++
++      if (argc != 1)
++              return -1;
++
++      if (strcmp(argv[0], "on") == 0)
++              code = 0x4d;
++      else if (strcmp(argv[0], "1hz") == 0)
++              code = 0x4e;
++      else if (strcmp(argv[0], "2hz") == 0)
++              code = 0x4c;
++      else if (strcmp(argv[0], "off") == 0)
++              code = 0x4b;
++      else
++              return -1;
++
++      return serial_write(&code, 1);
++      return 0;
++}
++
++static int ts41x_statusled(int argc, const char **argv)
++{
++      char code = 0;
++
++      if (argc != 1)
++              return -1;
++
++      if (strcmp(argv[0], "red2hz") == 0)
++              code = 0x54;
++      else if (strcmp(argv[0], "green2hz") == 0)
++              code = 0x55;
++      else if (strcmp(argv[0], "greenon") == 0)
++              code = 0x56;
++      else if (strcmp(argv[0], "redon") == 0)
++              code = 0x57;
++      else if (strcmp(argv[0], "greenred2hz") == 0)
++              code = 0x58;
++      else if (strcmp(argv[0], "off") == 0)
++              code = 0x59;
++      else if (strcmp(argv[0], "green1hz") == 0)
++              code = 0x5a;
++      else if (strcmp(argv[0], "red1hz") == 0)
++              code = 0x5b;
++      else if (strcmp(argv[0], "greenred1hz") == 0)
++              code = 0x5c;
++      else
++              return -1;
++
++      return serial_write(&code, 1);
++      return 0;
++}
++
++static int ts41x_buzz(int argc, const char **argv)
++{
++      char code = 0;
++
++      if (argc != 1)
++              return -1;
++
++      if (strcmp(argv[0], "short") == 0)
++              code = 0x50;
++      else if (strcmp(argv[0], "long") == 0)
++              code = 0x51;
++      else
++              return -1;
++
++      return serial_write(&code, 1);
++      return 0;
++}
++
++static int ts41x_fanspeed(int argc, const char **argv)
++{
++      char code = 0;
++
++      if (argc != 1)
++              return -1;
++
++      if (strcmp(argv[0], "stop") == 0)
++              code = 0x30;
++      else if (strcmp(argv[0], "silence") == 0)
++              code = 0x31;
++      else if (strcmp(argv[0], "low") == 0)
++              code = 0x32;
++      else if (strcmp(argv[0], "medium") == 0)
++              code = 0x33;
++      else if (strcmp(argv[0], "high") == 0)
++              code = 0x34;
++      else if (strcmp(argv[0], "full") == 0)
++              code = 0x35;
++      else
++              return -1;
++
++      return serial_write(&code, 1);
++      return 0;
++}
++
++static int ts41x_usbled(int argc, const char **argv)
++{
++      char code = 0;
++
++      if (argc != 1)
++              return -1;
++
++      if (strcmp(argv[0], "on") == 0)
++              code = 0x60;
++      else if (strcmp(argv[0], "8hz") == 0)
++              code = 0x61;
++      else if (strcmp(argv[0], "off") == 0)
++              code = 0x62;
++      else
++              return -1;
++
++      return serial_write(&code, 1);
++      return 0;
++}
++
++static int ts41x_autopower(int argc, const char **argv)
++{
++      char code = 0;
++
++      if (argc != 1)
++              return -1;
++
++      if (strcmp(argv[0], "on") == 0)
++              code = 0x48;
++      else if (strcmp(argv[0], "off") == 0)
++              code = 0x49;
++      else
++              return -1;
++
++      return serial_write(&code, 1);
++      return 0;
++}
++
++int ts41x_init(int argc, const char **argv)
++{
++      int err;
++
++      if (argc > 0) {
++              printf("%s: module does not take any arguments\n", __func__);
++              return -1;
++      }
++
++      err = serial_open("/dev/ttyS1");
++      if (err < 0)
++              return err;
++
++      err = register_command("statusled",
++                             "Change the status LED",
++                             "Change the status LED, options are:\n"
++                             "\tred2hz\n\tgreen2hz\n\tgreenon\n\tredon\n"
++                             "\tgreenred2hz\n\toff\n\tgreen1hz\n\tred1hz\n",
++                             ts41x_statusled);
++      err = register_command("powerled",
++                             "Change the power LED",
++                             "Change the power LED, options are:\n"
++                             "\ton\n\toff\n\t1hz\n\t2hz\n",
++                             ts41x_powerled);
++      err = register_command("buzzer",
++                             "Buzz",
++                             "Buzz, options are:\n"
++                             "\tshort\n\tlong\n",
++                             ts41x_buzz);
++      err = register_command("fanspeed",
++                             "Set the fanspeed",
++                             "Set the fanspeed, options are:\n"
++                             "\tstop\n\tsilence\n\tlow\n\tmedium\n"
++                             "\thigh\n\tfull\n",
++                             ts41x_fanspeed);
++      err = register_command("usbled",
++                             "Set the usbled",
++                             "Set the usbled, options are:\n"
++                             "\ton\n\t8hz\n\toff\n",
++                             ts41x_usbled);
++      err = register_command("autopower",
++                             "Control the automatic power mechanism",
++                             "Control the automatic power mechanism, options 
are:\n"
++                             "\ton\n\toff\n",
++                             ts41x_autopower);
++
++      return pthread_create(&ts41x_thread, NULL, serial_poll, NULL);
++}
++
++void ts41x_exit(void)
++{
++      serial_close();
++}
++
++struct picmodule ts41x_module = {
++      .name           = "ts41x",
++      .init           = ts41x_init,
++      .exit           = ts41x_exit,
++};
diff -urN 1/debian/patches/series qcontrol-0.4.2/debian/patches/series
--- 1/debian/patches/series     2009-11-14 10:18:59.000000000 +0000
+++ qcontrol-0.4.2/debian/patches/series        2009-11-14 10:25:23.000000000 
+0000
@@ -2,3 +2,4 @@
 002_Update_config_values_for_restart_and_media_buttons.patch
 003_Add_support_for_ts-119.patch
 004_Support_autopower_feature.patch
+005_Add_support_for_ts-41x.patch
diff -urN 1/debian/qcontrol.1 qcontrol-0.4.2/debian/qcontrol.1
--- 1/debian/qcontrol.1 2009-11-14 10:18:59.000000000 +0000
+++ qcontrol-0.4.2/debian/qcontrol.1    2009-11-14 10:28:46.000000000 +0000
@@ -19,8 +19,9 @@
 control a device.
 .PP
 Currently supported devices are the QNAP TS-109, QNAP TS-119, QNAP TS-209,
-QNAP TS-219, QNAP TS-409 and QNAP TS-409U, but support for additional
-devices may be added in future releases.
+QNAP TS-219, QNAP TS-409, QNAP TS-409U, QNAP TS-410, QNAP TS-410U, QNAP
+TS-419P and QNAP TS-419U but support for additional devices may be added
+in future releases.
 
 .SH BASIC USAGE
 First a control process needs to be started that opens a socket through
diff -urN 1/debian/qcontrol.postinst qcontrol-0.4.2/debian/qcontrol.postinst
--- 1/debian/qcontrol.postinst  2009-11-14 10:18:59.000000000 +0000
+++ qcontrol-0.4.2/debian/qcontrol.postinst     2009-11-14 10:26:57.000000000 
+0000
@@ -11,6 +11,8 @@
                ln -s qcontrol/ts219.lua /etc/qcontrol.conf ;;
            "QNAP TS-409")
                ln -s qcontrol/ts409.lua /etc/qcontrol.conf ;;
+           "QNAP TS-41x")
+               ln -s qcontrol/ts41x.lua /etc/qcontrol.conf ;;
        esac
 fi
 

-- 
Martin Michlmayr
http://www.cyrius.com/



-- 
To UNSUBSCRIBE, email to [email protected]
with a subject of "unsubscribe". Trouble? Contact [email protected]

Reply via email to