[tuxdroid-svn] r580 - in software/gadgets/light_monitor/trunk: . Light_monitor Light_monitor/Script
Status: Beta
Brought to you by:
ks156
From: Paul_R <c2m...@c2...> - 2007-10-04 15:08:56
|
Author: Paul_R Date: 2007-10-04 17:08:19 +0200 (Thu, 04 Oct 2007) New Revision: 580 Modified: software/gadgets/light_monitor/trunk/Light_monitor.tgf software/gadgets/light_monitor/trunk/Light_monitor/Scripts/Python/GUI/widget/other.glade software/gadgets/light_monitor/trunk/Light_monitor/Scripts/Python/GUI/widget/other.pyp software/gadgets/light_monitor/trunk/Light_monitor/Scripts/Python/init.pyp software/gadgets/light_monitor/trunk/Light_monitor/Scripts/Python/lightGraph_class.py software/gadgets/light_monitor/trunk/Light_monitor/Scripts/Python/notify.pyp software/gadgets/light_monitor/trunk/Light_monitor/Strings/fr_ALL.xml software/gadgets/light_monitor/trunk/Light_monitor/settings.xml software/gadgets/light_monitor/trunk/Light_monitor/strings.xml Log: * Fix a bug which freeze the gadget. * Add buttons to search light and dark Modified: software/gadgets/light_monitor/trunk/Light_monitor/Scripts/Python/GUI/widget/other.glade =================================================================== --- software/gadgets/light_monitor/trunk/Light_monitor/Scripts/Python/GUI/widget/other.glade 2007-10-03 11:19:59 UTC (rev 579) +++ software/gadgets/light_monitor/trunk/Light_monitor/Scripts/Python/GUI/widget/other.glade 2007-10-04 15:08:19 UTC (rev 580) @@ -49,7 +49,7 @@ <widget class="GtkExpander" id="expander1"> <property name="visible">True</property> <property name="can_focus">True</property> - <property name="expanded">True</property> + <property name="expanded">False</property> <property name="spacing">0</property> <child> @@ -452,6 +452,26 @@ <property name="y">48</property> </packing> </child> + + <child> + <widget class="GtkCheckButton" id="chkChangeNotified"> + <property name="width_request">168</property> + <property name="height_request">24</property> + <property name="visible">True</property> + <property name="can_focus">True</property> + <property name="label" translatable="yes">checkbutton1</property> + <property name="use_underline">True</property> + <property name="relief">GTK_RELIEF_NORMAL</property> + <property name="focus_on_click">True</property> + <property name="active">False</property> + <property name="inconsistent">False</property> + <property name="draw_indicator">True</property> + </widget> + <packing> + <property name="x">328</property> + <property name="y">24</property> + </packing> + </child> </widget> </child> </widget> @@ -516,7 +536,7 @@ <widget class="GtkExpander" id="expander2"> <property name="visible">True</property> <property name="can_focus">True</property> - <property name="expanded">True</property> + <property name="expanded">False</property> <property name="spacing">0</property> <child> @@ -698,6 +718,26 @@ </child> <child> + <widget class="GtkCheckButton" id="chk_ThresholdBehavior"> + <property name="width_request">168</property> + <property name="height_request">24</property> + <property name="visible">True</property> + <property name="can_focus">True</property> + <property name="label" translatable="yes">checkbutton2</property> + <property name="use_underline">True</property> + <property name="relief">GTK_RELIEF_NORMAL</property> + <property name="focus_on_click">True</property> + <property name="active">False</property> + <property name="inconsistent">False</property> + <property name="draw_indicator">True</property> + </widget> + <packing> + <property name="x">328</property> + <property name="y">40</property> + </packing> + </child> + + <child> <widget class="GtkFileChooserButton" id="threshold_behavior_path"> <property name="width_request">168</property> <property name="height_request">32</property> @@ -717,7 +757,7 @@ </child> <child> - <widget class="GtkCheckButton" id="chk_ThresholdBehavior"> + <widget class="GtkCheckButton" id="chkThresholdNotified"> <property name="width_request">168</property> <property name="height_request">24</property> <property name="visible">True</property> @@ -732,7 +772,7 @@ </widget> <packing> <property name="x">328</property> - <property name="y">40</property> + <property name="y">16</property> </packing> </child> </widget> @@ -796,9 +836,136 @@ </child> <child> + <widget class="GtkExpander" id="expander3"> + <property name="visible">True</property> + <property name="can_focus">True</property> + <property name="expanded">True</property> + <property name="spacing">0</property> + + <child> + <widget class="GtkFrame" id="frame4"> + <property name="border_width">5</property> + <property name="visible">True</property> + <property name="label_xalign">0</property> + <property name="label_yalign">0.5</property> + <property name="shadow_type">GTK_SHADOW_IN</property> + + <child> + <widget class="GtkAlignment" id="alignment5"> + <property name="visible">True</property> + <property name="xalign">0.5</property> + <property name="yalign">0.5</property> + <property name="xscale">1</property> + <property name="yscale">1</property> + <property name="top_padding">0</property> + <property name="bottom_padding">0</property> + <property name="left_padding">12</property> + <property name="right_padding">0</property> + + <child> + <widget class="GtkFixed" id="fixed5"> + <property name="height_request">34</property> + <property name="visible">True</property> + + <child> + <widget class="GtkButton" id="lblBtnDark"> + <property name="width_request">130</property> + <property name="height_request">29</property> + <property name="visible">True</property> + <property name="can_focus">True</property> + <property name="label" translatable="yes"></property> + <property name="use_underline">True</property> + <property name="relief">GTK_RELIEF_NORMAL</property> + <property name="focus_on_click">True</property> + <signal name="clicked" handler="on_btnDark_clicked" last_modification_time="Wed, 03 Oct 2007 09:23:25 GMT"/> + </widget> + <packing> + <property name="x">208</property> + <property name="y">0</property> + </packing> + </child> + + <child> + <widget class="GtkButton" id="lblBtnLight"> + <property name="width_request">130</property> + <property name="height_request">30</property> + <property name="visible">True</property> + <property name="can_focus">True</property> + <property name="label" translatable="yes"></property> + <property name="use_underline">True</property> + <property name="relief">GTK_RELIEF_NORMAL</property> + <property name="focus_on_click">True</property> + <signal name="clicked" handler="on_btnLight_clicked" last_modification_time="Wed, 03 Oct 2007 09:23:19 GMT"/> + </widget> + <packing> + <property name="x">48</property> + <property name="y">0</property> + </packing> + </child> + </widget> + </child> + </widget> + </child> + + <child> + <widget class="GtkLabel" id="label13"> + <property name="visible">True</property> + <property name="label" translatable="yes"></property> + <property name="use_underline">False</property> + <property name="use_markup">True</property> + <property name="justify">GTK_JUSTIFY_LEFT</property> + <property name="wrap">False</property> + <property name="selectable">False</property> + <property name="xalign">0.5</property> + <property name="yalign">0.5</property> + <property name="xpad">0</property> + <property name="ypad">0</property> + <property name="ellipsize">PANGO_ELLIPSIZE_NONE</property> + <property name="width_chars">-1</property> + <property name="single_line_mode">False</property> + <property name="angle">0</property> + </widget> + <packing> + <property name="type">label_item</property> + </packing> + </child> + </widget> + </child> + + <child> + <widget class="GtkLabel" id="lblTest"> + <property name="visible">True</property> + <property name="label" translatable="yes">Test</property> + <property name="use_underline">False</property> + <property name="use_markup">False</property> + <property name="justify">GTK_JUSTIFY_LEFT</property> + <property name="wrap">False</property> + <property name="selectable">False</property> + <property name="xalign">0.5</property> + <property name="yalign">0.5</property> + <property name="xpad">0</property> + <property name="ypad">0</property> + <property name="ellipsize">PANGO_ELLIPSIZE_NONE</property> + <property name="width_chars">-1</property> + <property name="single_line_mode">False</property> + <property name="angle">0</property> + </widget> + <packing> + <property name="type">label_item</property> + </packing> + </child> + </widget> + <packing> + <property name="padding">0</property> + <property name="expand">True</property> + <property name="fill">True</property> + </packing> + </child> + + <child> <widget class="GtkFrame" id="frame3"> <property name="border_width">5</property> - <property name="height_request">89</property> + <property name="height_request">136</property> <property name="visible">True</property> <property name="label_xalign">0</property> <property name="label_yalign">0.5</property> @@ -856,16 +1023,16 @@ </widget> <packing> <property name="x">168</property> - <property name="y">32</property> + <property name="y">40</property> </packing> </child> <child> - <widget class="GtkLabel" id="lblSample"> - <property name="width_request">240</property> + <widget class="GtkLabel" id="lblRate"> + <property name="width_request">224</property> <property name="height_request">24</property> <property name="visible">True</property> - <property name="label" translatable="yes">Sample :</property> + <property name="label" translatable="yes">Rate :</property> <property name="use_underline">False</property> <property name="use_markup">False</property> <property name="justify">GTK_JUSTIFY_LEFT</property> @@ -882,14 +1049,14 @@ </widget> <packing> <property name="x">0</property> - <property name="y">32</property> + <property name="y">8</property> </packing> </child> <child> <widget class="GtkButton" id="btnApply"> <property name="width_request">144</property> - <property name="height_request">40</property> + <property name="height_request">30</property> <property name="visible">True</property> <property name="can_focus">True</property> <property name="relief">GTK_RELIEF_NORMAL</property> @@ -961,17 +1128,17 @@ </child> </widget> <packing> - <property name="x">424</property> - <property name="y">16</property> + <property name="x">0</property> + <property name="y">72</property> </packing> </child> <child> - <widget class="GtkLabel" id="lblRate"> - <property name="width_request">224</property> + <widget class="GtkLabel" id="lblSample"> + <property name="width_request">240</property> <property name="height_request">24</property> <property name="visible">True</property> - <property name="label" translatable="yes">Rate :</property> + <property name="label" translatable="yes">Sample :</property> <property name="use_underline">False</property> <property name="use_markup">False</property> <property name="justify">GTK_JUSTIFY_LEFT</property> @@ -988,9 +1155,48 @@ </widget> <packing> <property name="x">0</property> - <property name="y">8</property> + <property name="y">40</property> </packing> </child> + + <child> + <widget class="GtkComboBox" id="cbbConfig"> + <property name="width_request">150</property> + <property name="height_request">30</property> + <property name="visible">True</property> + <property name="items" translatable="yes">1 +2 +3 +4 +5 +6 +7</property> + <property name="add_tearoffs">False</property> + <property name="focus_on_click">True</property> + </widget> + <packing> + <property name="x">320</property> + <property name="y">0</property> + </packing> + </child> + + <child> + <widget class="GtkButton" id="btnSet"> + <property name="width_request">149</property> + <property name="height_request">30</property> + <property name="visible">True</property> + <property name="can_focus">True</property> + <property name="label" translatable="yes">button1</property> + <property name="use_underline">True</property> + <property name="relief">GTK_RELIEF_NORMAL</property> + <property name="focus_on_click">True</property> + <signal name="pressed" handler="on_btnSet_pressed" last_modification_time="Thu, 04 Oct 2007 14:52:44 GMT"/> + </widget> + <packing> + <property name="x">320</property> + <property name="y">40</property> + </packing> + </child> </widget> </child> </widget> Modified: software/gadgets/light_monitor/trunk/Light_monitor/Scripts/Python/GUI/widget/other.pyp =================================================================== --- software/gadgets/light_monitor/trunk/Light_monitor/Scripts/Python/GUI/widget/other.pyp 2007-10-03 11:19:59 UTC (rev 579) +++ software/gadgets/light_monitor/trunk/Light_monitor/Scripts/Python/GUI/widget/other.pyp 2007-10-04 15:08:19 UTC (rev 580) @@ -45,7 +45,6 @@ self.get_widget("window1").set_title(_me.string('name_to_read')) #Set the labels - print 'tick' self.get_widget("radBoth").set_label(_me.string('widget_lblBoth')) self.get_widget("lblBtnApply").set_text(_me.string('widget_lblBtnApply')) self.get_widget("lblChange").set_text(_me.string('widget_lblChange')) @@ -63,9 +62,24 @@ self.get_widget("chkThreshold").set_label(_me.string('widget_lblDisplayThreshold')) self.get_widget('chk_ThresholdBehavior').set_label(_me.string('widget_lblBehavior')) self.get_widget('chk_ChangeBehavior').set_label(_me.string('widget_lblBehavior')) + self.get_widget('chkChangeNotified').set_label(_me.string('widget_lblNotified')) + self.get_widget('chkThresholdNotified').set_label(_me.string('widget_lblNotified')) self.get_widget("lblRate").set_text(_me.string('gui_conf_rate_lb')) self.get_widget("lblSample").set_text(_me.string('gui_conf_sample_lb')) - + self.get_widget("lblBtnDark").set_label(_me.string('widget_lblDark')) + self.get_widget("lblBtnLight").set_label(_me.string('widget_lblLight')) + self.get_widget("btnSet").set_label(_me.string('widget_lblSet')) + + for i in range (7): + self.get_widget('cbbConfig').remove_text(0) + self.get_widget('cbbConfig').append_text(_me.string('conf_lblDrop')) + self.get_widget('cbbConfig').append_text(_me.string('conf_lblRaise')) + self.get_widget('cbbConfig').append_text(_me.string('conf_lblChangeD')) + self.get_widget('cbbConfig').append_text(_me.string('conf_lblChangeU')) + self.get_widget('cbbConfig').append_text(_me.string('conf_lblIncrease')) + self.get_widget('cbbConfig').append_text(_me.string('conf_lblDecrease')) + self.get_widget('cbbConfig').append_text(_me.string('conf_lblBoth')) + self.get_widget('cbbConfig').set_active(0) thread.start_new_thread(self.update, ()) ########################################################### @@ -85,7 +99,6 @@ #Drop _me.set_param('drop', self.light_measure.val_drop) self.get_widget("valDrop_percent").set_text(str(_me.get_param('drop'))) - print self.light_measure.val_drop_time _me.set_param('drop_time', self.light_measure.val_drop_time) self.get_widget("valDrop_time").set_text(str(_me.get_param('drop_time'))) @@ -111,8 +124,8 @@ _me.set_param('threshold', self.light_measure.val_threshold) self.get_widget("valThreshold").set_text(str(_me.get_param('threshold'))) + self.light_measure.change_control() - #update the radio button status self.light_measure.drop = _me.get_param('drop_rad') self.light_measure.raising = _me.get_param('raise_rad') @@ -125,11 +138,12 @@ self.light_measure.changetext = _me.string('conf_lblChange') self.light_measure.thresholdtext = _me.string('conf_lblThreshold') # '' the check boxes + self.light_measure.change_notified = _me.get_param('change_notified') + self.light_measure.threshold_notified = _me.get_param('threshold_notified') self.light_measure.threshold_chk = _me.get_param('threshold_chk') - print _me.get_param('chk_ThresholdBehavior') self.light_measure.threshold_behavior_chk = _me.get_param('chk_ThresholdBehavior') self.light_measure.change_behavior_chk = _me.get_param('chk_ChangeBehavior') - self.light_measure.change_control() + @@ -142,7 +156,13 @@ def on_window1_destroy(self, widget, *args): _me.get_param('measure').GUI_on = False self.light_measure.GUI_on = False + + + def on_btnSet_clicked(self, widget, *args): + pass + + def on_btnApply_clicked(self, widget, *args): #Store the new radio buttons status _me.set_param('drop_rad', self.get_widget('radDrop').get_active()) @@ -154,8 +174,9 @@ _me.set_param('both_rad', self.get_widget('radBoth').get_active()) _me.set_param('threshold_chk', self.get_widget('chkThreshold').get_active()) _me.set_param('chk_ThresholdBehavior', self.get_widget('chk_ThresholdBehavior').get_active()) + _me.set_param('threshold_notified', self.get_widget('chkThresholdNotified').get_active()) + _me.set_param('change_notified', self.get_widget('chkChangeNotified').get_active()) _me.set_param('chk_ChangeBehavior', self.get_widget('chk_ChangeBehavior').get_active()) - print _me.get_param('chk_ChangeBehavior') temp_rate = self.check_float_value(self.get_widget('txtRate').get_text(), 0.1, 36000) temp_sample = self.check_float_value(self.get_widget('txtSample').get_text(), 1, 100000) @@ -168,7 +189,7 @@ max_time = self.light_measure.rate * self.light_measure.sample - + self.light_measure.val_drop = self.check_float_value(self.get_widget('valDrop_percent').get_text(), 1, 100) self.light_measure.val_drop_time = self.check_float_value(self.get_widget('valDrop_time').get_text(), self.light_measure.rate, max_time) self.light_measure.val_raise = self.check_float_value(self.get_widget('valRaise_percent').get_text(), 1, 100) @@ -178,22 +199,41 @@ self.light_measure.val_changeU = self.check_float_value(self.get_widget('valChangeU_percent').get_text(), 1, 100) self.light_measure.val_changeU_time = self.check_float_value(self.get_widget('valChangeU_time').get_text(), self.light_measure.rate, max_time) self.light_measure.val_threshold = self.check_float_value(self.get_widget('valThreshold').get_text(), 0, 100) - print self.light_measure.val_changeD_time - + #Update values self.update_value() def on_threshold_selection_changed(self, widget, *args): filename = widget.get_filename() + filename = filename.replace('%20', ' ') _me.set_param('behavior_file_threshold', filename) _me.get_param('measure').threshold_behavior = _me.get_param('behavior_file_threshold') def on_change_selection_changed(self, widget, *args): filename = widget.get_filename() + filename = filename.replace('%20', ' ') _me.set_param('behavior_file_change', filename) _me.get_param('measure').change_behavior = _me.get_param('behavior_file_change') + + def on_btnLight_clicked(self, widget, *args): + self.light_measure.val_table = [0] * int(self.light_measure.sample+1) + self.light_measure.light_search = True + self.light_measure.light_value = 3000 + self.config_light_search() - + def on_btnDark_clicked(self, widget, *args): + self.light_measure.val_table = [1124] * int(self.light_measure.sample+1) + self.light_measure.light_search = False + self.light_measure.light_value = 0 + self.config_light_search() + + def config_light_search(self): + self.light_measure.search_light_flag = True + self.light_measure.light_search_state = 0 + self.light_measure.tick = 2 + self.light_measure.ok_flag = False + self.light_measure.timer = 0 + tux.cmd.spinl_on_free(4, 1) ########################################################### # # Value integrity control @@ -203,14 +243,11 @@ try: value = float(value) except: - print '0' value = float(minimum) if value < float(minimum): - print '1' value = float(minimum) elif value > float(maximum): - print '2' value = float(maximum) return value Modified: software/gadgets/light_monitor/trunk/Light_monitor/Scripts/Python/init.pyp =================================================================== --- software/gadgets/light_monitor/trunk/Light_monitor/Scripts/Python/init.pyp 2007-10-03 11:19:59 UTC (rev 579) +++ software/gadgets/light_monitor/trunk/Light_monitor/Scripts/Python/init.pyp 2007-10-04 15:08:19 UTC (rev 580) @@ -44,5 +44,15 @@ measure.change_behavior = _me.get_param('behavior_file_change') measure.event_tab = _me.get_param('config') -tux.monitoring.insert(0x1B, measure.on_light_level) +monitor_id = tux.monitoring.insert(0x1B, measure.on_light_level) +_me.set_param('monitor_id', monitor_id) +def destroy(): + print ' Remove' + tux.monitoring.remove(_me.get_param('monitor_id')) + +_me.insert_funct('destroy', destroy) + + + + Modified: software/gadgets/light_monitor/trunk/Light_monitor/Scripts/Python/lightGraph_class.py =================================================================== --- software/gadgets/light_monitor/trunk/Light_monitor/Scripts/Python/lightGraph_class.py 2007-10-03 11:19:59 UTC (rev 579) +++ software/gadgets/light_monitor/trunk/Light_monitor/Scripts/Python/lightGraph_class.py 2007-10-04 15:08:19 UTC (rev 580) @@ -2,6 +2,8 @@ import sys import time import os +import threading +import thread sys.path.append('/opt/tuxdroid/api/python') from tux import * @@ -130,8 +132,16 @@ self.timeout = 0 self.start_flag = True self.wait = 0 + self.temp = 1124 + self.ok_flag = False + self.light_search = True + self.search_light_flag = False + self.search_dark_flag = False + self.__on_light_mutex = threading.Lock() + self.__timeout_mutex = threading.Lock() + ########################################################### # # Events control @@ -140,44 +150,59 @@ def event_control(self): if self.GUI_on == False: for i in range (len(self.event_tab)): - print 'Goto threshold control' + print 'goto threshold control' self.Threshold_control(i) - print 'Goto change control' + print 'goto change control' self.Change_control(i) #Gadget or test notifications else: - print 'Goto test functions' - self.test_func() - #disable gadget notifications - self.notify = False - - #goto test notification every sec. - if self.wait == 0: - self.wait = 10 - self.test_notification() + print 'GUI on' + if self.search_light_flag: + print 'search light' + self.search_light(self.light_search) else: - self.wait -= 1 + print 'goto test function' + self.test_func() + #disable gadget notifications + self.notify = False + #goto test notification every sec. + if self.wait == 0: + self.wait = 10 + print 'goto notifications' + self.test_notification() + else: + self.wait -= 1 + # To prevent notifications at startup if self.start_flag == True: + print 'start flag' self.change_event = False self.threshold_event = False self.start_flag = False for i in range (len(self.event_tab)): - self.event_tab[i][7] = False + self.event_tab[i][7] = False + + def change_control(self): # Determine how many point must be checked for changes events + print 'Enter change control' pts_per_sec = self.sample / (self.rate * self.sample) - self.timeout = 0 + if self.val_drop_time >= 0.1 and self.val_drop > 0: - self.val_drop_time = int(self.val_drop_time * pts_per_sec) + self.drop_point = int(self.val_drop_time * pts_per_sec) + self.set_timeout(self.drop_point) if self.val_raise_time >= 0.1 and self.val_raise > 0: - self.val_raise_time = int(self.val_raise_time * pts_per_sec) + self.raise_point = int(self.val_raise_time * pts_per_sec) + self.set_timeout(self.raise_point) if self.val_changeD_time >= 0.1 and self.val_changeD > 0: - self.val_changeD_time = int(self.val_changeD_time * pts_per_sec) + self.changeD_point = int(self.val_changeD_time * pts_per_sec) + self.set_timeout(self.changeD_point) if self.val_changeU_time >= 0.1 and self.val_changeU > 0: - self.val_changeU_time = int(self.val_changeU_time * pts_per_sec) + self.changeU_point = int(self.val_changeU_time * pts_per_sec) + self.set_timeout(self.changeU_point) + print 'exiting change control' ########################################################### @@ -187,47 +212,47 @@ ########################################################### def Threshold_control(self, index): if self.event_tab[index][1] == 1: - print 'Threshold found' if self.event_tab[index][7] != True: - print 'No event detected' if self.event_tab[index][2] == 0: - print 'Increase' + print 'increase detected' #Increasing threshold control if self.Increase_control(self.event_tab[index][3]) == True: - print 'Increase detected' self.event_tab[index][7] = True elif self.event_tab[index][2] == 1: - print 'Decrease' + print 'decrease detected' #Decreasing threshold control if self.Decrease_control(self.event_tab[index][3]) == True: - print 'Decrease detected' self.event_tab[index][7] = True elif self.event_tab[index][2] == 2: - print 'Both direction' + print 'both detected' #Both direction theshold control if self.Both_control(self.event_tab[index][3]) == True: - print 'Both detected' self.event_tab[index][7] = True - print 'Threshold control done ...' def Increase_control(self, value): + print 'enter increase control' val_act = (self.val_table[len(self.val_table)-1]*100) / 1124.0 val_prev = (self.val_table[len(self.val_table)-2]*100) / 1124.0 if val_prev <= value and val_act > value: return True + print 'leave increase control' def Decrease_control(self, val): + print 'enter decrease control' val_act = (self.val_table[len(self.val_table)-1]*100) / 1124.0 val_prev = (self.val_table[len(self.val_table)-2]*100) / 1124.0 if val_prev >= val and val_act < val: return True + print 'leave decrease control' def Both_control(self, val): + print 'enter both control' val_act = (self.val_table[int(len(self.val_table)-1)]*100) / 1124.0 val_prev = (self.val_table[int(len(self.val_table)-2)]*100) / 1124.0 if val_prev <= val and val_act > val or val_prev >= val and val_act < val: return True + print 'leave both control' ########################################################### @@ -238,76 +263,96 @@ def Change_control(self, i): #Changements control if self.event_tab[i][1] == 0: - print 'Change found' + print 'change detected' pts_per_sec = self.sample / (self.rate * self.sample) - time = float(self.event_tab[i][4] * pts_per_sec) + time = int(self.event_tab[i][4] * pts_per_sec) if self.event_tab[i][7] != True: - print 'no event detected' # Drop change part : if self.event_tab[i][2] == 0: - print 'Drop' + print 'drop detected' if self.Drop_control(time, self.event_tab[i][3], self.event_tab[i][8], i) == True: - print 'Drop detected' self.event_tab[i][7] = True + print 'dropped' # Raise change part if self.event_tab[i][2] == 1: - print 'Raise' + print 'raise detected' if self.Raise_control(time, self.event_tab[i][3], self.event_tab[i][8], i) == True: - print 'Raise detected' self.event_tab[i][7] = True + print 'raised' # Drop and Raise change if self.event_tab[i][2] == 2: - print 'Drop and raise' + print 'drop and raise detected' if self.ChangeD_control(time, self.event_tab[i][3], self.event_tab[i][8], i) == True: - print 'Drop and raise detected' self.event_tab[i][7] = True + print 'drop and raise event !' # Raise and Drop change if self.event_tab[i][2] == 3: - print 'Raise and drop' + print 'raise and drop detected' if self.ChangeU_control(time, self.event_tab[i][3], self.event_tab[i][8], i) == True: - print 'Raise and drop detected' self.event_tab[i][7] = True - print 'Change control done ...' + print 'raise and drop event !' def Drop_control(self, time, val, timeout, index): + print 'enter drop control' #timeout control : to prevent multiple notifications with the same event if timeout != 0: timeout -= 1 init_val = len(self.val_table) - 1 - int(time) + timeout - maximum = max(self.val_table[init_val:len(self.val_table)-1]) + try: + maximum = max(self.val_table[init_val:len(self.val_table)-1]) + except: + init_val = len(self.val_table) - 1 - int(time) + maximum = max(self.val_table[init_val:len(self.val_table)-1]) + if maximum >= self.val_table[len(self.val_table)-1] + ((val/100)*1124): if self.GUI_on == False: self.event_tab[index][8] = int(time) else: - self.timeout = int(time) + self.set_timeout(int(time)) return True else: if self.GUI_on: - self.timeout = timeout + self.set_timeout(timeout) else: self.event_tab[index][8] = timeout + print 'leave drop control' def Raise_control(self, time, val, timeout, index): + print 'enter raise control' if timeout != 0: timeout -= 1 init_val = len(self.val_table) - 1 - int(time) + timeout + try: + maximum = max(self.val_table[init_val:len(self.val_table)-1]) + except: + init_val = len(self.val_table) - 1 - int(time) + maximum = max(self.val_table[init_val:len(self.val_table)-1]) + minimum = min(self.val_table[init_val:(len(self.val_table)-1)]) if minimum <= self.val_table[len(self.val_table)-1] - ((val/100)*1124): if self.GUI_on == False: self.event_tab[index][8] = int(time) else: - self.timeout = int(time) + self.set_timeout(int(time)) return True else: if self.GUI_on: - self.timeout = timeout + self.set_timeout(timeout) else: self.event_tab[index][8] = timeout + print 'leave raise control' def ChangeD_control(self, time, val, timeout, index): + print 'enter drop and raise control' if timeout != 0: timeout -= 1 init_val = len(self.val_table) - 1 - int(time) + timeout + try: + maximum = max(self.val_table[init_val:len(self.val_table)-1]) + except: + init_val = len(self.val_table) - 1 - int(time) + maximum = max(self.val_table[init_val:len(self.val_table)-1]) + for i in range(int(time - timeout)): if self.val_table[int(len(self.val_table)-1-i)] <= self.val_table[len(self.val_table) - 1] - ((val/100)*1124): maximum = max(self.val_table[init_val:len(self.val_table) - i]) @@ -315,18 +360,27 @@ if self.GUI_on == False: self.event_tab[index][8] = int(time) else: - self.timeout = int(time) + self.set_timeout(int(time)) return True if self.GUI_on: - self.timeout = timeout + self.set_timeout(timeout) else: self.event_tab[index][8] = timeout + print 'leave drop and raise control' return False + def ChangeU_control(self, time, val, timeout, index): + print 'enter raise and drop control' if timeout != 0: timeout -= 1 init_val = len(self.val_table) - 1 - int(time) + timeout + try: + maximum = max(self.val_table[init_val:len(self.val_table)-1]) + except: + init_val = len(self.val_table) - 1 - int(time) + maximum = max(self.val_table[init_val:len(self.val_table)-1]) + for i in range(int(time - timeout)): if self.val_table[int(len(self.val_table)-1-i)] >= self.val_table[len(self.val_table) - 1] + ((val/100)*1124): minimum = min(self.val_table[init_val:len(self.val_table)-i]) @@ -334,13 +388,15 @@ if self.GUI_on == False: self.event_tab[index][8] = int(time) else: - self.timeout = int(time) + self.set_timeout(int(time)) return True if self.GUI_on: - self.timeout = timeout + self.set_timeout(timeout) else: self.event_tab[index][8] = timeout + print 'leave raise and drop control' return False + ########################################################### # @@ -349,96 +405,176 @@ ########################################################### def test_func(self): if self.threshold_event != True: - print 'Threshold event found' + print 'test threshold control' #Decrease threshold control if self.decrease: - print 'Goto decrease control' + print 'test decrease' if self.Decrease_control(self.val_threshold) == True: self.threshold_event = True - print 'done ...' + print 'test decrease event' #Increasing threshold control if self.increase: - print 'Goto Increase control' + print 'test increase' if self.Increase_control(self.val_threshold) == True: self.threshold_event = True - print 'done ...' + print 'test increase event' #Both direction theshold control if self.both: - print 'Goto Both control' + print 'test both' if self.Both_control(self.val_threshold) == True: self.threshold_event = True - print 'done ...' + print 'test both event' #Changements control if self.change_event != True: - print 'Change event found' + timeout = self.get_timeout() + print 'test change control' # Drop change part : if self.drop == True and self.val_drop_time > 0.0: - print 'Goto drop control' - if self.Drop_control(self.val_drop_time, self.val_drop, self.timeout, 0) == True: + print 'test drop detected' + if self.Drop_control(self.drop_point, self.val_drop, timeout, 0) == True: self.change_event = True - print 'done ...' + print 'test drop event' # Raise change part if self.raising == True and self.val_raise_time > 0.0: - print 'Goto raise control' - if self.Raise_control(self.val_raise_time, self.val_raise, self.timeout, 0) == True: + print 'test raise detected' + if self.Raise_control(self.raise_point, self.val_raise, timeout, 0) == True: self.change_event = True - print 'done ...' + print 'test raise event' # Drop and Raise change if self.changeD == True and self.val_changeD_time > 0.0: - print 'Goto drop and raise control' - if self.ChangeD_control(self.val_changeD_time, self.val_changeD, self.timeout, 0) == True: + print 'test drop and raise detected' + if self.ChangeD_control(self.changeD_point, self.val_changeD, timeout, 0) == True: self.change_event = True - print 'done ...' + print 'test drop and raise event' # Raise and Drop change if self.changeU == True and self.val_changeU_time > 0.0: - print 'Goto raise and drop control' - if self.ChangeU_control(self.val_changeU_time, self.val_changeU, self.timeout, 0) == True: + print 'test raise and drop detected' + if self.ChangeU_control(self.changeU_point, self.val_changeU, timeout, 0) == True: self.change_event = True - print 'Done' + print 'test raise and drop event' def test_notification(self): + print 'enter test notifications' if self.threshold_event == True: - print 'Theshold event occur' - if self.threshold_behavior_chk and os.path.isfile(self.threshold_behavior) and os.path.exists(self.threshold_behavior) : - print 'Execute behavior script' - self.threshold_event = False - tux.sys.shell_free(self.threshold_behavior) + if self.threshold_notified: + path = self.change_behavior + path = "'%s'" % path + if self.threshold_behavior_chk and os.path.isfile(self.threshold_behavior) and os.path.exists(self.threshold_behavior): + print 'threshold behavior script' + self.threshold_event = False + tux.sys.shell_free(path) + else: + print 'threshold default behavior' + self.threshold_event = False + thread.start_new_thread(self.test_default_behavior, (self.thresholdtext,)) else: - print 'execute deflaut behavior' self.threshold_event = False - tux.cmd.mouth_open() - tux.tts.speak(self.thresholdtext) - tux.cmd.mouth_close() - + elif self.change_event == True: - print 'Change event occur' - if self.change_behavior_chk and os.path.isfile(self.change_behavior) and os.path.exists(self.change_behavior): - print 'Execute behavior script' - self.change_event = False - tux.sys.shell_free(self.change_behavior) + if self.change_notified: + path = self.change_behavior + path = "'%s'" % path + if self.change_behavior_chk and os.path.isfile(self.change_behavior) and os.path.exists(self.change_behavior): + print 'change behavior script' + self.change_event = False + tux.sys.shell_free(path) + else: + print 'change default behavior' + self.change_event = False + thread.start_new_thread(self.test_default_behavior, (self.changetext,)) else: - print 'Default behavior' self.change_event = False - tux.cmd.mouth_open() - tux.tts.speak(self.changetext) - tux.cmd.mouth_close() - print 'End of test notifications' + + def test_default_behavior(self, txt): + tux.cmd.mouth_open() + tux.tts.speak(txt) + tux.cmd.mouth_close() ########################################################### # # Acquire # ########################################################### def on_light_level(self, args): - self.tick -= 1 - if self.tick == 0: - val = (args[0] * 256) + args[1] - self.val_table.append(val) - self.val_table.pop(0) - if self.GUI_on: - self.light_graph_measure.refresh() - self.tick = int(self.rate * 10) - self.event_control() + try: + self.__on_light_mutex.acquire() + self.tick -= 1 + if self.tick == 0: + val = (args[0] * 256) + args[1] + self.val_table.append(val) + self.val_table.pop(0) + if self.GUI_on: + self.light_graph_measure.refresh() + self.tick = int(self.rate * 10) + self.event_control() + self.__on_light_mutex.release() + except: + print sys.exc_info() + sys.exit() + + ########################################################### + # + # Timeout management + # + ########################################################### + def set_timeout(self, val): + self.__timeout_mutex.acquire() + self.timeout = val + self.__timeout_mutex.release() + def get_timeout(self): + self.__timeout_mutex.acquire() + val = self.timeout + self.__timeout_mutex.release() + return val + + ########################################################### + # + # Search functions + # + ########################################################### + def search_light(self, light): + detect = False + if self.light_search_state == 0 and tux.status.spin_counter() == 0: + self.light_search_state = 1 + if light == True: + self.light_value = max(self.val_table) + self.light_value -= 50 + else: + self.light_value = min(self.val_table) + self.light_value += 50 + self.timer = 10 + elif self.light_search_state == 1: + self.timer_control() + + if light: + if self.val_table[len(self.val_table)-1] >= (self.light_value): + thread.start_new_thread(tux.cmd.spinl_off, ()) + detect = True + else: + if self.val_table[len(self.val_table)-1] <= (self.light_value): + thread.start_new_thread(tux.cmd.spinl_off, ()) + detect = True + + if detect: + self.search_light_flag = False + self.light_search_state = 0 + self.threshold_event = False + self.change_event = False + self.change_control() + + + def timer_control(self): + self.timer -= 1 + if self.timer > 2: + return True + + elif self.timer == 2: + tux.cmd.spinl_on_free(1, 1) + + elif self.timer == 0: + thread.start_new_thread(tux.cmd.spinl_off, ()) + self.timer = 7 + Modified: software/gadgets/light_monitor/trunk/Light_monitor/Scripts/Python/notify.pyp =================================================================== --- software/gadgets/light_monitor/trunk/Light_monitor/Scripts/Python/notify.pyp 2007-10-03 11:19:59 UTC (rev 579) +++ software/gadgets/light_monitor/trunk/Light_monitor/Scripts/Python/notify.pyp 2007-10-04 15:08:19 UTC (rev 580) @@ -39,10 +39,13 @@ if event[i][7]: print 'first notification step' if event[i][5]: + path = event[i][6] + path = path.replace('%20', ' ') print 'notification enable' - if os.path.isfile(event[i][6]) and os.path.exists(event[i][6]): + if os.path.isfile(path) and os.path.exists(path): print 'script found and valid' - tux.sys.shell_free(event[i][6]) + path = "'%s'" % path + tux.sys.shell_free(path) event[i][7] = False else: print 'default behavior' Modified: software/gadgets/light_monitor/trunk/Light_monitor/Strings/fr_ALL.xml =================================================================== --- software/gadgets/light_monitor/trunk/Light_monitor/Strings/fr_ALL.xml 2007-10-03 11:19:59 UTC (rev 579) +++ software/gadgets/light_monitor/trunk/Light_monitor/Strings/fr_ALL.xml 2007-10-04 15:08:19 UTC (rev 580) @@ -32,6 +32,7 @@ <widget_lblDisplayThreshold type='str'>Afficher le seuil sur le graph.</widget_lblDisplayThreshold> <conf_btnModify type='str'>Modifier</conf_btnModify> <widget_lblEvent type='str'>Evènement</widget_lblEvent> + <widget_lblNotified type='str'>Notifé</widget_lblNotified> <widget_lblIncrease type='str'>Accroissement</widget_lblIncrease> <widget_lblRaise type='str'>Augmentation</widget_lblRaise> <conf_btnAdd type='str'>Ajouter</conf_btnAdd> @@ -46,11 +47,13 @@ <conf_lblBehavior type='str'>Comportement</conf_lblBehavior> <gui_conf_remote_set_bt type='str'>Set</gui_conf_remote_set_bt> <widget_lblChange type='str'>Changement</widget_lblChange> + <widget_lblLight type='str'>Trouver lumière</widget_lblLight> <name_to_read type='str'>Moniteur de lumière</name_to_read> <conf_lblNotNotified type='str'>Non notifié</conf_lblNotNotified> <conf_lblDrop type='str'>Chute</conf_lblDrop> <gui_conf_window_title type='str'>Paramètres</gui_conf_window_title> - <widget_lblThreshold type='str'>Seuil</widget_lblThreshold> + <widget_lblDark type='str'>Trouver ombre</widget_lblDark> + <widget_lblSet type='str'>Ajouter a la config.</widget_lblSet> <conf_lblValue type='str'>Valeur (%)</conf_lblValue> <conf_lblRate type='str'>Taux de rafraichissement</conf_lblRate> <widget_lblBehavior type='str'>Activer le script</widget_lblBehavior> @@ -58,4 +61,5 @@ <conf_lblTime type='str'>Temps (sec.)</conf_lblTime> <conf_lblControl type='str'>Contrôle</conf_lblControl> <conf_lblNotified type='str'>Notifié ?</conf_lblNotified> + <widget_lblThreshold type='str'>Seuil</widget_lblThreshold> </strings> Modified: software/gadgets/light_monitor/trunk/Light_monitor/settings.xml =================================================================== --- software/gadgets/light_monitor/trunk/Light_monitor/settings.xml 2007-10-03 11:19:59 UTC (rev 579) +++ software/gadgets/light_monitor/trunk/Light_monitor/settings.xml 2007-10-04 15:08:19 UTC (rev 580) @@ -1,35 +1,39 @@ <?xml version='1.0' encoding='UTF-8'?> <settings> <parameters> + <change_notified type='bool'>False</change_notified> <chk_ThresholdBehavior type='bool'>False</chk_ThresholdBehavior> <increase_rad type='bool'>True</increase_rad> <chk_ChangeBehavior type='bool'>False</chk_ChangeBehavior> - <changeU_time type='int'>1</changeU_time> + <changeU_time type='float'>1.0</changeU_time> <changeD_rad type='bool'>False</changeD_rad> <threshold type='float'>50.0</threshold> <decrease_rad type='bool'>False</decrease_rad> <behavior_file_threshold type='str'>/home/</behavior_file_threshold> <raise type='float'>10.0</raise> <changeU_rad type='bool'>False</changeU_rad> + <threshold_notified type='bool'>False</threshold_notified> <config type='list'>[]</config> <behavior_file_change type='str'>/home/</behavior_file_change> <drop_rad type='bool'>True</drop_rad> <raise_rad type='bool'>False</raise_rad> <changeD type='float'>10.0</changeD> - <drop_time type='int'>1</drop_time> + <drop_time type='float'>1.0</drop_time> <changeU type='float'>10.0</changeU> - <raise_time type='int'>1</raise_time> + <raise_time type='float'>1.0</raise_time> <drop type='float'>10.0</drop> <Sample type='float'>500.0</Sample> <threshold_chk type='bool'>False</threshold_chk> <Rate type='float'>0.1</Rate> - <changeD_time type='int'>1</changeD_time> + <changeD_time type='float'>1.0</changeD_time> <both_rad type='bool'>False</both_rad> </parameters> <general> <gui_state> <widget> - <visible type='bool'>False</visible> + <y type='int'>73</y> + <visible type='bool'>True</visible> + <x type='int'>10</x> </widget> <conf> <y type='int'>131</y> Modified: software/gadgets/light_monitor/trunk/Light_monitor/strings.xml =================================================================== --- software/gadgets/light_monitor/trunk/Light_monitor/strings.xml 2007-10-03 11:19:59 UTC (rev 579) +++ software/gadgets/light_monitor/trunk/Light_monitor/strings.xml 2007-10-04 15:08:19 UTC (rev 580) @@ -31,6 +31,7 @@ <widget_lblDisplayThreshold type='str'>Display threshold on graph</widget_lblDisplayThreshold> <conf_btnModify type='str'>Modify</conf_btnModify> <widget_lblEvent type='str'>Event</widget_lblEvent> + <widget_lblNotified type='str'>Notified</widget_lblNotified> <widget_lblIncrease type='str'>Increasing</widget_lblIncrease> <widget_lblRaise type='str'>Raise</widget_lblRaise> <conf_btnAdd type='str'>Add</conf_btnAdd> @@ -46,11 +47,13 @@ <conf_lblChangeU type='str'>Raise and drop</conf_lblChangeU> <gui_conf_remote_set_bt type='str'>Set</gui_conf_remote_set_bt> <widget_lblChange type='str'>Change</widget_lblChange> + <widget_lblLight type='str'>Search light</widget_lblLight> <name_to_read type='str'>Light monitor</name_to_read> <conf_lblNotNotified type='str'>Not notified</conf_lblNotNotified> <conf_lblDrop type='str'>Drop</conf_lblDrop> <gui_conf_window_title type='str'>Parameters</gui_conf_window_title> - <widget_lblThreshold type='str'>Threshold</widget_lblThreshold> + <widget_lblDark type='str'>Search darkness</widget_lblDark> + <widget_lblSet type='str'>Add to config</widget_lblSet> <conf_lblValue type='str'>Value (%)</conf_lblValue> <conf_lblRate type='str'>Refresh rate</conf_lblRate> <widget_lblBehavior type='str'>Enable behavior script</widget_lblBehavior> @@ -58,4 +61,5 @@ <conf_lblTime type='str'>Time (sec.)</conf_lblTime> <conf_lblControl type='str'>Control</conf_lblControl> <conf_btnRemove type='str'>Remove</conf_btnRemove> + <widget_lblThreshold type='str'>Threshold</widget_lblThreshold> </strings> Modified: software/gadgets/light_monitor/trunk/Light_monitor.tgf =================================================================== (Binary files differ) |