def start(self, filename, timetorun, interval): """ Starts the data logger, runs for the 'time to run' in seconds, writing data every 'interval' seconds. """ #create astro pi object self._write_message("Starting Sense HAT") #use the threaded astro pi class, so orientation stay in sync ap = AstroPiThreaded() #create the astro pi progress bar progressbar = AstroPiBelshawProgressBar(ap) try: self._write_message("Initialising Sense HAT") self._init_astro_pi(ap) #open cpu temperature file self._write_message("Opening CPU temperature") with CPUTemp() as cpu_temp: self._write_message("Starting data logger") self._write_message(" filename - {}".format(filename)) self._write_message(" time to run - {} seconds".format(timetorun)) self._write_message(" interval - {} seconds".format(interval)) #open file for writing self._write_message("Creating file {}".format(filename)) with open(filename, "w") as datafile: #create the writer writer = DictWriter(datafile, fieldnames = self.FIELDNAMES) #write the csv file header writer.writeheader() #get the time the program started starttime = time() self._write_message("Writing data") nextrowtime = starttime #loop until the time to run as passed while((time() - starttime) < timetorun): #read data and write to csv file datarow = self._read_data(ap, cpu_temp) writer.writerow(datarow) #wait until the next interval nextrowtime = nextrowtime + interval while(time() < nextrowtime): sleep(0.01) progressbar.next() finally: #stop the astro pi thread which reads the orientation ap.stop() #clear the progress bar progressbar.clear() self._write_message("Finished")
def start(self, filename, timetorun, interval): """ Starts the data logger, runs for the 'time to run' in seconds, writing data every 'interval' seconds. """ #create astro pi object self._write_message("Starting Sense HAT") #use the threaded astro pi class, so orientation stay in sync ap = AstroPiThreaded() #create the astro pi progress bar progressbar = AstroPiBelshawProgressBar(ap) try: self._write_message("Initialising Sense HAT") self._init_astro_pi(ap) #open cpu temperature file self._write_message("Opening CPU temperature") with CPUTemp() as cpu_temp: self._write_message("Starting data logger") self._write_message(" filename - {}".format(filename)) self._write_message( " time to run - {} seconds".format(timetorun)) self._write_message(" interval - {} seconds".format(interval)) #open file for writing self._write_message("Creating file {}".format(filename)) with open(filename, "w") as datafile: #create the writer writer = DictWriter(datafile, fieldnames=self.FIELDNAMES) #write the csv file header writer.writeheader() #get the time the program started starttime = time() self._write_message("Writing data") nextrowtime = starttime #loop until the time to run as passed while ((time() - starttime) < timetorun): #read data and write to csv file datarow = self._read_data(ap, cpu_temp) writer.writerow(datarow) #wait until the next interval nextrowtime = nextrowtime + interval while (time() < nextrowtime): sleep(0.01) progressbar.next() finally: #stop the astro pi thread which reads the orientation ap.stop() #clear the progress bar progressbar.clear() self._write_message("Finished")
left = 1 elif event.key == pygame.K_RIGHT: right = 1 elif event.key == pygame.K_RETURN: button = 1 return {"up": up, "down": down, "left": left, "right": right, "button": button} if __name__ == "__main__": #create the connection to minecraft mc = Minecraft.create() mc.postToChat("SpaceCRAFT - Real time display") #create the astro pi object, my threaded one which keeps reading orientation data ap = AstroPiThreaded() ap.set_imu_config(True, True, True) #initialise pygame init_pygame() #open the cpu temperature object cpu_temp = CPUTemp() cpu_temp.open() #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) #create the iss tower display