def run(self): #open the file self.running = True self.stopped = False try: #open astro pi data file apr = AstroPiDataReader(self.filename) self.apr = apr #are there any rows? if apr.rowcount > 0: #create connection to minecraft mc = Minecraft.create() mc.postToChat("Playback {} Started".format(self.filename)) #find the position of where to put the ISS tower display pos = mc.player.getTilePos() pos.z -= 10 pos.y = mc.getHeight(pos.x, pos.z) try: #create the iss tower display isstowerdisplay = ISSTowerMinecraftDisplay(mc, pos) #loop until its stopped found_row = True while self.stopped == False and found_row == True: #get the time started real_time_start = time() last_row_time = apr.get_time() #update the ISS dispay with the data isstowerdisplay.update( apr.get_time(), apr.get_cpu_temperature(), apr.get_temperature(), apr.get_humidity(), apr.get_pressure(), apr.get_orientation(), apr.get_joystick()) #move onto the next row found_row = apr.next() #wait until the next row time if found_row: #wait until the time in the real world is greater than the time between the rows while (time() - real_time_start) < ((apr.get_time() - last_row_time) / self.speed) : sleep(0.001) finally: isstowerdisplay.clear() mc.postToChat("Playback {} finished".format(self.filename)) else: print("Error - {} contained no data".format(self.filename)) #catch failed to open file error except IOError: print("Failed to open file '{}'.".format(self.filename)) print(sys.exc_info()[1]) #catch any other error except: print(sys.exc_info()[0]) print(sys.exc_info()[1]) finally: self.running = False self.stopped = True
""" import argparse from astropidata import AstroPiDataReader #data reader program if __name__ == "__main__": parser = argparse.ArgumentParser(description="Astro Pi Data Reader") parser.add_argument("filename", help="The input filename") parser.add_argument("-v", "--verbose", action="store_true", help="Output verbose debug statements") args = parser.parse_args() #open the file apreader = AstroPiDataReader(args.filename, args.verbose) #are there any rows? if apreader.rowcount > 0: #keep looping until its the end of file found_row = True while (found_row): #read the values datetime = apreader.get_datetime() time = apreader.get_time() cpu_temp = apreader.get_cpu_temperature() temp_humid = apreader.get_temperature_from_humidity() temp_press = apreader.get_temperature_from_pressure() pressure = apreader.get_pressure() humidity = apreader.get_humidity() ori_deg = apreader.get_orientation_in_degrees()
Program for reading in data logged by the AstroPiDataLogger - its not invisaged that this progam will be used as all it does is output data to the screen, but it should be used as an example of how to use AstroPiDataReader """ import argparse from astropidata import AstroPiDataReader #data reader program if __name__ == "__main__": parser = argparse.ArgumentParser(description="Astro Pi Data Reader") parser.add_argument("filename", help="The input filename") parser.add_argument("-v", "--verbose", action="store_true", help="Output verbose debug statements") args = parser.parse_args() #open the file apreader = AstroPiDataReader(args.filename, args.verbose) #are there any rows? if apreader.rowcount > 0: #keep looping until its the end of file found_row = True while(found_row): #read the values datetime = apreader.get_datetime() time = apreader.get_time() cpu_temp = apreader.get_cpu_temperature() temp_humid = apreader.get_temperature_from_humidity() temp_press = apreader.get_temperature_from_pressure() pressure = apreader.get_pressure() humidity = apreader.get_humidity() ori_deg = apreader.get_orientation_in_degrees()