#[derive(Clone, Copy, PartialEq, Debug)]
pub enum Error {
NoSuchRecording,
+ StorageError,
}
enum SectorFlag {
recording_started: u32,
+ // The total distance logged of the currently running recording.
+ pub total_distance_cm: u32,
+
// The number of slots filled in num_flight.
num_in_flight: usize,
recording_id: 0,
first_sector: 0,
recording_started: 0,
+ total_distance_cm: 0,
num_in_flight: 0,
in_flight: [InFlight::new(); 7],
self.sectors_written = 0;
self.recording_started = tap.unix_time;
+ self.total_distance_cm = 0;
self.num_in_flight = 0;
self.prepare_write_buffer(true);
}
pub fn log(&mut self, prev_tap: &TimeAndPos, tap: &TimeAndPos) {
+ self.total_distance_cm += tap.distance_cm(&prev_tap) as u32;
+
let d_time_ms = elapsed_ms(tap.system_time, prev_tap.system_time);
// We know that our hardware cannot deliver updates more often
Err(Error::NoSuchRecording)
}
}
+
+ ///
+ /// Remove recording @p recording_id.
+ pub fn remove_recording(&mut self, recording_id: u16) -> Result<(), Error> {
+ if let Some(found_index) = (0..NUM_SECTORS).find(|&index| {
+ let sector_header = &self.sector_header[index as usize];
+
+ sector_header.recording_id == recording_id &&
+ sector_header.starts_recording()
+ }) {
+ let mut next_sector = found_index as usize;
+
+ for _ in 0..NUM_SECTORS {
+ let address = next_sector * SECTOR_SIZE;
+
+ if let Err(_) = self.storage.erase(address) {
+ return Err(Error::StorageError);
+ }
+
+ // Mark this sector as eligible for the next recording
+ // and ensure it won't be picked up by list_recordings().
+ self.read_sector_header(next_sector);
+
+ next_sector += 1;
+ next_sector &= NUM_SECTORS - 1;
+
+ if !self.sector_header[next_sector].belongs_to(recording_id) {
+ break;
+ }
+ }
+
+ Ok(())
+ } else {
+ Err(Error::NoSuchRecording)
+ }
+ }
}