Sunday, March 3, 2024

class – Go array to initialization listing

I’m writing a customized class Settings with customized members crccfg. However presently I’m a bit misplaced tips on how to initialize all of this… The Crccfg() constructor ought to get the _DEFAULT_CRCCFG, however it fails like this:

a price of kind “uint8_t *” can’t be used to initialize an entity of kind “uint8_t [2]”C/C++(144)

  typedef union Crccfg {
    Crccfg(uint8_t knowledge[2]) : uncooked(knowledge) {}
    uint8_t uncooked[2];  //!< CRC-16 Checksum Worth
  } crccfg_t;

  class Settings {
    const uint8_t _DEFAULT_CONFIG0   = 0xC0;                
    const uint8_t _DEFAULT_CONFIG1   = 0x0C;                
    const uint8_t _DEFAULT_CONFIG2   = 0x8B;                
    const uint8_t _DEFAULT_CONFIG3   = 0x00;                
    const uint8_t _DEFAULT_IRQ       = 0x73;                
    const uint8_t _DEFAULT_MUX       = 0x01;                
    const uint8_t _DEFAULT_SCAN[3]   = {0x00, 0x00, 0x00};  
    const uint8_t _DEFAULT_TIMER[3]  = {0x00, 0x00, 0x00};  
    const uint8_t _DEFAULT_OFFSET[3] = {0x00, 0x00, 0x00};  
    const uint8_t _DEFAULT_GAIN[3]   = {0x80, 0x00, 0x00};  
    const uint8_t _DEFAULT_LOCK      = 0xA5;                
    const uint8_t _DEFAULT_CRCCFG[2] = {0x00, 0x00};        

    config0_t config0           = _DEFAULT_CONFIG0;    
    config1_t config1           = _DEFAULT_CONFIG1;    
    config2_t config2           = _DEFAULT_CONFIG2;    
    config3_t config3           = _DEFAULT_CONFIG3;    
    irq_t irq                   = _DEFAULT_IRQ;        
    mux_t mux                   = _DEFAULT_MUX;        
    scan_t scan                 = _DEFAULT_SCAN;       
    timer_t timer               = _DEFAULT_TIMER;      
    offset_t offsetcal          = _DEFAULT_OFFSET;     
    gain_t gaincal              = _DEFAULT_GAIN;       
    const uint8_t reserverd1[3] = {0x90, 0x00, 0x00};  
    const uint8_t reserverd2    = 0x50;                
    lock_t lock                 = _DEFAULT_LOCK;       
    uint16_t id;                                       
    crccfg_t crccfg = _DEFAULT_CRCCFG;                 

    Settings(const uint16_t MCP3x6x_DEVICE_TYPE) { id = MCP3x6x_DEVICE_TYPE; }
  } settings;


Related Articles


Please enter your comment!
Please enter your name here

Latest Articles