#ifndef _COMMSEXPANDER

#define _COMMSEXPANDER

#include <arduino.h>
#include "Config.h"

class CommsExpander {
    public:
        CommsExpander() {
            rs232SelectList[0] = RS232_SELECT_0;
            rs232SelectList[1] = RS232_SELECT_1;
            rs232SelectList[2] = RS232_SELECT_2;
        }
        void selectPort(uint32_t port) {

            // Disable the expander
            digitalWrite(RS232_EN,LOW);
            
            // Set the port address
            for (int i = 0; i < 3; i++) {
                uint8_t bit = bitRead(port, i);
                //DEBUGPORT.print(bit);
                if (bit > 0) {
                    digitalWrite(rs232SelectList[i],HIGH);
                }
                else {
                    digitalWrite(rs232SelectList[i],LOW);
                }
            }
            //DEBUGPORT.println();

            // Enable the expander
            digitalWrite(RS232_EN,HIGH);

        }

    protected:
        uint32_t currentPort;
        uint32_t rs232SelectList[3];
};

#endif