Как правильно сохранить структуру данных, вроде всё сделал по примеру но что-то пошло не так: Код (C++): struct EEPROM_I2C{ public: void begin(byte deviceAddress, unsigned int deviceSize); void writeByte(unsigned int eeaddresspage, byte data); byte readByte(unsigned int eeaddresspage); void writePage(unsigned int eeaddresspage, byte* data, byte length ); void readBuffer(unsigned int eeaddress, byte *buffer, int length ); //uint16_t readPixel(uint16_t theMemoryAddress); //void readImage(uint16_t theMemoryAddress, int width, int height); template< typename T > const T &put (int ee, const T& value) { const uint8_t* p = (const uint8_t*)(const void*) &value; // Ошибка на этапе присвоения //C:\Users\Admin\Documents\Arduino\libraries\EEPROM_I2C-master/EEPROM_I2C_DUE.h: In instantiation of 'const T& EEPROM_I2C::put(int, const T&) [with T = adafruit_bno055_offsets_t]': //C:\Users\Admin\Desktop\AV2\AV2.ino:168:35: required from here //C:\Users\Admin\Documents\Arduino\libraries\EEPROM_I2C-master/EEPROM_I2C_DUE.h:38:28: error: invalid initialization of reference of type 'const adafruit_bno055_offsets_t&' from expression of type 'int' int i; for (i = 0; i < sizeof(value); i++) EEPROM.writeByte(ee++, *p++); return i; } template< typename T > T &get (int ee, T& value) { uint8_t* p = (uint8_t*)(void*) &value; //error: invalid initialization of reference of type 'adafruit_bno055_offsets_t&' from expression of type 'int' //error: invalid initialization of reference of type 'long int&' from expression of type 'int' int i; for (i = 0; i < sizeof(value); i++) *p++ = EEPROM.readByte(ee++); return i; } protected: void _beginTransmission(unsigned int eeaddress); void _endTransmission(); private: byte deviceAddress; byte pageSize; bool isAddressSizeTwoWords; }; static EEPROM_I2C EEPROM; Аналогичный пример в родной библиотеке Arduino вполне корректно работает: Код (C++): struct EEPROMClass{ //Basic user access methods. EERef operator[]( const int idx ) { return idx; } uint8_t read( int idx ) { return EERef( idx ); } void write( int idx, uint8_t val ) { (EERef( idx )) = val; } void update( int idx, uint8_t val ) { EERef( idx ).update( val ); } //STL and C++11 iteration capability. EEPtr begin() { return 0x00; } EEPtr end() { return length(); } uint16_t length() { return E2END + 1; } //Functionality to 'get' and 'put' objects to and from EEPROM. template< typename T > T &get( int idx, T &t ){ EEPtr e = idx; uint8_t *ptr = (uint8_t*) &t; for( int count = sizeof(T) ; count ; --count, ++e ) *ptr++ = *e; return t; } template< typename T > const T &put( int idx, const T &t ){ EEPtr e = idx; const uint8_t *ptr = (const uint8_t*) &t; for( int count = sizeof(T) ; count ; --count, ++e ) (*e).update( *ptr++ ); return t; } }; static EEPROMClass EEPROM; #endif
Я бы по полям структуры указателями прошёлся и делов. Зачем весь этот рудимент в виде теймплетов и прочих букв?
Нет вы не правы, я использую плату Arduino DUE в ней нет ПЗУ и класс EEPROM.h там не работает, нужно сделать аналогичный функционал в библиотек для I2C памяти. Примеры которые указали вы уже используют готовые функции Get и Put в моём случае их нужно сделать.
Да зря вы так самокритично. Со всеми бывает! Описывайте то, что нужно, более понятно, и ответы будут ближе.