mirror of
				https://github.com/Djeeberjr/fw-anwesenheit.git
				synced 2025-11-04 07:34:10 +00:00 
			
		
		
		
	implemented save function for SD Card
This commit is contained in:
		
							parent
							
								
									dcb4b14854
								
							
						
					
					
						commit
						d96b3ed11a
					
				@ -1,3 +1,4 @@
 | 
				
			|||||||
 | 
					use bleps::att::Att;
 | 
				
			||||||
use embassy_executor::Spawner;
 | 
					use embassy_executor::Spawner;
 | 
				
			||||||
use embassy_net::Stack;
 | 
					use embassy_net::Stack;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -8,9 +9,7 @@ use esp_hal::peripherals::{
 | 
				
			|||||||
    UART1,
 | 
					    UART1,
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
use esp_hal::rmt::{ConstChannelAccess, Rmt};
 | 
					use esp_hal::rmt::{ConstChannelAccess, Rmt};
 | 
				
			||||||
use esp_hal::spi::{
 | 
					use esp_hal::spi::master::{Config as Spi_config, Spi};
 | 
				
			||||||
    master::{Config as Spi_config, Spi},
 | 
					 | 
				
			||||||
};
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
use esp_hal::Blocking;
 | 
					use esp_hal::Blocking;
 | 
				
			||||||
use esp_hal::time::Rate;
 | 
					use esp_hal::time::Rate;
 | 
				
			||||||
@ -24,12 +23,15 @@ use esp_hal::{
 | 
				
			|||||||
    uart::Uart,
 | 
					    uart::Uart,
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
use esp_hal_smartled::{SmartLedsAdapterAsync, buffer_size_async};
 | 
					use esp_hal_smartled::{SmartLedsAdapterAsync, buffer_size_async};
 | 
				
			||||||
 | 
					use esp_println::dbg;
 | 
				
			||||||
use esp_println::logger::init_logger;
 | 
					use esp_println::logger::init_logger;
 | 
				
			||||||
use log::{debug, error};
 | 
					use log::{debug, error, info};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
use crate::init::network;
 | 
					use crate::init::network;
 | 
				
			||||||
use crate::init::sd_card::setup_sdcard;
 | 
					use crate::init::sd_card::setup_sdcard;
 | 
				
			||||||
use crate::init::wifi;
 | 
					use crate::init::wifi;
 | 
				
			||||||
 | 
					use crate::store::AttendanceDay;
 | 
				
			||||||
 | 
					use crate::store::persistence::Persistence;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/*************************************************
 | 
					/*************************************************
 | 
				
			||||||
 * GPIO Pinout Xiao Esp32c6
 | 
					 * GPIO Pinout Xiao Esp32c6
 | 
				
			||||||
@ -44,7 +46,7 @@ use crate::init::wifi;
 | 
				
			|||||||
 * D7  -> GPIO17 -> UART/RX -> Level Shifter A1 -> NFC Reader
 | 
					 * D7  -> GPIO17 -> UART/RX -> Level Shifter A1 -> NFC Reader
 | 
				
			||||||
 * D8  -> GPIO19 -> SPI/SCLK
 | 
					 * D8  -> GPIO19 -> SPI/SCLK
 | 
				
			||||||
 * D9  -> GPIO20 -> SPI/MISO
 | 
					 * D9  -> GPIO20 -> SPI/MISO
 | 
				
			||||||
 * D10 -> GPIO10 -> SPI/MOSI
 | 
					 * D10 -> GPIO18 -> SPI/MOSI
 | 
				
			||||||
 *
 | 
					 *
 | 
				
			||||||
 *************************************************/
 | 
					 *************************************************/
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -107,7 +109,7 @@ pub async fn hardware_init(
 | 
				
			|||||||
        OutputConfig::default(),
 | 
					        OutputConfig::default(),
 | 
				
			||||||
    );
 | 
					    );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    let vol_mgr = setup_sdcard(spi_bus, sd_cs_pin);
 | 
					    let mut vol_mgr = setup_sdcard(spi_bus, sd_cs_pin);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    let buzzer_gpio = peripherals.GPIO21;
 | 
					    let buzzer_gpio = peripherals.GPIO21;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -43,20 +43,28 @@ impl Persistence for SDCardPersistence {
 | 
				
			|||||||
        let mut vol_0 = self.vol_mgr.open_volume(VolumeIdx(0)).unwrap();
 | 
					        let mut vol_0 = self.vol_mgr.open_volume(VolumeIdx(0)).unwrap();
 | 
				
			||||||
        let mut root_dir = vol_0.open_root_dir().unwrap();
 | 
					        let mut root_dir = vol_0.open_root_dir().unwrap();
 | 
				
			||||||
        let mut file = root_dir
 | 
					        let mut file = root_dir
 | 
				
			||||||
            .open_file_in_dir("days/TODO", embedded_sdmmc::Mode::ReadOnly)
 | 
					            .open_file_in_dir("day.jsn", embedded_sdmmc::Mode::ReadOnly)
 | 
				
			||||||
            .unwrap();
 | 
					            .unwrap();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        let mut read_buffer: [u8; 1024] = [0; 1024];
 | 
					        let mut read_buffer: [u8; 1024] = [0; 1024];
 | 
				
			||||||
        let read = file.read(&mut read_buffer).unwrap();
 | 
					        let read = file.read(&mut read_buffer).unwrap();
 | 
				
			||||||
        file.close().unwrap();
 | 
					        file.close().unwrap();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        let day: AttendanceDay = serde_json::from_slice(&read_buffer).unwrap();
 | 
					        let day: AttendanceDay = serde_json::from_slice(&read_buffer[..read]).unwrap();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        Some(day)
 | 
					        Some(day)
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    async fn save_day(&mut self, day: Date, data: &AttendanceDay) {
 | 
					    async fn save_day(&mut self, day: Date, data: &AttendanceDay) {
 | 
				
			||||||
        todo!()
 | 
					        let mut vol_0 = self.vol_mgr.open_volume(VolumeIdx(0)).unwrap();
 | 
				
			||||||
 | 
					        let mut root_dir = vol_0.open_root_dir().unwrap();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        let mut file = root_dir
 | 
				
			||||||
 | 
					            .open_file_in_dir("day.jsn", embedded_sdmmc::Mode::ReadWriteCreateOrTruncate)
 | 
				
			||||||
 | 
					            .unwrap();
 | 
				
			||||||
 | 
					        file.write(&serde_json::to_vec(data).unwrap()).unwrap();
 | 
				
			||||||
 | 
					        file.flush();
 | 
				
			||||||
 | 
					        file.close();
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    async fn load_mapping(&mut self) -> Option<crate::store::IDMapping> {
 | 
					    async fn load_mapping(&mut self) -> Option<crate::store::IDMapping> {
 | 
				
			||||||
 | 
				
			|||||||
@ -15,7 +15,7 @@ use embassy_time::{Duration, Timer};
 | 
				
			|||||||
use log::{debug, info};
 | 
					use log::{debug, info};
 | 
				
			||||||
use static_cell::make_static;
 | 
					use static_cell::make_static;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
use crate::{store::TallyID, webserver::start_webserver};
 | 
					use crate::{store::TallyID};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
extern crate alloc;
 | 
					extern crate alloc;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -23,7 +23,7 @@ mod drivers;
 | 
				
			|||||||
mod feedback;
 | 
					mod feedback;
 | 
				
			||||||
mod init;
 | 
					mod init;
 | 
				
			||||||
mod store;
 | 
					mod store;
 | 
				
			||||||
mod webserver;
 | 
					//mod webserver;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static FEEDBACK_STATE: Signal<CriticalSectionRawMutex, feedback::FeedbackState> = Signal::new();
 | 
					static FEEDBACK_STATE: Signal<CriticalSectionRawMutex, feedback::FeedbackState> = Signal::new();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -5,15 +5,16 @@ use super::IDMapping;
 | 
				
			|||||||
use super::TallyID;
 | 
					use super::TallyID;
 | 
				
			||||||
use alloc::vec::Vec;
 | 
					use alloc::vec::Vec;
 | 
				
			||||||
use serde::Deserialize;
 | 
					use serde::Deserialize;
 | 
				
			||||||
 | 
					use serde::Serialize;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#[derive(Clone, Deserialize)]
 | 
					#[derive(Clone, Serialize, Deserialize, Debug)]
 | 
				
			||||||
pub struct AttendanceDay {
 | 
					pub struct AttendanceDay {
 | 
				
			||||||
    date: Date,
 | 
					    date: Date,
 | 
				
			||||||
    ids: Vec<TallyID>,
 | 
					    ids: Vec<TallyID>,
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
impl AttendanceDay {
 | 
					impl AttendanceDay {
 | 
				
			||||||
    fn new(date: Date) -> Self {
 | 
					   pub fn new(date: Date) -> Self {
 | 
				
			||||||
        Self {
 | 
					        Self {
 | 
				
			||||||
            date,
 | 
					            date,
 | 
				
			||||||
            ids: Vec::new(),
 | 
					            ids: Vec::new(),
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user