- def start_interval(self):
- logger.info("New interval started")
- stime = time.time()
- t=[]
- coords = [[], [], []]
- while not self.stop_requested and (len(t) == 0 or t[-1] < 5):
- x,y,z = self.get_rotation()
- coords[0].append(int(x))
- coords[1].append(int(y))
- coords[2].append(int(z))
- now = time.time()-stime
- if self.logging:
- self.file.write("%d %d %d %f\n" %(coords[0][-1], coords[1][-1], coords[2][-1], now))
-
- t.append(now)
- time.sleep(self.COORD_GET_INTERVAL)
- pic = PedoIntervalCounter(coords, t)
+ def start(self):
+ logger.info("Counter started")
+ self.isRunning = True
+ if self.logging:
+ fname = "%d_%d_%d_%d_%d_%d" % time.localtime()[0:6]
+ self.file = open(self.LOGFILE + fname + ".txt", "w")
+ gobject.idle_add(self.run)
+
+ def run(self):
+ self.coords = [[], [], []]
+ self.stime = time.time()
+ self.t = []
+ gobject.timeout_add(self.COORD_GET_INTERVAL, self.read_coords)
+ return False
+
+ def read_coords(self):
+ x,y,z = self.get_rotation()
+ self.coords[0].append(int(x))
+ self.coords[1].append(int(y))
+ self.coords[2].append(int(z))
+ now = time.time()-self.stime
+ if self.logging:
+ self.file.write("%d %d %d %f\n" %(self.coords[0][-1], self.coords[1][-1], self.coords[2][-1], now))
+
+ self.t.append(now)
+ #call stop_interval
+ ret = True
+ if self.t[-1] > 5 or self.stop_requested:
+ ret = False
+ gobject.idle_add(self.stop_interval)
+ return ret
+
+ def stop_interval(self):
+ pic = PedoIntervalCounter(self.coords, self.t)