What's wrong with my "myHal.cpp" file?

Peter Poggi Feb 23, 2025

  1. Peter Poggi

    Peter Poggi TrainBoard Member

    35
    58
    9
    I'm trying to define 2 Capacitive Discharge boards in a simple myHal.cpp file EXRAIL, and this is generating a compile error. I can't see what's wrong - maybe I'm looking right at it??

    Error Generated:
    #define SEQUENCE(id) id,
    ^~
    In file included from C:\Users\peter\ex-installer\CommandStation-EX\EXRAIL.h:33,
    from C:\Users\peter\ex-installer\CommandStation-EX\DCCEX.h:53,
    from C:\Users\peter\ex-installer\CommandStation-EX\CommandStation-EX.ino:52:
    C:\Users\peter\ex-installer\CommandStation-EX\EXRAILMacros.h:100:4: error: expected declaration before '}' token
    };
    ^
    This is the cpp file.

    Code:
    //myHal.cpp
    #include "IODevice.h"
    
    void halSetup() { 
        PCF8574::create(200, 8, 0x20);
        PCF8574::create(208, 8, 0x21);
        }
    
     
    BNSF FAN likes this.
  2. Sumner

    Sumner TrainBoard Member

    3,379
    8,220
    68
    I haven't used what your are trying to do but wonder if you need to include...

    //#include "IO_PCA9555.h" // 16-bit I/O expander (NXP & Texas Instruments).

    If that doesn't work I'd open a ticket on the Discord channel.

    Sumner
     
    BNSF FAN likes this.
  3. Professor Chaos

    Professor Chaos TrainBoard Member

    14
    18
    16
    The include may work (though I think it would be #include "IO_PCF8574.h"). But I get a "'PCF8574' has not been declared" error instead of the one you get when I try to paste in your definitions.

    DCC-EX is changing the preferred method of creating devices. Instead of defining them in myHal.cpp, use the HAL() function in myAutomation.h (see here).

    One of the reasons the team is making that the preferred method is to avoid the need for the user to put in the includes.

    Also I think you may need to comment out the default MCP23017 expanders in IODevice.cpp, if you want to have a different I2c device at 0x20 or 0x21.
     
    Last edited: Feb 23, 2025
    Sumner likes this.
  4. Peter Poggi

    Peter Poggi TrainBoard Member

    35
    58
    9
    Yep! You hit it on the head. That worked Thanks!
     
    Professor Chaos and Sumner like this.

Share This Page