[tuxdroid-svn] r526 - daemon/trunk/libs
Status: Beta
Brought to you by:
ks156
From: Paul_R <c2m...@c2...> - 2007-09-18 09:54:29
|
Author: Paul_R Date: 2007-09-18 11:54:28 +0200 (Tue, 18 Sep 2007) New Revision: 526 Modified: daemon/trunk/libs/USBDaemon_command_tux.c daemon/trunk/libs/USBDaemon_status_table.c daemon/trunk/libs/USBDaemon_status_table.h Log: * Added light measurment processing in order to get the light level as a single int from the three raw bytes. The two curves (from the two resistor values) are now merged into one. Modified: daemon/trunk/libs/USBDaemon_command_tux.c =================================================================== --- daemon/trunk/libs/USBDaemon_command_tux.c 2007-09-18 08:22:50 UTC (rev 525) +++ daemon/trunk/libs/USBDaemon_command_tux.c 2007-09-18 09:54:28 UTC (rev 526) @@ -608,9 +608,8 @@ result[1] = sensors1.bits.PB7; break; case DATA_STATUS_LIGHT_LEVEL: - result[1] = sensors2.level_light_high.Byte; - result[2] = sensors2.level_light_low.Byte; - result[3] = sensors2.light_mode.Byte; + result[1] = sensors2.light_level / 256; + result[2] = sensors2.light_level % 256; break; case DATA_STATUS_EYES_POSITION_COUNTER: result[1] = position1.eyes_position.Byte; Modified: daemon/trunk/libs/USBDaemon_status_table.c =================================================================== --- daemon/trunk/libs/USBDaemon_status_table.c 2007-09-18 08:22:50 UTC (rev 525) +++ daemon/trunk/libs/USBDaemon_status_table.c 2007-09-18 09:54:28 UTC (rev 526) @@ -211,8 +211,7 @@ sensors1.Byte = new_value; } -static void sensors2_changed(unsigned char new_value_high, unsigned char new_value_low, - unsigned char new_light_mode) +static void sensors2_changed(int light_level) { tcp_frame_t tcp_frame; @@ -225,12 +224,10 @@ tcp_frame[4] = DATA_STATUS_LIGHT_LEVEL; - sensors2.level_light_high.Byte = new_value_high; - sensors2.level_light_low.Byte = new_value_low; - sensors2.light_mode.Byte = new_light_mode; - - tcp_frame[5] = new_value_high; - tcp_frame[6] = new_value_low; + sensors2.light_level = light_level; + + tcp_frame[5] = light_level / 256; + tcp_frame[6] = light_level % 256; } static void pong_event(unsigned char pong_number, unsigned char pong_received) @@ -552,9 +549,18 @@ break; case STATUS_LIGHT_CMD: - if (sensors2.level_light_high.Byte != new_status[1] - || sensors2.level_light_low.Byte != new_status[2]) - sensors2_changed(new_status[1], new_status[2], new_status[3]); + { + int light_level; + light_level = (new_status[1] << 8) + new_status[2]; + if (new_status[3] == 0) + light_level = light_level / 8 + 1000; + /* 1128 is the maximum value when there is no light + * We substract here to represent the lightness instead of darkness + */ + light_level = 1128 - light_level; + if (light_level != sensors2.light_level) + sensors2_changed(light_level); + } break; case STATUS_POSITION1_CMD: Modified: daemon/trunk/libs/USBDaemon_status_table.h =================================================================== --- daemon/trunk/libs/USBDaemon_status_table.h 2007-09-18 08:22:50 UTC (rev 525) +++ daemon/trunk/libs/USBDaemon_status_table.h 2007-09-18 09:54:28 UTC (rev 526) @@ -238,6 +238,7 @@ _PORT_BYTE_ level_light_high; _PORT_BYTE_ level_light_low; _PORT_BYTE_ light_mode; + int light_level; } sensors2; struct { |