#ifndef CONFIG_H
#define CONFIG_H

#include <Arduino.h>
#include <stdint.h>

// Platform / Boards

//#define PLATFORM_PORTENTA_H7_M7
//#define BOARD_NAME "Portenta H7 M7"

///////////////////////////////////////////////////////
//
// Features

#define MODBUS_BRIDGE
// #define OMRON_PID
#define MUDBUS

#define MODBUS_RS485_BAUDRATE           19200
#define MODBUS_RS485_PORT               SERIAL_8N1
#define MODBUS_RS485_TIMEOUT            2000

#define MODBUS_TCP_DEFAULT_REGISTER_VALUE 0

#define HAS_MODBUS_BRIDGE

#ifdef MODBUS_BRIDGE
  static uint8_t MB_MAC[] =               {0x01, 0xAA, 0xBB, 0xCC, 0xDE, 0x02};
  static uint8_t MB_IP[]{192, 168, 1, 177};
  static uint8_t MB_DNS[]{192, 168, 1, 1};
  static uint8_t MB_GATEWAY[] =           {192, 168, 1, 1};
  static uint8_t MB_SUBNET[] =            {255, 255, 255, 0};
#endif

/////////////////////////////////////////////////////////////
//
// Motor load settings, this requires a current sensor or can be
// taken from the VFD's output. 

// the interval to read the current
#define MOTOR_LOAD_READ_INTERVAL                        100

// the current measured when the motor runs idle, min - max range
#define MOTOR_IDLE_LOAD_RANGE_MIN                       30
#define MOTOR_IDLE_LOAD_RANGE_MAX                       50

// the current measured when the motor is under load, min - max range
#define MOTOR_SHREDDING_LOAD_RANGE_MIN                  50
#define MOTOR_SHREDDING_LOAD_RANGE_MAX                  99

// the current measured when the motor is overloaded, min - max range
#define MOTOR_OVERLOAD_RANGE_MIN                        100
#define MOTOR_OVERLOAD_RANGE_MAX                        400

#define MOTOR_LOAD_PIN                      12


#ifdef PLATFORM_PORTENTA_H7_M7
  #include <Arduino_MachineControl.h>
  using namespace machinecontrol;
#endif

#define SERIAL_BAUD_RATE 19200
#define SERIAL_COMMAND_PARSE_INTERVAL 100


//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
// Modbus - Commons

#define MODBUS_RS485_BAUDRATE           19200
#define MODBUS_RS485_PORT               SERIAL_8N1
#define MODBUS_RS485_TIMEOUT            2000

#define MODBUS_TCP_DEFAULT_REGISTER_VALUE 0


//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
//  Omron Pids - E5.x series - Modbus interface 
//

#define NB_OMRON_PIDS 0
//  #define OMRON_PID_SLAVE_START 1
#define OMRON_PID_UPDATE_INTERVAL       1000
#define OMRON_PID_WRITE_INTERVAL        500


////////////////////////////////////////////////////////////////
//
// Modbus settings - Omron - MX2

#define OMRON_MX2_SLAVE_ID              2

#define OMRON_MX2_STATE_INTERVAL        1000
#define OMRON_MX2_DEBUG_INTERVAL        3000
#define OMRON_MX2_READ_INTERVAL         1000
#define OMRON_MX2_LOOP_INTERVAL         500
#define OMRON_MX2_SAME_REQUEST_INTERVAL 2000

#define MODBUS_QUEUE_MIN_FREE           5
#define OMRON_VFD_MAX_FREQ              800


#endif // CONFIG_H
