#####################################################################
#  Displays
#####################################################################

[board_pins]
aliases:
  # EXP1 header
  EXP1_1=PE8, EXP1_2=PE7,
  EXP1_3=PE9, EXP1_4=PE10,
  EXP1_5=PE12, EXP1_6=PE13,    # Slot in the socket on this side
  EXP1_7=PE14, EXP1_8=PE15,
  EXP1_9=<GND>, EXP1_10=<5V>,

  # EXP2 header
  EXP2_1=PA6, EXP2_2=PA5,
  EXP2_3=PB1, EXP2_4=PA4,
  EXP2_5=PB2, EXP2_6=PA7,      # Slot in the socket on this side
  EXP2_7=PC15, EXP2_8=<RST>,
  EXP2_9=<GND>, EXP2_10=<5V>

[display]
# mini12864 LCD Display
lcd_type: uc1701
cs_pin: EXP1_3
a0_pin: EXP1_4
rst_pin: EXP1_5
encoder_pins: ^EXP2_5, ^EXP2_3
click_pin: ^!EXP1_2
contrast: 63
spi_software_miso_pin: EXP2_1
spi_software_mosi_pin: EXP2_6
spi_software_sclk_pin: EXP2_2
# display_group: __voron_display

[neopixel btt_mini12864]
# To control Neopixel RGB in mini12864 display
pin: EXP1_6
chain_count: 3
initial_RED: 0.1
initial_GREEN: 0.5
initial_BLUE: 0.0
color_order: RGB

# Set RGB values on boot up for each Neopixel.
# Index 1 = display, Index 2 and 3 = Knob
[delayed_gcode setdisplayneopixel]
initial_duration: 1
gcode:
  SET_LED LED=btt_mini12864 RED=0.50 GREEN=0.00 BLUE=0.00 INDEX=1 TRANSMIT=0
  SET_LED LED=btt_mini12864 RED=0.13 GREEN=0.16 BLUE=1.00 INDEX=2 TRANSMIT=0
  SET_LED LED=btt_mini12864 RED=0.13 GREEN=0.16 BLUE=1.00 INDEX=3


#####################################################################
# Display Menu definition
#####################################################################

# Removed items
[menu __main __octoprint]
type: disabled

## Control
[menu __main __control __home]
type: disabled

[menu __main __control __homez]
type: disabled

[menu __main __control __homexy]
type: disabled

##  PreHeat
[menu __main __temp __preheat_pla]
type: disabled

[menu __main __temp __preheat_abs]
type: disabled

##  use own load and unload macro
[menu __main __filament __loadf]
type: disabled

[menu __main __filament __loads]
type: disabled

[menu __main __filament __unloadf]
type: disabled

[menu __main __filament __unloads]
type: disabled

## Control
[menu __main __control __home]
type: disabled

[menu __main __control __homez]
type: disabled

[menu __main __control __homexy]
type: disabled


# Bed Probe
[menu __main __setup __calib __bedprobe]
type: disabled

##  Delta Calibration
[menu __main __setup __calib __delta_calib_auto]
type: disabled

[menu __main __setup __calib __delta_calib_man]
type: disabled


# Added Items to the Stock menu
## Control
[menu __main __control __home]
type: input
enable: {not printer.idle_timeout.state == "Printing"}
name: Home: {['noop', 'ALL', 'XY', 'Z'][menu.input|int]}
input: 0
input_min: 0
input_max: 3
input_step: 1
gcode:
  {%- if menu.event == 'long_click' -%}
    {[' ', 'G28', 'G28 XY', 'G28 Z'][menu.input|int]}
  {%- endif -%}

[menu __main __control __move]
type: input
enable: {not printer.idle_timeout.state == "Printing"}
name: Move: {['FRONT CENTER', 'CENTER', 'REAR CENTER'][menu.input|int]}
input: 0
input_min: 0
input_max: 2
input_step: 1
gcode:
  {%- if menu.event == 'long_click' -%}
    CENTER {['Y=15', '', 'Y=290'][menu.input|int]}
  {%- endif -%}


## Filament
[menu __main __filament __preheat]
type: input
enable: {not printer.idle_timeout.state == "Printing"}
name: Preheat: {['Off', 'ABS', 'PLA', 'PET'][menu.input|int]}
input: 0
input_min: 0
input_max: 3
input_step: 1
gcode:
  {%- if menu.event == 'long_click' -%}
    M104 S{[0, 215, 190, 200][menu.input|int]}
  {%- endif -%}


