
#ifndef maxlib_h
#define maxlib_h

#include "firmatalib.h"

#define TOTAL_IN_PINS       20
#define TOTAL_OUT_PINS      12

#define DEFAUTLT_BAUD       57600
#define MAX_PORTS           20

#define IN_BOARD            0
#define OUT_BOARD           1


typedef struct {
    
    // ARDUINO Uno board
    board_t *board;

    // serial port full name
    char *name;

    // double links to the Max interface objects
    void *board_in, *board_out;

} board_mgr_t;

// connect to board via a serial port, init board to desired configuration
// and start listening to updates from the board.
int maxclient_connect(board_t *board, int len_config, int *pins, int *modes, int funct);

// close communication with the board,
int maxclient_disconnect(board_t *board);

//
int  maxclient_shutdown(board_t *board);

// reads input pin values from the board.
void maxclient_getInputValues(board_t *board, long *indexArray, long *valuesArray, int pinsCount);

//
int  maxclient_verifyconfig(board_t *board, int len, int *pins, int *modes);

// toggle the digital pin value.
void maxclient_toggleDigital(board_t *board, int pin, int newVal);

// update servo pin value.
// caps the values to range [0-180] degree angles.
void maxclient_moveServo(board_t *board, int pin, int newVal);

// update pwm pin value.
void maxclient_movePwm(board_t *board, int pin, int newVal);

//
board_t* maxclient_newboard(char *name, int baud, char *err);

// Release resources allocated.
void maxclient_freemgr(board_mgr_t *mgr);

#endif /* maxlib_h */

