#!/usr/bin/env bash
#
# Build tests for Teensy 3.5/3.6 (ARM Cortex-M4)
#

# exit on first failure
set -e

restore_configs
opt_set MOTHERBOARD BOARD_TEENSY35_36
cp Marlin/src/pins/pins_RAMPS.h Marlin/src/pins/pins_RAMPS.h.backup
exec_test $1 $2 "Teensy3.5 with default config"

#
# Test as many features together as possible
#
restore_configs
opt_set EXTRUDERS 2
opt_set TEMP_SENSOR_0 1
opt_set TEMP_SENSOR_1 5
opt_set TEMP_SENSOR_BED 1
opt_enable REPRAP_DISCOUNT_FULL_GRAPHIC_SMART_CONTROLLER SDSUPPORT \
           FILAMENT_WIDTH_SENSOR FILAMENT_LCD_DISPLAY \
           FIX_MOUNTED_PROBE Z_SAFE_HOMING AUTO_BED_LEVELING_BILINEAR Z_MIN_PROBE_REPEATABILITY_TEST DEBUG_LEVELING_FEATURE \
           BABYSTEPPING BABYSTEP_XY BABYSTEP_ZPROBE_OFFSET BABYSTEP_ZPROBE_GFX_OVERLAY \
           PRINTCOUNTER NOZZLE_PARK_FEATURE NOZZLE_CLEAN_FEATURE SLOW_PWM_HEATERS PIDTEMPBED EEPROM_SETTINGS INCH_MODE_SUPPORT TEMPERATURE_UNITS_SUPPORT M100_FREE_MEMORY_WATCHER
opt_enable_adv ADVANCED_PAUSE_FEATURE LCD_INFO_MENU ARC_SUPPORT BEZIER_CURVE_SUPPORT EXPERIMENTAL_I2CBUS EXTENDED_CAPABILITIES_REPORT AUTO_REPORT_TEMPERATURES SDCARD_SORT_ALPHA PARK_HEAD_ON_PAUSE
opt_set_adv I2C_SLAVE_ADDRESS 63
opt_set GRID_MAX_POINTS_X 16
exec_test $1 $2 "Teensy3.5 with many features"

#
# Test a Sled Z Probe with Linear leveling
#
restore_configs
opt_enable EEPROM_SETTINGS \
           Z_PROBE_SLED AUTO_BED_LEVELING_LINEAR DEBUG_LEVELING_FEATURE
opt_enable_adv GCODE_MACROS
exec_test $1 $2 "Sled Z Probe with Linear leveling"

#
# Test a Servo Probe
#
# restore_configs
# opt_enable Z_PROBE_SERVO_NR Z_SERVO_ANGLES DEACTIVATE_SERVOS_AFTER_MOVE \
#            AUTO_BED_LEVELING_3POINT DEBUG_LEVELING_FEATURE EEPROM_SETTINGS
# opt_set NUM_SERVOS 1
# exec_test $1 $2 "Servo Probe"
#
# ...with AUTO_BED_LEVELING_3POINT, DEBUG_LEVELING_FEATURE, EEPROM_SETTINGS, EEPROM_CHITCHAT, EXTENDED_CAPABILITIES_REPORT, and AUTO_REPORT_TEMPERATURES
#
# opt_enable AUTO_BED_LEVELING_3POINT DEBUG_LEVELING_FEATURE EEPROM_SETTINGS
# opt_enable_adv EXTENDED_CAPABILITIES_REPORT AUTO_REPORT_TEMPERATURES
# exec_test $1 $2 "...with AUTO_BED_LEVELING_3POINT, DEBUG_LEVELING_FEATURE, EEPROM_SETTINGS, EEPROM_CHITCHAT, EXTENDED_CAPABILITIES_REPORT, and AUTO_REPORT_TEMPERATURES"

#
# Test MESH_BED_LEVELING feature, with LCD
#
restore_configs
opt_enable MESH_BED_LEVELING MESH_G28_REST_ORIGIN MANUAL_BED_LEVELING ULTIMAKERCONTROLLER
exec_test $1 $2 "MESH_BED_LEVELING feature, with LCD"

#
# Mixing Extruder
#
restore_configs
opt_enable MIXING_EXTRUDER DIRECT_MIXING_IN_G1
opt_set MIXING_STEPPERS 2
exec_test $1 $2 "Mixing Extruder"

#
# Test SWITCHING_EXTRUDER
#
# restore_configs
# opt_set EXTRUDERS 2
# opt_set NUM_SERVOS 1
# opt_enable SWITCHING_EXTRUDER ULTIMAKERCONTROLLER
# exec_test $1 $2 "SWITCHING_EXTRUDER"
#
# Enable COREXY
#
restore_configs
opt_enable COREXY
exec_test $1 $2 "COREXY"

#
# Enable COREXZ
#
restore_configs
opt_enable COREXZ
exec_test $1 $2 "COREXZ"

#
# Enable Z_DUAL_STEPPER_DRIVERS, Z_DUAL_ENDSTOPS
#
restore_configs
opt_enable_adv Z_DUAL_STEPPER_DRIVERS Z_DUAL_ENDSTOPS
pins_set RAMPS X_MAX_PIN -1
opt_add_adv Z2_MAX_PIN 2
opt_enable USE_XMAX_PLUG
exec_test $1 $2 "Z_DUAL_STEPPER_DRIVERS, Z_DUAL_ENDSTOPS"

# Clean up
restore_configs
