simple project to control mirrorless camera

Dependencies:   mbed BLE_API nRF51822

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers FlashStore.h Source File

FlashStore.h

00001 #ifndef MBED_FLASHSTORE_H
00002 #define MBED_FLASHSTORE_H
00003  
00004 #include "mbed.h"
00005 
00006 #include "pstorage.h"
00007 #include "nrf_error.h"
00008 
00009 struct settings {
00010     char devicever[10];
00011     char devicepin[4];
00012     char devicename[20];
00013     int deviceblemajor;
00014     int devicebleminor;
00015     int devicepower;
00016 };
00017 
00018 struct measure {
00019   long madatetime;
00020   float measurevaue;
00021 };
00022 
00023 
00024 
00025 class FlashStore {
00026 public:
00027     
00028     FlashStore(Serial &_Serial) : Tserial(_Serial)        
00029     {
00030         storestate = 0;
00031         void setupStore(void);
00032     }       
00033     
00034     void saveSettings(char name[20], char pin[4], int power, int bleMinor, int bleMajor, char version[10]) {
00035                 
00036         settings toSave;
00037                 
00038       //  toSave.devicename = name;
00039       //  toSave.devicepin = pin;
00040         toSave.devicepower = power;
00041         toSave.devicebleminor = bleMinor;
00042         toSave.deviceblemajor = bleMajor;
00043       //  toSave.devicever = version;
00044         
00045         tempstate = pstorage_store(&settingsHandle, (uint8_t *)&toSave, sizeof(toSave), 0);
00046         Tserial.printf("FlashStore saveSettings\r\n");
00047         
00048         if (tempstate == NRF_SUCCESS) {
00049             Tserial.printf("FlashStore saveSettings - ok! \r\n");
00050         }
00051         
00052     }
00053     
00054      void readSettings(void) {
00055         
00056         settings toLoad;
00057         
00058         tempstate = pstorage_load((uint8_t *)&toLoad, &settingsHandle, sizeof(toLoad), 0);
00059         Tserial.printf("FlashStore readSettings\r\n");
00060         if (tempstate == NRF_SUCCESS) {
00061         
00062             Tserial.printf("FlashStore readSettings - ok: %s\r\n", toLoad.devicename );     
00063              
00064         }
00065         
00066         
00067         
00068         Tserial.printf("FlashStore Read It\r\n");
00069     }
00070 
00071 
00072 
00073     
00074 private:  
00075    Serial &Tserial; // tx, rx
00076    uint32_t storestate; // 0 - not init, 1 - not register, 2 - not measure register, 3 - ok
00077    uint32_t tempstate;
00078    pstorage_handle_t settingsHandle, measureHandle;
00079    pstorage_module_param_t settingsParams, measureParams;
00080    
00081     void setupStore(void) {
00082         tempstate = pstorage_init(); 
00083         
00084         if(tempstate == NRF_SUCCESS) {
00085             
00086             storestate = 1;                    
00087             
00088             settingsParams.block_size  = sizeof(settings);
00089             settingsParams.block_count = 1; 
00090             settingsParams.cb = cb_handler;            
00091             tempstate = pstorage_register(&settingsParams, &settingsHandle);
00092             
00093             if (tempstate == NRF_SUCCESS)
00094             {
00095                 storestate = 2;                                                
00096             }                           
00097         }
00098         
00099         Tserial.printf("FlashStore up\r\n");
00100     }
00101    
00102    
00103     static void cb_handler(pstorage_handle_t  * handle,
00104                                uint8_t              op_code,
00105                                uint32_t             result,
00106                                uint8_t            * p_data,
00107                                uint32_t             data_len)
00108     {
00109         //Tserial.printf("Callback handler successful\r\n");
00110     }
00111     
00112    
00113     
00114 };
00115  
00116 #endif