[menu __main __filament __filament_load]
type: input
enable: {not printer.idle_timeout.state == "Printing"}
name: Filament: {['noop', 'Load', 'Unload', 'Purge (10mm)'][menu.input|int]}
input: 0
input_min: 0
input_max: 3
input_step: 1
gcode:
  {%- if menu.event == 'long_click' -%}
    {% if printer.extruder.can_extrude|lower == 'true' %}
      M83
      G1 {['E0', 'E50 F3000', 'E-75 F3000', 'E10 F300'][menu.input|int]}
      G1 {['E0', 'E35 F300', 'E0', 'E0'][menu.input|int]}
      M82
    {% else %}
      {action_respond_info("extruder not hot enough")}
    {%- endif -%}
  {%- endif -%}


## Calibration
[menu __main __setup __calib __bedprobe]
type: command
enable: {not printer.idle_timeout.state == "Printing"}
name: Bed probe
gcode:
  {%- if printer.toolhead.position.y|float < 270 -%}
    PROBE
  {%- else -%}
    {action_respond_info("Won't probe inunsafe position")}
  {%- endif -%}


## Probe & Endstop Z-Offset calibration
[menu __main __setup __calib __Z_offset]
type: list
enable: {not printer.idle_timeout.state == "Printing"}
name: Z offset

[menu __main __setup __calib __Z_offset __start]
type: input
enable: {not printer.idle_timeout.state == "Printing"}
name: Calibrate: {['noop','Probe','Endstop'][menu.input|int]}
input: 0
input_min: 0
input_max: 2
input_step: 1
gcode:
  {%- if menu.event == 'long_click' -%}
    {menu.back()}
  {%- endif -%}
  {%- if menu.input|int == 1 -%}
    {% if "xyz" in printer.toolhead.homed_axes %}
      {action_respond_info("Start Probe calibration")}
      CENTER
      PROBE_CALIBRATE
    {%- else -%}
      {action_respond_info("Printer not homed")}
    {%- endif -%}
  {%- elif menu.input|int == 2 -%}
    {% if "xyz" in printer.toolhead.homed_axes %}
      {action_respond_info(" Start Z-Endstop calibration")}
      CENTER
      Z_ENDSTOP_CALIBRATE
    {%- else -%}
      {action_respond_info("Printer not homed")}
    {%- endif -%}
  {%- endif -%}


[menu __main __setup __calib __Z_offset __move_z]
type: input
name: Move Z: {'%03.2f' % menu.input}
input: {printer.gcode_move.gcode_position.z}
input_step: 1
realtime: True
gcode:
  {%- if menu.event == 'change' -%}
    G1 Z{'%.2f' % menu.input}
  {%- elif menu.event == 'long_click' -%}
    G1 Z{'%.2f' % menu.input}
    SAVE_GCODE_STATE NAME=__move__axis
    G91
    G1 Z2
    G1 Z-2
    RESTORE_GCODE_STATE NAME=__move__axis
  {%- endif -%}

[menu __main __setup __calib __Z_offset __test_z]
type: input
name: Test Z: {['-1.0', '-0.5', '-0.1', '-.05', '-.01', '0.0', '+0.01', '+0.05', '+0.1', '+0.5', '+1.0'][menu.input|int]}
input: 5
input_min: 0
input_max: 10
input_step: 1
gcode:
  {%- if menu.event == 'long_click' -%}
    TESTZ Z={['-1.0', '-0.5', '-0.1', '-.05', '-.01', '0', '+0.01', '+0.05', '+0.1', '+0.5', '+1.0'][menu.input|int]}
  {%- endif -%}

[menu __main __setup __calib __Z_offset __test_z_live]
type: input
name: Test Z : {'%03.3f' % menu.input}
input: 0
input_min: -5.0
input_max: 5.0
input_step: 0.01
realtime: True
gcode:
  {%- if menu.event == 'long_click' -%}
    TESTZ Z={'%.3f' % menu.input}
  {%- endif -%}

[menu __main __setup __calib __Z_offset __accept]
type: command
name: Accept
gcode: ACCEPT

[menu __main __setup __calib __Z_offset __abort]
type: command
name: Abort
gcode: ABORT

[menu __main __setup __calib __Z_offset __saveconfig]
type: command
name: Save config
gcode: SAVE_CONFIG