1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105
|
/*
* Copyright (C) 2007-2008 Byron Bradley (byron.bbradley@gmail.com)
* Copyright (C) 2008 Martin Michlmayr (tbm@cyrius.com)
* Copyright (C) 2013 Ian Campbell (ijc@hellion.org.uk)
*
* 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 <lua.h>
#include <lualib.h>
#include <lauxlib.h>
#include <string.h>
#include <syslog.h>
#include <linux/input.h>
#include "picmodule.h"
#include "qnap-pic.h"
static int ts409_read_serial_events(void)
{
unsigned char buf[100];
int err = qnap_serial_read(buf, 100);
if (err < 0)
return err;
switch (buf[0]) {
case QNAP_PICSTS_POWER_BUTTON:
call_function("power_button", "%d", 3);
break;
case QNAP_PICSTS_POWER_LOSS_POWER_OFF:
/* RTC Wake-Up (ignored) */
break;
case QNAP_PICSTS_FAN1_ERROR:
case QNAP_PICSTS_FAN2_ERROR:
case QNAP_PICSTS_FAN3_ERROR:
case QNAP_PICSTS_FAN4_ERROR:
call_function("fan_error", "");
break;
case QNAP_PICSTS_FAN1_NORMAL:
case QNAP_PICSTS_FAN2_NORMAL:
case QNAP_PICSTS_FAN3_NORMAL:
case QNAP_PICSTS_FAN4_NORMAL:
call_function("fan_normal", "");
break;
case QNAP_PICSTS_SYS_TEMP_0 ... QNAP_PICSTS_SYS_TEMP_70:
call_function("temp", "%d", buf[0] - QNAP_PICSTS_SYS_TEMP_0);
break;
case QNAP_PICSTS_SYS_TEMP_71_79:
call_function("temp", "%d", 75);
break;
case QNAP_PICSTS_SYS_TEMP_80:
call_function("temp", "%d", 80);
break;
default:
print_log(LOG_WARNING, "(PIC 0x%x) unknown command from PIC",
buf[0]);
}
return -1;
}
static int ts409_init(int argc, const char **argv UNUSED)
{
int err;
if (argc > 0) {
print_log(LOG_ERR, "ts409: module takes no arguments");
return -1;
}
err = qnap_serial_open("/dev/ttyS1");
if (err < 0)
return err;
err = qnap_register_commands(QNAP_PIC_FEATURE_STATUSLED|
QNAP_PIC_FEATURE_USBLED|
QNAP_PIC_FEATURE_AUTOPOWER|
QNAP_PIC_FEATURE_BUZZER|
QNAP_PIC_FEATURE_FANSPEED);
if (err < 0)
return err;
return qnap_serial_poll(&ts409_read_serial_events);
}
static void ts409_exit(void)
{
qnap_serial_close();
}
struct picmodule ts409_module = {
.name = "ts409",
.init = ts409_init,
.exit = ts409_exit,
};
|