#ifndef CONFIG_ADV_H
#define CONFIG_ADV_H

////////////////////////////////////////////////////////////////////////////////
//
//  Common settings

#define ANALOG_READ_THRESHOLD 800

////////////////////////////////////////////////////////////////////////////////
//
//  Plunger settings

#define MAX_PLUNGE_TIME     10000

////////////////////////////////////////////////////////////////////////////////
//
//  Plunger settings and timings
//
//  Times are base on observations rather than calculations. Calculating it
//  will affect plunger speed drasitcally even more lower spec boards.

// interval before reading the limit switch
// this setting will affect your plunging speed since analogRead will
// consume some time and we do have only one thread.
#define LIMIT_SWITCH_INTERVAL 30

/////////////////////////////////////////////////////////////
//
// 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 50

// the motor runs idle
#define MOTOR_IDLE_LOAD_RANGE_MIN 0
#define MOTOR_IDLE_LOAD_RANGE_MAX 20

#define MOTOR_HOMING_LOAD_RANGE_MIN 60
#define MOTOR_HOMING_LOAD_RANGE_MAX 100

#define MOTOR_PLUNGING_LOAD_RANGE_MIN 100
#define MOTOR_PLUNGING_LOAD_RANGE_MAX 130

#define MOTOR_HIGHLOAD_RANGE_MIN 100
#define MOTOR_HIGHLOAD_RANGE_MAX 130

#define MOTOR_OVERLOAD_RANGE_MIN 130
#define MOTOR_OVERLOAD_RANGE_MAX 255

#define MOTOR_LOAD_SCALE 40

#define MOTOR_MIN_DT 2500

/////////////////////////////////////////////////////////////
//
//  Error codes
//
#define E_MSG_OK                                "Ok"
#define E_MSG_STUCK                             "Shredder is stuck"

// common operating failures
#define E_OK                                    0   //all good
#define E_STUCK                                 100 //Shredder stuck

// power failures

#define E_POWER_PRIM_ON                         145 // Power is on whilst it shouldn't be
#define E_POWER_PRIM_OFF                        146 // Power is off whilst it should be

#define E_POWER_SEC_ON                          147 // Power is on whilst it shouldn't be
#define E_POWER_SEC_OFF                         148 // Power is off whilst it should be
#define E_POWER                                 150 // Nothing is online

#define E_VFD_OFFLINE                           E_POWER_PRIM_OFF // VFD should be online
#define E_PLUNGER_OFFLINE                       E_POWER_SEC_OFF // Plunger should be online

// sensor failures
#define E_VFD_CURRENT                           200 // VFD current abnormal: below or above average
#define E_PLUNGER_CURRENT                       210 // Plunger current abnormal: below or above average
#define E_OPERATING_SWITCH                      220 // Operating switch invalid value

#define E_PLUNGER_LIMIT                         230 // Something is wrong with the limit switches, should
#define E_PLUNGER_OVERLOAD                      235 // Stepper above average

#define E_CARTRIDGE_OPEN                        240 // Cartridge open sensor doesn't work
#define E_SERVICE_OPEN                          241   // Sensor open sensor doesn't work

////////////////////////////
//
// sub system failures
//
#define E_USER_START 1000 // base offset for sub system errors

// vfd
#define E_VFD_RUN                               300  // Motor should spin but doesnt
#define E_VFD_LOSS                              301  // Motor should not spin but does
#define E_VFD_CUSTOM(A)                         E_USER_START + A // Custom VFD error

// plunger
#define E_PLUNGER_RUN                           400 // Plungers runs with weird limit/homing switch activity

// motor
#define E_MOTOR_DT_IDLE 320     // Motor runs idle longer as defined
#define E_MOTOR_DT_OVERLOAD 321 // Motor runs overloaded longer as defined

#define E_BRIDGE_LOSS 400 // bridge poll timeout

#endif