[tuxdroid-svn] r823 - in daemon/trunk: . libs
Status: Beta
Brought to you by:
ks156
From: jaguarondi <c2m...@c2...> - 2008-01-04 11:39:35
|
Author: jaguarondi Date: 2008-01-04 12:39:33 +0100 (Fri, 04 Jan 2008) New Revision: 823 Added: daemon/trunk/led.c daemon/trunk/led.h daemon/trunk/log.c daemon/trunk/log.h daemon/trunk/status.c daemon/trunk/status.h Removed: daemon/trunk/libs/USBDaemon_log.c daemon/trunk/libs/USBDaemon_log.h Modified: daemon/trunk/Makefile daemon/trunk/libs/USBDaemon_command_tux.c daemon/trunk/libs/USBDaemon_command_tux.h daemon/trunk/libs/USBDaemon_pidfile.c daemon/trunk/libs/USBDaemon_status_table.c daemon/trunk/libs/USBDaemon_status_table.h daemon/trunk/libs/USBDaemon_tcp_server.c daemon/trunk/libs/USBDaemon_usb.c daemon/trunk/main.c daemon/trunk/versioning.c Log: Didn't commit for a while, there's too much for a single commit but I can't split it anymore. Here are the changes: * Added led.[ch] to control the new LED firmware functions with fading effects. All effects should work with led_set(). The pulsing functions are not added yet. * Continued to refactor the status, new files status.[ch] have been added, work in progress. * Moved libs/USBDaemon_log.[ch] to log.[ch]. * Corrected some messages in libs/USBDaemon_usb.c. Modified: daemon/trunk/Makefile =================================================================== --- daemon/trunk/Makefile 2008-01-04 11:39:24 UTC (rev 822) +++ daemon/trunk/Makefile 2008-01-04 11:39:33 UTC (rev 823) @@ -18,9 +18,9 @@ TARGET = tuxd C_INCLUDE_DIRS = -I"/usr/local/include" C_PREPROC = - CFLAGS = -pipe -Wall -Werror -g2 -O0 -DUSB_DEBUG + CFLAGS = -pipe -Wall -Werror -g2 -std=gnu99 -O0 -DUSB_DEBUG LIB_DIRS = -L"/usr/local/lib" - LIBS = -lusb + LIBS = -lusb -lm LDFLAGS = -pipe endif @@ -30,22 +30,24 @@ TARGET = USBDaemon C_INCLUDE_DIRS = C_PREPROC = - CFLAGS = -pipe -Wall -g0 -O2 - LIB_DIRS = - LIBS = -lusb + CFLAGS = -pipe -Wall -g0 -O2 -std=c99 + LIB_DIRS = -L"/usr/local/lib" + LIBS = -lusb -lm LDFLAGS = -pipe -s endif SRC_OBJS = \ $(OBJ_DIR)/main.o \ $(OBJ_DIR)/USBDaemon_usb.o \ + $(OBJ_DIR)/status.o \ $(OBJ_DIR)/USBDaemon_status_table.o \ $(OBJ_DIR)/USBDaemon_pidfile.o \ $(OBJ_DIR)/USBDaemon_command_tux.o \ $(OBJ_DIR)/USBDaemon_tcp_server.o \ $(OBJ_DIR)/supervise.o \ $(OBJ_DIR)/versioning.o \ - $(OBJ_DIR)/USBDaemon_log.o + $(OBJ_DIR)/led.o \ + $(OBJ_DIR)/log.o define build_target @echo Linking... @@ -102,9 +104,15 @@ $(OBJ_DIR)/versioning.o: versioning.c versioning.h $(compile_source) -$(OBJ_DIR)/USBDaemon_log.o: libs/USBDaemon_log.c libs/USBDaemon_log.h +$(OBJ_DIR)/led.o: led.c led.h $(compile_source) +$(OBJ_DIR)/status.o: status.c status.h + $(compile_source) + +$(OBJ_DIR)/log.o: log.c log.h + $(compile_source) + $(OBJ_DIR)/USBDaemon_usb.o: libs/USBDaemon_usb.c \ libs/USBDaemon_usb.h \ libs/USBDaemon_globals.h \ Added: daemon/trunk/led.c =================================================================== --- daemon/trunk/led.c (rev 0) +++ daemon/trunk/led.c 2008-01-04 11:39:33 UTC (rev 823) @@ -0,0 +1,335 @@ +/* + * Tux Droid - USB Daemon + * Copyright (C) 2007 KYSOH S.A. <in...@ky...> + * + * 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, 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., 59 Temple Place - Suite 330, Boston, MA + * 02111-1307, USA. + */ + +/* $Id$ */ + +#include <assert.h> +#include <math.h> + +#include "led.h" +#include "status.h" +#include "libs/USBDaemon_command_tux.h" +#include "libs/USBDaemon_status_table.h" +#include "tuxdefs/api.h" + +/** Default settings for the fading effect. */ +#define DEFAULT_STEP 1 +/** Default settings for the fading effect. */ +#define DEFAULT_DELAY 1 + +/** Values corresponding to the firmware implementation of the fading effect. + * 'delay' is the delay (4ms time base) before which 'step' is applied. */ +static int delay = DEFAULT_DELAY, step = DEFAULT_STEP; + +/** + * \brief Configure the led effect parameters for a fading effect. + * \param leds Which LEDs should be configured. + * \param fading_delay Delay (in seconds) between 2 increments of intensity + * when fading. + * \return ack of tux command. + * + * One problem is that around 1sec (delay = 1, step = 1, 255 steps to fade from + * off to on), the resolution is quite coarse if we increment step or delay but + * not both simultaneously. We have approximately 0.25s, 0.5s, 1s, 2s, 3s, etc. + * when delay or step is increased. XXX If necessary we can add intermediate + * values by using 3/4 or 2,3,4/5 or even 2,3,7,9/10 and get a 100ms + * resolution, but the gradient (steps) effect starts to be noticeable. + */ +int config_fading(leds_t leds, float fading_delay) +{ + int ack; + float loops = fading_delay / FW_MAIN_LOOP_DELAY; + + /* Can't go infinitely fast. */ + if (loops == 0) + { + step = 0xFF; + delay = 1; + } + /* XXX We only handle the firmware function for now, + * when the delay will be over 255, we should split in 2 + * commands while tracking the time. */ + else if (loops > 255) + { + step = 1; + delay = 255; + } + /* Faster speed, the delay is set to minimum and we need to + * increase the step. */ + else if (loops < 1) + { + delay = 1; + step = roundf(1/loops); + } + else if (loops >= 1) + { + step = 1; + delay = roundf(loops); + } + ack = send_usb_tux_cmd(LED_FADE_SPEED_CMD, leds, delay, step); + return ack; +} + +/** + * \brief Configure the led effect parameters for a gradient effect. + * \param leds Which LEDs should be configured. + * \param delta Intensity increment to apply at each step. + * \param gradient_delay Delay (in seconds) between 2 increments of intensity. + * \return ack of tux command. + */ +int config_gradient(leds_t leds, int delta, float gradient_delay) +{ + int ack; + + /* Preconditions. */ + assert(delta > 0); + assert(delta <= 255); + + delay = roundf(gradient_delay / FW_MAIN_LOOP_DELAY); + /* Can't go infinitely fast. */ + if (delay == 0) + delay = 1; + /* Hardware doesn't support longer delays, we should do them with multiple + * commands if necessary. XXX Not supported for now. */ + if (delay > 255) + delay = 255; + ack = send_usb_tux_cmd(LED_FADE_SPEED_CMD, leds, delay, delta); + return ack; +} + +/** + * \brief Set the intensity of the LEDs. + * \param leds Which LEDs are affected by the command + * \param intensity Value of the intensity the LEDs should be set to. + * \param effect Fading or gradient effect applied when changing the intensity. + * + * \sa The effect types and parameters are described in the documentation of + * effect_type_t. + */ +int led_set(leds_t leds, int intensity, led_effect_t *effect) +{ + int ack; + /* Preconditions */ + assert(LED_NONE <= leds && leds <= LED_BOTH); + assert(0 <= intensity && intensity <= 255); + + switch(effect->type) + { + case UNAFFECTED: + /* Just change the intensity in this case. */ + break; + case LAST: + /* Don't update the parameters but send them in case the standalone + * changed them in the meantime. */ + ack = send_usb_tux_cmd(LED_FADE_SPEED_CMD, leds, delay, step); + /* XXX Due to bugs lying around in the dongle, RF and daemon, + * we can't trust the ack, so disabled for now. */ + /*if (ack != ACK_CMD_OK)*/ + /*return ack;*/ + break; + case NONE: + /* Emulate on/off. */ + step = 0xFF; + delay = 1; + ack = send_usb_tux_cmd(LED_FADE_SPEED_CMD, leds, delay, step); + /* XXX Due to bugs lying around in the dongle, RF and daemon, + * we can't trust the ack, so disabled for now. */ + /*if (ack != ACK_CMD_OK)*/ + /*return ack;*/ + break; + case DEFAULT: + /* Use default settings. */ + step = DEFAULT_STEP; + delay = DEFAULT_DELAY; + ack = send_usb_tux_cmd(LED_FADE_SPEED_CMD, leds, delay, step); + /* XXX Due to bugs lying around in the dongle, RF and daemon, + * we can't trust the ack, so disabled for now. */ + /*if (ack != ACK_CMD_OK)*/ + /*return ack;*/ + break; + case FADE_DURATION: + { + /* Intensity is changed by 'step' each 'delay'*4ms. + * So the duration from I1 to I2 is: + * duration = abs(I2 - I1) * 4ms * delay / step + * The fading delay in seconds is + * fading_delay = delay * 4ms / step + * = duration / abs(I2 - I1) + * + * If both leds are not at the same initial level, we can only + * have the same duration by assigning different parameters to + * each eye. */ + int left_increase, right_increase; + /* Flag that indicates if nothing needs to be done. */ + bool skip = true; + + /* We should use effect NONE if we don't want fading. */ + assert(effect->speed > 0); + left_increase = abs(intensity - get_led_left_intensity()); + right_increase = abs(intensity - get_led_right_intensity()); + /* Don't divide by zero if there's nothing to do ;-). */ + if (leds & LED_LEFT && left_increase) + { + skip = false; + ack = config_fading(LED_LEFT, effect->speed / \ + left_increase); + /* XXX Due to bugs lying around in the dongle, RF and daemon, + * we can't trust the ack, so disabled for now. */ + /*if (ack != ACK_CMD_OK)*/ + /*return ack;*/ + } + if (leds & LED_RIGHT && right_increase) + { + skip = false; + ack = config_fading(LED_RIGHT, effect->speed / \ + right_increase); + } + /* XXX Due to bugs lying around in the dongle, RF and daemon, + * we can't trust the ack, so disabled for now. */ + /*if (ack != ACK_CMD_OK)*/ + /*return ack;*/ + if (skip) + /* Nothing to do then. */ + return ack; + } + break; + case FADE_RATE: + /* Intensity is changed by 'step' each 'delay'*4ms, and it takes + * 255 steps to go from off to on. + * So the duration from off to on is: + * duration = 255 * 4ms * delay / step + * The fading delay in seconds is + * fading_delay = delay * 4ms / step + * = duration / 255 + * Now the delay should be rounded to the closest int or, if + * inferior to 1, we should play with the step in order to + * achieve faster effects. + */ + ack = config_fading(leds, effect->speed / 255); + /* XXX Due to bugs lying around in the dongle, RF and daemon, + * we can't trust the ack, so disabled for now. */ + /*if (ack != ACK_CMD_OK)*/ + /*return ack;*/ + break; + case GRADIENT_NBR: + { + int left_increase, right_increase; + int delta; + /* Flag indicating if nothing needs to be done. */ + bool skip = true; + + /* Preconditions */ + assert(effect->step > 0); + assert(effect->step <= 255); + /* We should use effect NONE if we don't want gradient. */ + assert(effect->speed > 0); + + left_increase = abs(intensity - get_led_left_intensity()); + right_increase = abs(intensity - get_led_right_intensity()); + /* Don't divide by zero if there's nothing to do ;-). */ + if (leds & LED_LEFT && left_increase) + { + skip = false; + delta = roundf(left_increase / effect->step); + /* If we can't have as many steps as required. */ + if (delta == 0) + delta = 1; + ack = config_gradient(LED_LEFT, delta, + effect->speed/effect->step); + /* XXX Due to bugs lying around in the dongle, RF and daemon, + * we can't trust the ack, so disabled for now. */ + /*if (ack != ACK_CMD_OK)*/ + /*return ack;*/ + } + if (leds & LED_RIGHT && right_increase) + { + skip = false; + delta = roundf(right_increase / effect->step); + /* If we can't have as many steps as required. */ + if (delta == 0) + delta = 1; + ack = config_gradient(LED_RIGHT, delta, + effect->speed/effect->step); + } + /* XXX Due to bugs lying around in the dongle, RF and daemon, + * we can't trust the ack, so disabled for now. */ + /*if (ack != ACK_CMD_OK)*/ + /*return ack;*/ + if (skip) + /* Nothing to do then. */ + return ack; + } + break; + case GRADIENT_DELTA: + { + int left_increase, right_increase; + float gradient_delay; + /* Flag indicating if nothing needs to be done. */ + bool skip = true; + + /* Preconditions */ + assert(effect->step > 0); + assert(effect->step <= 255); + /* We should use effect NONE if we don't want gradient. */ + assert(effect->speed > 0); + + left_increase = abs(intensity - get_led_left_intensity()); + right_increase = abs(intensity - get_led_right_intensity()); + /* Don't divide by zero if there's nothing to do ;-). */ + if (leds & LED_LEFT && left_increase) + { + skip = false; + gradient_delay = effect->speed * effect->step / \ + left_increase; + ack = config_gradient(LED_LEFT, effect->step, gradient_delay); + /* XXX Due to bugs lying around in the dongle, RF and daemon, + * we can't trust the ack, so disabled for now. */ + /*if (ack != ACK_CMD_OK)*/ + /*return ack;*/ + } + if (leds & LED_RIGHT && right_increase) + { + skip = false; + gradient_delay = effect->speed * effect->step / \ + right_increase; + ack = config_gradient(LED_RIGHT, effect->step, gradient_delay); + } + /* XXX Due to bugs lying around in the dongle, RF and daemon, + * we can't trust the ack, so disabled for now. */ + /*if (ack != ACK_CMD_OK)*/ + /*return ack;*/ + if (skip) + /* Nothing to do then. */ + return ack; + } + break; + default: + /* Not a correct type. */ + assert(0); + break; + } + ack = send_usb_tux_cmd(LED_SET_CMD, leds, intensity, 0); + return ack; +} + +void led_pulse(void) +{ + /* XXX add pulsing here. */ +} Property changes on: daemon/trunk/led.c ___________________________________________________________________ Name: svn:mime-type + text/plain Name: svn:keywords + Id Name: svn:eol-style + native Added: daemon/trunk/led.h =================================================================== --- daemon/trunk/led.h (rev 0) +++ daemon/trunk/led.h 2008-01-04 11:39:33 UTC (rev 823) @@ -0,0 +1,95 @@ +/* + * Tux Droid - USB Daemon + * Copyright (C) 2007 KYSOH S.A. <in...@ky...> + * + * 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, 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., 59 Temple Place - Suite 330, Boston, MA + * 02111-1307, USA. + */ + +/* $Id$ */ + +/** \file led.h + \brief Blue LEDs control interface. + \ingroup led +*/ + +/** \defgroup led LEDs + The LED module contains the functions that drive the eye LEDs. + There are 2 main functions: + - Setting the LEDs to a given intensity; it's possible to apply an effect + when changing the intensity; + - Pulsing the LEDs, you can choose the period, the intensity range and the + effect. +*/ +/*! @{ */ + +#ifndef _LED_H_ +#define _LED_H_ + +#include "tuxdefs/defines.h" + +/* + * Structure definitions, constants and custom types. + */ + +/** Types of effects applied when changing the intensity of the LEDs. */ +enum effect_type_t +{ + UNAFFECTED, /**< Don't update the effect parameters. This can either be + the last effect set by software, or by firmware in the + autonomous mode. This is probably not what you want. */ + LAST, /**< Last effect requested by software. */ + NONE, /**< Don't use effects, equivalent to on/off mode. */ + DEFAULT, /**< Default effect which is a short fading effect. */ + FADE_DURATION, /**< Fading effect, 'effect.speed' sets the duration (in + seconds) the effect will last. */ + FADE_RATE, /**< Fading effect, 'effect.speed' sets the rate of the + effect. Its value represents the number of seconds it + takes to apply the effect from off to on. So the actual + effect duration will take less time than specified if the + intensity starts or ends at intermediate values. + Therefore this parameter guarantees a constant rate of + the effect, not the duration. + */ + GRADIENT_NBR, /**< Gradient effect, the intensity changes gradually by a + number of steps given by 'effect.step'. 'effect.speed' + represents the number of seconds it should take to apply + the effect. */ + GRADIENT_DELTA, /**< Gradient effect, the intensity changes by a delta + value of 'effect.step'. 'effect.speed' represents the + number of seconds it should take to apply the effect. */ +}; + +/** Fading or gradient effect. This structure holds the type of effect and the + * corresponding parameters. + * \sa The effect types and parameters are described in the documentation of + * effect_type_t. */ +struct led_effect_t +{ + enum effect_type_t type; /**< Type of effect. */ + float speed; /**< Speed of the effect, used in both + gradients and fading effects. */ + int step; /**< Intensity step of the gradient effect. Not + used for the fading effect. */ +}; +typedef struct led_effect_t led_effect_t; + +/* + * Prototypes. + */ +extern int led_set(leds_t leds, int intensity, led_effect_t *effect); +/*! @} */ + +#endif /* _LED_H_ */ Property changes on: daemon/trunk/led.h ___________________________________________________________________ Name: svn:mime-type + text/plain Name: svn:keywords + Id Name: svn:eol-style + native Modified: daemon/trunk/libs/USBDaemon_command_tux.c =================================================================== --- daemon/trunk/libs/USBDaemon_command_tux.c 2008-01-04 11:39:24 UTC (rev 822) +++ daemon/trunk/libs/USBDaemon_command_tux.c 2008-01-04 11:39:33 UTC (rev 823) @@ -27,9 +27,11 @@ #include "USBDaemon_usb.h" #include "USBDaemon_command_tux.h" #include "USBDaemon_globals.h" -#include "USBDaemon_log.h" +#include "../log.h" #include "../tuxdefs/commands.h" #include "USBDaemon_pidfile.h" +#include "../led.h" +#include "../status.h" /*_____________________ D E F I N I T I O N S ______________________________*/ @@ -58,10 +60,6 @@ static void tux_req_status(unsigned char const data[], unsigned char result[]); static void tux_req_info(unsigned char const data[], unsigned char result[]); -static unsigned char send_usb_tux_cmd(unsigned char cmd, unsigned char param1, - unsigned char param2, - unsigned char param3); - /************************************************************************** */ /* COMMANDS FROM CLIENTS DISPATCHER */ /************************************************************************** */ @@ -460,8 +458,31 @@ ACK = send_usb_tux_cmd(LED_OFF_CMD, 0, 0, 0); break; case TUX_CMD_STRUCT_SUB_BLINK: - ACK = send_usb_tux_cmd(LED_BLINK_CMD, data[2], data[3], 0); + { + led_effect_t myeffect; + myeffect.type = DEFAULT; + //ACK = send_usb_tux_cmd(LED_PULSE_CMD, 3, data[2], data[3]); + ACK = led_set(data[2], data[3], &myeffect); + } break; + case TUX_CMD_STRUCT_SUB_SET: + { + led_effect_t effect; + effect.type = data[4]; + /* Workaround to send a float through TCP/IP, just send a + * uint8_t which is the float parameter multiplied by 16, then + * divide it here again. The limitation is of course the range. + */ + effect.speed = (float)data[5]/16; + effect.step = data[6]; + ACK = led_set(data[2], data[3], &effect); + } + break; + case TUX_CMD_STRUCT_SUB_PULSE: + { + /* XXX add pulsing here. */ + } + break; } break; case TUX_CMD_STRUCT_LEDL: @@ -581,10 +602,10 @@ case DATA_STATUS_MOTOR_FOR_WINGS: result[1] = portc.bits.PB1; break; - case DATA_STATUS_LEFT_BLUE_LED: + case DATA_STATUS_LED_LEFT_INTENSITY: result[1] = portc.bits.PB2; break; - case DATA_STATUS_RIGHT_BLUE_LED: + case DATA_STATUS_LED_RIGHT_INTENSITY: result[1] = portc.bits.PB3; break; case DATA_STATUS_HEAD_MOTOR_FOR_MOUTH: Modified: daemon/trunk/libs/USBDaemon_command_tux.h =================================================================== --- daemon/trunk/libs/USBDaemon_command_tux.h 2008-01-04 11:39:24 UTC (rev 822) +++ daemon/trunk/libs/USBDaemon_command_tux.h 2008-01-04 11:39:33 UTC (rev 823) @@ -41,6 +41,9 @@ unsigned char param1, unsigned char param2, unsigned char param3); +extern unsigned char send_usb_tux_cmd(unsigned char cmd, unsigned char param1, + unsigned char param2, + unsigned char param3); extern void tux_audio_init(void); extern unsigned char send_wave_wings(unsigned char count, unsigned char speed); extern unsigned char send_stop_wings(); Deleted: daemon/trunk/libs/USBDaemon_log.c =================================================================== --- daemon/trunk/libs/USBDaemon_log.c 2008-01-04 11:39:24 UTC (rev 822) +++ daemon/trunk/libs/USBDaemon_log.c 2008-01-04 11:39:33 UTC (rev 823) @@ -1,211 +0,0 @@ - -#include "USBDaemon_globals.h" -#include "USBDaemon_log.h" - -#include <stdlib.h> -#include <stdio.h> -#include <stdarg.h> -#include <time.h> -#include <assert.h> -#include <syslog.h> - -/** Name of log file for target LOG_TARGET_TUX */ -#define LOG_FILE "/var/log/" TUX_DAEMON_NAME ".log" - -/** All logged messages are prefixed with this text */ -#define LOG_PREFIX TUX_DAEMON_NAME - -/** Current logging level */ -static log_level_t current_level = LOG_LEVEL_INFO; - -/** Logging level names */ -static const char *level_names[] = -{ - [LOG_LEVEL_DEBUG] = "debug", - [LOG_LEVEL_INFO] = "info", - [LOG_LEVEL_WARNING] = "warning", - [LOG_LEVEL_ERROR] = "error", - [LOG_LEVEL_NONE] = "none" -}; - -/** Logging level to syslog priority mapping */ -static int level_prio[] = -{ - [LOG_LEVEL_DEBUG] = LOG_DEBUG, - [LOG_LEVEL_INFO] = LOG_INFO, - [LOG_LEVEL_WARNING] = LOG_WARNING, - [LOG_LEVEL_ERROR] = LOG_ERR, - [LOG_LEVEL_NONE] = 0 -}; - -/** Current logging target */ -static log_target_t log_target = LOG_TARGET_SHELL; - -/** Log file for target LOG_TARGET_TUX */ -static FILE *log_file; - -/** Whether the log has been opened */ -static bool log_opened; - -/** - * Open the log. - * - * /param[in] target Logging target - * - * /return true if successfull, false otherwise - */ -bool log_open(log_target_t target) -{ - if (log_opened) - return true; - - switch (target) - { - case LOG_TARGET_SYSLOG: - openlog(LOG_PREFIX, 0, LOG_DAEMON); - break; - - case LOG_TARGET_TUX: - log_file = fopen(LOG_FILE, "at"); - if (log_file == NULL) - return false; - break; - - case LOG_TARGET_SHELL: - break; - } - - log_target = target; - log_opened = true; - - return true; -} - -/** - * Close the log. - */ -void log_close(void) -{ - if (!log_opened) - return; - - switch (log_target) - { - case LOG_TARGET_SYSLOG: - closelog(); - break; - - case LOG_TARGET_TUX: - fclose(log_file); - log_file = NULL; - break; - - case LOG_TARGET_SHELL: - break; - } - - log_opened = false; -} - -/** - * Set the logging level. - * - * /param[in] new_level New logging level - */ -void log_set_level(log_level_t new_level) -{ - assert(new_level >= LOG_LEVEL_DEBUG && new_level <= LOG_LEVEL_NONE); - current_level = new_level; -} - -/** - * Get the logging level. - * - * /return current logging level - */ -log_level_t log_get_level(void) -{ - return current_level; -} - -/** - * Log formatted message at the specified level. - * - * /param[in] at_level Level to log the message at - * /param[in] fmt Message format - * /param[in] ... Optional message data - * - * If the priority of the specifed level is lower than the priority - * of the current logging level, the message is silently dropped. - * - * /return true if successful, false otherwise - */ -bool log_text(log_level_t at_level, const char *fmt, ...) -{ - char text[1024], *p = text; - size_t size = sizeof(text); - int prio; - time_t now; - va_list al; - int r; - - /* No need for the log to be 'opened' when logging to std{out,err} */ - if (log_target != LOG_TARGET_SHELL && !log_opened) - return false; - - /* Logging at level NONE has no sense */ - assert(at_level >= LOG_LEVEL_DEBUG && at_level < LOG_LEVEL_NONE); - - if (at_level < current_level) - return true; - - /* Add date & time when LOG_TARGET_TUX */ - if (log_target == LOG_TARGET_TUX) - { - now = time(NULL); - r = strftime(p, size, "%F %T ", localtime(&now)); - if (r == 0) - return false; - - p += r; - size -= r; - } - - /* Only prefix non-INFO level messages */ - if (at_level != LOG_LEVEL_INFO) - { - r = snprintf(p, size, "%s: ", level_names[at_level]); - if (r < 0) - return false; - - p += r; - size -= r; - } - - va_start(al, fmt); - r = vsnprintf(p, size, fmt, al); - va_end(al); - if (r < 0) - return false; - - switch (log_target) - { - case LOG_TARGET_SYSLOG: - prio = level_prio[at_level]; - syslog(prio, "%s", text); - break; - - case LOG_TARGET_TUX: - fprintf(log_file, "%s\n", text); - break; - - case LOG_TARGET_SHELL: - if (at_level == LOG_LEVEL_WARNING || at_level == LOG_LEVEL_ERROR) - fprintf(stderr, "%s\n", text); - else - fprintf(stdout, "%s\n", text); - break; - } - - return true; -} Deleted: daemon/trunk/libs/USBDaemon_log.h =================================================================== --- daemon/trunk/libs/USBDaemon_log.h 2008-01-04 11:39:24 UTC (rev 822) +++ daemon/trunk/libs/USBDaemon_log.h 2008-01-04 11:39:33 UTC (rev 823) @@ -1,38 +0,0 @@ -#ifndef __USBDAEMON_LOG_H__ -#define __USBDAEMON_LOG_H__ - -#include <stdbool.h> - -/** Logging target */ -typedef enum log_target -{ - LOG_TARGET_SYSLOG, - LOG_TARGET_TUX, - LOG_TARGET_SHELL -} log_target_t; - -extern bool log_open(log_target_t target); -extern void log_close(void); - -/** Logging levels, in increasing priorities */ -typedef enum log_level -{ - LOG_LEVEL_DEBUG, - LOG_LEVEL_INFO, - LOG_LEVEL_WARNING, - LOG_LEVEL_ERROR, - LOG_LEVEL_NONE -} log_level_t; - -extern void log_set_level(log_level_t new_level); -extern log_level_t log_get_level(void); - -extern bool log_text(log_level_t at_level, const char *fmt, ...) - __attribute__((format(printf, 2, 3))); - -#define log_debug(fmt, ...) log_text(LOG_LEVEL_DEBUG, (fmt), ## __VA_ARGS__) -#define log_info(fmt, ...) log_text(LOG_LEVEL_INFO, (fmt), ## __VA_ARGS__) -#define log_warning(fmt, ...) log_text(LOG_LEVEL_WARNING, (fmt), ## __VA_ARGS__) -#define log_error(fmt, ...) log_text(LOG_LEVEL_ERROR, (fmt), ## __VA_ARGS__) - -#endif Modified: daemon/trunk/libs/USBDaemon_pidfile.c =================================================================== --- daemon/trunk/libs/USBDaemon_pidfile.c 2008-01-04 11:39:24 UTC (rev 822) +++ daemon/trunk/libs/USBDaemon_pidfile.c 2008-01-04 11:39:33 UTC (rev 823) @@ -31,7 +31,7 @@ #include <signal.h> #include "USBDaemon_globals.h" -#include "USBDaemon_log.h" +#include "../log.h" #define PIDFILE "/var/run/" TUX_DAEMON_NAME ".pid" Modified: daemon/trunk/libs/USBDaemon_status_table.c =================================================================== --- daemon/trunk/libs/USBDaemon_status_table.c 2008-01-04 11:39:24 UTC (rev 822) +++ daemon/trunk/libs/USBDaemon_status_table.c 2008-01-04 11:39:33 UTC (rev 823) @@ -1,6 +1,6 @@ /* * Tux Droid - USB Daemon - * Copyright (C) 2007 C2ME Sa <rem...@c2...> + * Copyright (C) 2007 C2ME S.A. <tux...@c2...> * * 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 @@ -28,8 +28,9 @@ #include "USBDaemon_status_table.h" #include "USBDaemon_usb.h" #include "USBDaemon_globals.h" -#include "USBDaemon_log.h" +#include "../log.h" #include "USBDaemon_tcp_server.h" +#include "../status.h" #include "../supervise.h" #include "../versioning.h" #include "../tuxdefs/commands.h" @@ -49,14 +50,6 @@ unsigned char sound_flash_count = 0; /** - * Tux status table. - * - * This hierarchical structure holds all current status of tux and the dongle. - * As soon as a new status is received from tux, the structure is updated. - */ -struct tux_status_t tux_status; - -/** * Status table and settings of the dongle and RF modules */ struct connection_status_t connection_status; @@ -252,6 +245,17 @@ tcp_server_send_raw(tcp_frame); } +static void update_leds(uint8_t const * led_status) +{ + set_led_left_intensity(*led_status++); + set_led_right_intensity(*led_status++); + set_led_left_fading(*led_status & 0x01 ? true : false); + set_led_left_pulsing(*led_status & 0x02 ? true : false); + set_led_right_fading(*led_status & 0x04 ? true : false); + set_led_right_pulsing(*led_status & 0x08 ? true : false); + set_led_mask(*led_status & 0x10 ? true : false); +} + /* TODO Add functions to get the average battery voltage and status */ static void battery_changed(unsigned int const level, unsigned int const loaded) @@ -435,24 +439,10 @@ tcp_server_send_raw(tcp_frame); } - /* right blue led */ - if ((portc.Byte & 0x08) != (new_value & 0x08)) - { - tcp_frame[4] = DATA_STATUS_RIGHT_BLUE_LED; - tcp_frame[5] = !portc.bits.PB3; - log_debug("right blue led %s", tcp_frame[5] ? "on" : "off"); - tcp_server_send_raw(tcp_frame); - } + /* Blue led I/O */ + tux_status.io.left_led = (new_value & 0x04) ? true : false; + tux_status.io.right_led = (new_value & 0x08) ? true : false; - /* left blue led */ - if ((portc.Byte & 0x04) != (new_value & 0x04)) - { - tcp_frame[4] = DATA_STATUS_LEFT_BLUE_LED; - tcp_frame[5] = !portc.bits.PB2; - log_debug("left blue led %s", tcp_frame[5] ? "on" : "off"); - tcp_server_send_raw(tcp_frame); - } - portc.Byte = new_value; } @@ -703,6 +693,10 @@ position2_changed(new_status[1]); break; + case STATUS_LED_CMD: + update_leds(&new_status[1]); + break; + case PONG_CMD: pong_received++; pong_event(new_status[1], pong_received); @@ -734,6 +728,7 @@ new_status[2], new_status[3]); break; } + status_log(); } /************************************************************************ */ Modified: daemon/trunk/libs/USBDaemon_status_table.h =================================================================== --- daemon/trunk/libs/USBDaemon_status_table.h 2008-01-04 11:39:24 UTC (rev 822) +++ daemon/trunk/libs/USBDaemon_status_table.h 2008-01-04 11:39:33 UTC (rev 823) @@ -141,6 +141,8 @@ #define TUX_CMD_STRUCT_SUB_CLOSE 0x0D #define TUX_CMD_STRUCT_SUB_DOWN 0x0D #define TUX_CMD_STRUCT_SUB_ERASE 0x0E +#define TUX_CMD_STRUCT_SUB_SET 0x0F +#define TUX_CMD_STRUCT_SUB_PULSE 0x10 /* Tux request information */ #define TUX_REQ_INFO_VERSION 0x01 @@ -154,7 +156,7 @@ #define DATA_STATUS_HEAD_PUSH_POSITION 0x06 #define DATA_STATUS_WINGS_POSITION_SWITCH 0x08 #define DATA_STATUS_MOTOR_FOR_WINGS 0x09 -#define DATA_STATUS_LEFT_BLUE_LED 0x0A +#define DATA_STATUS_LED_LEFT_INTENSITY 0x0A #define DATA_STATUS_I2C_SDA_LINE 0x0B #define DATA_STATUS_I2C_SCL_LINE 0x0C #define DATA_STATUS_HEAD_MOTOR_FOR_MOUTH 0x0D @@ -176,7 +178,7 @@ #define DATA_STATUS_MOUTH_POSITION_COUNTER 0x1D #define DATA_STATUS_WINGS_POSITION_COUNTER 0x1E #define DATA_STATUS_SPIN_POSITION_COUNTER 0x1F -#define DATA_STATUS_RIGHT_BLUE_LED 0x20 +#define DATA_STATUS_LED_RIGHT_INTENSITY 0x20 #define DATA_STATUS_RF_CONNECTED 0x21 #define DATA_STATUS_IR_CODE 0x22 #define DATA_STATUS_PONG 0x24 @@ -273,150 +275,8 @@ extern void update_raw_status_table(const unsigned char *new_status); extern void update_system_status_table(const unsigned char *new_status); -/** Number of firmware information structures to store. - * There's one for each firmware and one for the general release package. - * Firmware will have the same index as defined in CPU_IDENTIFIERS, the last - * one will be the release package. */ -#define NUMBER_OF_FIRMWARE (HIGHEST_CPU_NUM + 2) -/** Index of the general release package information structure defined in - * tux_status. */ -#define RELEASE_INDEX (NUMBER_OF_FIRMWARE - 1) -/** Size of the version string. */ -#define VERSION_STRING_LENGTH 100 -/** States of the battery charger */ -typedef enum charger_status -{ - CHARGER_UNPLUGGED = 0, /**< unplugged, on batteries */ - CHARGER_CHARGING = 1, /**< fast charge ongoing */ - CHARGER_PLUGGED_NO_POWER = 2, /**< transformer plugged on tux but not in - the wall socket */ - CHARGER_TRICKLE = 3, /**< trickle mode, mainly activated at the end of - charge */ - CHARGER_INHIBITED = 4, /**< the CPU has inhibited the charger */ -} charger_status_t; - -/** States of the battery level - * \todo TODO write the function that would compute the battery state depending - * on the battery voltage, load and charger status */ -typedef enum battery_status -{ - FULL, - HIGH, - LOW, - EMPTY, -} battery_status_t; - /** - * Tux status table. - * - * This hierarchical structure holds all available status of tux and the - * dongle. - */ -struct tux_status_t -{ - /** Firmware general information like versioning , svn revision, author and - * a couple more stuff. - * - * The version number is written as 'major.minor.update'. - * - * When local_modification or mixed_revisions are found, it can't be a - * release. */ - struct firmware_info_t - { - unsigned int version_major; /**< Major version number */ - unsigned int version_minor; /**< Minor version number */ - unsigned int version_update;/**< Update version number */ - unsigned int revision; /**< SVN revision number */ - bool release; /**< Set for a released firmware */ - bool local_modification; /**< Has local modifications compared to - the SVN revision copy */ - bool mixed_revisions; /**< Has been compiled with a mix of SVN - revisions */ - unsigned int author;/**< Number representing the author of the - firmware, '0' is the official firmware of Kysoh */ - unsigned int variation; /**< Variation can be used by the author to - differentiate multiple variations of the - same firmware */ - char version_string[VERSION_STRING_LENGTH]; /**< Whole version number - stored as a string */ - } firmware_info[NUMBER_OF_FIRMWARE]; - - /** Sound flash properties. */ - struct sound_flash_t - { - unsigned int number_of_sounds; /**< number of sounds stored in the - sound flash */ - unsigned int flash_usage; /**< flash space percentage filled */ - unsigned int available_record_time; /**< time (in seconds) of free - space remaining in the flash */ - } sound_flash; - - /** Battery status. - * 'loaded' can be used to filter out 'level' measurements that occurred - * when the motors were running as the battery voltage is highly affected - * by the load. */ - struct battery_t - { - unsigned int level; /**< Last battery level measurement (raw data - from the ADC) */ - bool loaded; /**< Set if the battery was loaded when the - measurement was done (i.e. motors running). */ - float voltage; /**< Mean battery voltage */ - battery_status_t status;/**< Battery level status (low, high, etc.) */ - charger_status_t charger_state; /**<Battery charger state. */ - - } battery; - - /** Audio status */ - struct audio_t - { - unsigned int play_internal_sound; /**< Number of the sound currently - playing ('0' when none) */ - bool streaming; /**< Set when audio data is streamed through the RF - link */ - bool mute; /**< Set when the amplifier has been muted */ - audiorec_status_t record_state; /**< States of the recording process */ - unsigned int last_block_size; /**< Size of the last recorded audio - segment. This can be used by the - recording process to determine if the - correct length has been recorded. */ - } audio; - - /** Raw I/O status */ - struct buttons_t - { - bool head; /**< Head push button */ - bool left_flipper; /**< Left flipper push button */ - bool right_flipper; /**< Right flipper push button */ - uint8_t RC5_code; /**< Last code of the Tuxdroid remote button pressed. - - Bit 6 is the toggle bit, it's toggled each time you - press a remote key and should be used to - differentiate successive key presses of the same - button. - - Bits 5-0 are the 6 bits RC5 command code. */ - bool RC5_receiving; /**< Set when the remote button is pressed, cleared - when released. If you're clicking the remote - buttons very quickly, RC5_receiving will miss the - button releases in between. You should use the - toggle bit of the remote code to differentiate - successive key presses. */ - } buttons; - - /** Raw I/O status */ - struct io_t - { - bool plugged; /**< Power plug insertion switch, set when the - transformer is plugged to tux */ - bool charger_led_signal; /**< LED signal of the BQ2002T IC charger. - Goes low when fast charging, high otherwise - (trickle, not charging, init, etc. See the - datasheet for details. */ - bool charge_inhibit; - } io; -}; - -/** * Daemon version information. */ struct daemon_version_t @@ -443,9 +303,6 @@ uint8_t wifi_channel; }; -/* Structures that define the variables that should be accessible by the API. - */ -extern struct tux_status_t tux_status; extern struct daemon_version_t daemon_version; extern struct connection_status_t connection_status; Modified: daemon/trunk/libs/USBDaemon_tcp_server.c =================================================================== --- daemon/trunk/libs/USBDaemon_tcp_server.c 2008-01-04 11:39:24 UTC (rev 822) +++ daemon/trunk/libs/USBDaemon_tcp_server.c 2008-01-04 11:39:33 UTC (rev 823) @@ -36,7 +36,7 @@ #include "USBDaemon_usb.h" #include "USBDaemon_pidfile.h" #include "../supervise.h" -#include "USBDaemon_log.h" +#include "../log.h" /*_____________________ V A R I A B L E S __________________________________*/ Modified: daemon/trunk/libs/USBDaemon_usb.c =================================================================== --- daemon/trunk/libs/USBDaemon_usb.c 2008-01-04 11:39:24 UTC (rev 822) +++ daemon/trunk/libs/USBDaemon_usb.c 2008-01-04 11:39:33 UTC (rev 823) @@ -26,7 +26,7 @@ #include "USBDaemon_usb.h" #include "USBDaemon_globals.h" -#include "USBDaemon_log.h" +#include "../log.h" #include "USBDaemon_status_table.h" #include "USBDaemon_tcp_server.h" @@ -148,7 +148,7 @@ log_error("Your dongle firmware is too old.\n" "This version is not compatible with this daemon, please \ update\n" - "the firmware to version 1.00 or better.\n" + "the firmware to version 0.3.1 or better.\n" "Check http://www.tuxisalive.com/documentation/how-to/\ updating-the-firmware\nfor details."); return 0; @@ -293,8 +293,9 @@ /* Send data */ idx = usb_write_TuxDroid(data, TUX_SEND_LENGTH); if (idx <= 0) - return ACK_CMD_TIMEOUT; - log_debug("CMD: %.2x %.2x %.2x %.2x", data[0], data[1], data[2], data[3]); + return ACK_CMD_ERROR; + log_debug("CMD: %.2x %.2x %.2x %.2x %.2x", data[0], data[1], data[2], + data[3], data[4]); cmd_status_flag = 1; counter = 0; csf = cmd_status_flag; Copied: daemon/trunk/log.c (from rev 740, daemon/trunk/libs/USBDaemon_log.c) =================================================================== --- daemon/trunk/log.c (rev 0) +++ daemon/trunk/log.c 2008-01-04 11:39:33 UTC (rev 823) @@ -0,0 +1,232 @@ +/* + * Tux Droid - USB Daemon + * Copyright (C) 2007 C2ME S.A. <tux...@c2...> + * + * 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, 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., 59 Temple Place - Suite 330, Boston, MA + * 02111-1307, USA. + */ + +/* $Id: USBDaemon_status_table.c 743 2007-11-29 10:50:21Z jaguarondi $ */ + +#include <stdlib.h> +#include <stdio.h> +#include <stdarg.h> +#include <time.h> +#include <assert.h> +#include <syslog.h> + +#include "libs/USBDaemon_globals.h" +#include "log.h" + +/** Name of log file for target LOG_TARGET_TUX */ +#define LOG_FILE "/var/log/" TUX_DAEMON_NAME ".log" + +/** All logged messages are prefixed with this text */ +#define LOG_PREFIX TUX_DAEMON_NAME + +/** Current logging level */ +static log_level_t current_level = LOG_LEVEL_INFO; + +/** Logging level names */ +static const char *level_names[] = +{ + [LOG_LEVEL_DEBUG] = "debug", + [LOG_LEVEL_INFO] = "info", + [LOG_LEVEL_WARNING] = "warning", + [LOG_LEVEL_ERROR] = "error", + [LOG_LEVEL_NONE] = "none" +}; + +/** Logging level to syslog priority mapping */ +static int level_prio[] = +{ + [LOG_LEVEL_DEBUG] = LOG_DEBUG, + [LOG_LEVEL_INFO] = LOG_INFO, + [LOG_LEVEL_WARNING] = LOG_WARNING, + [LOG_LEVEL_ERROR] = LOG_ERR, + [LOG_LEVEL_NONE] = 0 +}; + +/** Current logging target */ +static log_target_t log_target = LOG_TARGET_SHELL; + +/** Log file for target LOG_TARGET_TUX */ +static FILE *log_file; + +/** Whether the log has been opened */ +static bool log_opened; + +/** + * Open the log. + * + * /param[in] target Logging target + * + * /return true if successfull, false otherwise + */ +bool log_open(log_target_t target) +{ + if (log_opened) + return true; + + switch (target) + { + case LOG_TARGET_SYSLOG: + openlog(LOG_PREFIX, 0, LOG_DAEMON); + break; + + case LOG_TARGET_TUX: + log_file = fopen(LOG_FILE, "at"); + if (log_file == NULL) + return false; + break; + + case LOG_TARGET_SHELL: + break; + } + + log_target = target; + log_opened = true; + + return true; +} + +/** + * Close the log. + */ +void log_close(void) +{ + if (!log_opened) + return; + + switch (log_target) + { + case LOG_TARGET_SYSLOG: + closelog(); + break; + + case LOG_TARGET_TUX: + fclose(log_file); + log_file = NULL; + break; + + case LOG_TARGET_SHELL: + break; + } + + log_opened = false; +} + +/** + * Set the logging level. + * + * /param[in] new_level New logging level + */ +void log_set_level(log_level_t new_level) +{ + assert(new_level >= LOG_LEVEL_DEBUG && new_level <= LOG_LEVEL_NONE); + current_level = new_level; +} + +/** + * Get the logging level. + * + * /return current logging level + */ +log_level_t log_get_level(void) +{ + return current_level; +} + +/** + * Log formatted message at the specified level. + * + * /param[in] at_level Level to log the message at + * /param[in] fmt Message format + * /param[in] ... Optional message data + * + * If the priority of the specifed level is lower than the priority + * of the current logging level, the message is silently dropped. + * + * /return true if successful, false otherwise + */ +bool log_text(log_level_t at_level, const char *fmt, ...) +{ + char text[1024], *p = text; + size_t size = sizeof(text); + int prio; + time_t now; + va_list al; + int r; + + /* No need for the log to be 'opened' when logging to std{out,err} */ + if (log_target != LOG_TARGET_SHELL && !log_opened) + return false; + + /* Logging at level NONE has no sense */ + assert(at_level >= LOG_LEVEL_DEBUG && at_level < LOG_LEVEL_NONE); + + if (at_level < current_level) + return true; + + /* Add date & time when LOG_TARGET_TUX */ + if (log_target == LOG_TARGET_TUX) + { + now = time(NULL); + r = strftime(p, size, "%F %T ", localtime(&now)); + if (r == 0) + return false; + + p += r; + size -= r; + } + + /* Only prefix non-INFO level messages */ + if (at_level != LOG_LEVEL_INFO) + { + r = snprintf(p, size, "%s: ", level_names[at_level]); + if (r < 0) + return false; + + p += r; + size -= r; + } + + va_start(al, fmt); + r = vsnprintf(p, size, fmt, al); + va_end(al); + if (r < 0) + return false; + + switch (log_target) + { + case LOG_TARGET_SYSLOG: + prio = level_prio[at_level]; + syslog(prio, "%s", text); + break; + + case LOG_TARGET_TUX: + fprintf(log_file, "%s\n", text); + break; + + case LOG_TARGET_SHELL: + if (at_level == LOG_LEVEL_WARNING || at_level == LOG_LEVEL_ERROR) + fprintf(stderr, "%s\n", text); + else + fprintf(stdout, "%s\n", text); + break; + } + + return true; +} Copied: daemon/trunk/log.h (from rev 740, daemon/trunk/libs/USBDaemon_log.h) =================================================================== --- daemon/trunk/log.h (rev 0) +++ daemon/trunk/log.h 2008-01-04 11:39:33 UTC (rev 823) @@ -0,0 +1,38 @@ +#ifndef __USBDAEMON_LOG_H__ +#define __USBDAEMON_LOG_H__ + +#include <stdbool.h> + +/** Logging target */ +typedef enum log_target +{ + LOG_TARGET_SYSLOG, + LOG_TARGET_TUX, + LOG_TARGET_SHELL +} log_target_t; + +extern bool log_open(log_target_t target); +extern void log_close(void); + +/** Logging levels, in increasing priorities */ +typedef enum log_level +{ + LOG_LEVEL_DEBUG, + LOG_LEVEL_INFO, + LOG_LEVEL_WARNING, + LOG_LEVEL_ERROR, + LOG_LEVEL_NONE +} log_level_t; + +extern void log_set_level(log_level_t new_level); +extern log_level_t log_get_level(void); + +extern bool log_text(log_level_t at_level, const char *fmt, ...) + __attribute__((format(printf, 2, 3))); + +#define log_debug(fmt, ...) log_text(LOG_LEVEL_DEBUG, (fmt), ## __VA_ARGS__) +#define log_info(fmt, ...) log_text(LOG_LEVEL_INFO, (fmt), ## __VA_ARGS__) +#define log_warning(fmt, ...) log_text(LOG_LEVEL_WARNING, (fmt), ## __VA_ARGS__) +#define log_error(fmt, ...) log_text(LOG_LEVEL_ERROR, (fmt), ## __VA_ARGS__) + +#endif Modified: daemon/trunk/main.c =================================================================== --- daemon/trunk/main.c 2008-01-04 11:39:24 UTC (rev 822) +++ daemon/trunk/main.c 2008-01-04 11:39:33 UTC (rev 823) @@ -35,7 +35,7 @@ #include <signal.h> #include <sys/file.h> #include "libs/USBDaemon_globals.h" -#include "libs/USBDaemon_log.h" +#include "log.h" #include "libs/USBDaemon_pidfile.h" #include "libs/USBDaemon_usb.h" #include "libs/USBDaemon_tcp_server.h" Added: daemon/trunk/status.c =================================================================== --- daemon/trunk/status.c (rev 0) +++ daemon/trunk/status.c 2008-01-04 11:39:33 UTC (rev 823) @@ -0,0 +1,191 @@ +/* + * Tux Droid - USB Daemon + * Copyright (C) 2007 KYSOH S.A. <in...@ky...> + * + * 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, 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., 59 Temple Place - Suite 330, Boston, MA + * 02111-1307, USA. + */ + +/* $Id$ */ + +#include <stdbool.h> +#include <assert.h> + +#include "status.h" +#include "log.h" + +/** + * Tux status table. + * + * This hierarchical structure holds all current status of tux and the dongle. + * As soon as a new status is received from tux, the structure is updated. + */ +struct tux_status_t tux_status; + +/* Flags for updated status. */ +static bool up_led; + + +/* + * LEDs + */ + +/** + * Set the intensity status of the left LED. + */ +void set_led_left_intensity(int intensity) +{ + up_led = true; + tux_status.led.left.intensity = intensity; +} + +/** + * Get the intensity status of the left LED. + */ +int get_led_left_intensity(void) +{ + return tux_status.led.left.intensity; +} + +/** + * Set the fading status of the left LED. + */ +void set_led_left_fading(bool fading) +{ + up_led = true; + tux_status.led.left.fading = fading; +} + +/** + * Get the fading status of the left LED. + */ +bool get_led_left_fading(void) +{ + return tux_status.led.left.fading; +} + +/** + * Set the pulsing status of the left LED. + */ +void set_led_left_pulsing(bool pulsing) +{ + up_led = true; + tux_status.led.left.pulsing = pulsing; +} + +/** + * Get the pulsing status of the left LED. + */ +bool get_led_left_pulsing(void) +{ + return tux_status.led.left.pulsing; +} + +/** + * Set the intensity status of the right LED. + */ +void set_led_right_intensity(int intensity) +{ + up_led = true; + tux_status.led.right.intensity = intensity; +} + +/** + * Get the intensity status of the right LED. + */ +int get_led_right_intensity(void) +{ + return tux_status.led.right.intensity; +} + +/** + * Set the fading status of the right LED. + */ +void set_led_right_fading(bool fading) +{ + up_led = true; + tux_status.led.right.fading = fading; +} + +/** + * Get the fading status of the right LED. + */ +bool get_led_right_fading(void) +{ + return tux_status.led.right.fading; +} + +/** + * Set the pulsing status of the right LED. + */ +void set_led_right_pulsing(bool pulsing) +{ + up_led = true; + tux_status.led.right.pulsing = pulsing; +} + +/** + * Get the pulsing status of the right LED. + */ +bool get_led_right_pulsing(void) +{ + return tux_status.led.right.pulsing; +} + +/** + * Set the mask status of the LEDs. + */ +void set_led_mask(bool mask) +{ + up_led = true; + tux_status.led.mask = mask; +} + +/** + * Get the mask status of the LEDs. + */ +bool get_led_mask(void) +{ + return tux_status.led.mask; +} + + +/* + * Control functions. + */ + +/** + * When status are updated, log what changed. + * + * \todo TODO we should remove the flags and compare the table with a backup + * copy, then determine what changed and do the logs and callbacks. + */ +void status_log(void) +{ + if (up_led) + { + struct led_t *led = &tux_status.led; + + up_led = false; + log_debug("LEDs L:%3d (%s%s) R:%3d (%s%s) %s", + led->left.intensity, + led->left.fading ? "F" : "_", + led->left.pulsing ? "P" : "_", + led->right.intensity, + led->right.fading ? "F" : "_", + led->right.pulsing ? "P" : "_", + led->mask ? "masked" : ""); + } +} Property changes on: daemon/trunk/status.c ___________________________________________________________________ Name: svn:mime-type + text/plain Name: svn:keywords + Id Name: svn:eol-style + native Added: daemon/trunk/status.h =================================================================== --- daemon/trunk/status.h (rev 0) +++ daemon/trunk/status.h 2008-01-04 11:39:33 UTC (rev 823) @@ -0,0 +1,240 @@ +/* + * Tux Droid - USB Daemon + * Copyright (C) 2007 KYSOH S.A. <in...@ky...> + * + * 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, 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., 59 Temple Place - Suite 330, Boston, MA + * 02111-1307, USA. + */ + +/* $Id$ */ + +/** \file status.h + \brief Status module interface. + \ingroup status +*/ + +/** \defgroup status Status + The status module contains all tux status and its accessors functions. +*/ +/*! @{ */ + +#include <stdbool.h> + +#include "tuxdefs/api.h" +#include "tuxdefs/defines.h" +#include "version.h" + + +/** + * \name Versioning of the firmware + * XXX should clean this part + * @{ */ +/** Number of firmware information structures to store. + * There's one for each firmware and one for the general release package. + * Firmware will have the same index as defined in CPU_IDENTIFIERS, the last + * one will be the release package. */ +#define NUMBER_OF_FIRMWARE (HIGHEST_CPU_NUM + 2) +/** Index of the general release package information structure defined in + * tux_status. */ +#define RELEASE_INDEX (NUMBER_OF_FIRMWARE - 1) +/** Size of the version string. */ +#define VERSION_STRING_LENGTH 100 +/*! @} */ + +/** + * \name Battery and charger states definitions. + * XXX should add the accessors + * @{ */ +/** States of the battery charger */ +typedef enum charger_status +{ + CHARGER_UNPLUGGED = 0, /**< Unplugged, on batteries */ + CHARGER_CHARGING = 1, /**< Fast charge ongoing */ + CHARGER_PLUGGED_NO_POWER = 2, /**< Transformer plugged on tux but not in + the wall socket */ + CHARGER_TRICKLE = 3, /**< Trickle mode, mainly activated at the end of + charge */ + CHARGER_INHIBITED = 4, /**< The CPU has inhibited the charger */ +} charger_status_t; + +/** States of the battery level + * \todo TODO write the function that would compute the battery state depending + * on the battery voltage, load and charger status */ +typedef enum battery_status +{ + FULL, /**< Battery fully charged */ + HIGH, /**< Battery level high */ + LOW, /**< Battery level low */ + EMPTY, /**< Battery empty, tux won't work any longer */ +} battery_status_t; +/*! @} */ + +/** + * Tux status table. + * + * This hierarchical structure holds all available status of tux and the + * dongle. + * XXX this structure should be moved to .c file to hide the included data. + */ +struct tux_status_t +{ + /** Firmware general information like versioning , svn revision, author and + * a couple more stuff. + * + * The version number is written as 'major.minor.update'. + * + * When local_modification or mixed_revisions are found, it can't be a + * release. */ + struct firmware_info_t + { + unsigned int version_major; /**< Major version number */ + unsigned int version_minor; /**< Mi... [truncated message content] |