#  _   _                  _          _     
# | \ | |                (_)        | |    
# |  \| | ___  ___  _ __  ___  _____| |___ 
# | . ` |/ _ \/ _ \| '_ \| \ \/ / _ \ / __|
# | |\  |  __/ (_) | |_) | |>  <  __/ \__ \
# |_| \_|\___|\___/| .__/|_/_/\_\___|_|___/
#                  | |                     
#                  |_|                     
#
# Neopixels Configurations - Flsun Speeder Pad
#
# Guislain Cyril


[gcode_macro NEOPIXEL_ON]
description: Turn On Neopixels LEDs
gcode:
  SET_LED_TEMPLATE LED=NeoPixels TEMPLATE=""
  SET_LED LED=NeoPixels RED=1.0 GREEN=1.0 BLUE=1.0 SYNC=0 TRANSMIT=1


[gcode_macro NEOPIXEL_OFF]
description: Turn Off Neopixels LEDs
gcode:
  SET_LED_TEMPLATE LED=NeoPixels TEMPLATE=""
  SET_LED LED=NeoPixels RED=0.0 GREEN=0.0 BLUE=0.0 SYNC=0 TRANSMIT=1

      
[gcode_macro NEOPIXEL_BLUE]
description: Turn On Neopixels LEDs in blue
gcode:
  SET_LED_TEMPLATE LED=NeoPixels TEMPLATE=""
  SET_LED LED=NeoPixels RED=0.0 GREEN=0.0 BLUE=1.0 SYNC=0 TRANSMIT=1


[gcode_macro NEOPIXEL_RED]
description: Turn On Neopixels LEDs in red
gcode:
  SET_LED_TEMPLATE LED=NeoPixels TEMPLATE=""
  SET_LED LED=NeoPixels RED=1.0 GREEN=0.0 BLUE=0.0 SYNC=0 TRANSMIT=1


[gcode_macro NEOPIXEL_GREEN]
description: Turn On Neopixels LEDs in green
gcode:
  SET_LED_TEMPLATE LED=NeoPixels TEMPLATE=""
  SET_LED LED=NeoPixels RED=0.0 GREEN=1.0 BLUE=0.0 SYNC=0 TRANSMIT=1


[gcode_macro NEOPIXEL_YELLOW]
description: Turn On Neopixels LEDs in yellow
gcode:
  SET_LED_TEMPLATE LED=NeoPixels TEMPLATE=""
  SET_LED LED=NeoPixels RED=1.0 GREEN=1.0 BLUE=0.0 SYNC=0 TRANSMIT=1
  

[gcode_macro NEOPIXEL_ORANGE]
description: Turn On Neopixels LEDs in orange
gcode:
  SET_LED_TEMPLATE LED=NeoPixels TEMPLATE=""
  SET_LED LED=NeoPixels RED=1.0 GREEN=0.31 BLUE=0.0 SYNC=0 TRANSMIT=1


[gcode_macro NEOPIXEL_VIOLET]
description: Turn On Neopixels LEDs in violet
gcode:
  SET_LED_TEMPLATE LED=NeoPixels TEMPLATE=""
  SET_LED LED=NeoPixels RED=1.0 GREEN=0.0 BLUE=1.0 SYNC=0 TRANSMIT=1


[gcode_macro HOTEND_GLOW]
description: Turn on LEDs based on nozzle temperature (All LEDs)
gcode:
  NEOPIXEL_DISPLAY LED=NeoPixels TYPE=extruder_temp MODE=glow


[gcode_macro HOTEND_PROGRESS]
description: Turn on LEDs based on nozzle temperature (LED by LED)
gcode:
  NEOPIXEL_DISPLAY LED=NeoPixels TYPE=extruder_temp MODE=progress


[gcode_macro BED_GLOW]
description: Turn on the LEDs based on bed temperature (All LEDs)
gcode:
  NEOPIXEL_DISPLAY LED=NeoPixels TYPE=bed_temp MODE=glow


[gcode_macro BED_PROGRESS]
description: Turn on the LEDs based on bed temperature (LED by LED)
gcode:
  NEOPIXEL_DISPLAY LED=NeoPixels TYPE=bed_temp MODE=progress


[gcode_macro PERCENT_GLOW]
description: Turn on LEDs based on printing progress (All LEDs)
gcode:
  NEOPIXEL_DISPLAY LED=NeoPixels TYPE=print_percent MODE=glow


[gcode_macro PERCENT_PROGRESS]
description: Turn on LEDs based on printing progress (LED by LED)
gcode:
  NEOPIXEL_DISPLAY LED=NeoPixels TYPE=print_percent MODE=progress


[gcode_macro SPEED_GLOW]
description: Turn on LEDs based on printing speed (All LEDs)
gcode:
  NEOPIXEL_DISPLAY LED=NeoPixels TYPE=printer_speed MODE=glow


[gcode_macro SPEED_PROGRESS]
description: Turn on LEDs based on printing speed (LED by LED)
gcode:
  NEOPIXEL_DISPLAY LED=NeoPixels TYPE=printer_speed MODE=progress  


[gcode_macro NEOPIXEL_DISPLAY]
gcode:
  {% set led = params.LED %}
  {% set type = params.TYPE %}
  {% set mode = params.MODE %}
  {% set my_neopixel = printer.configfile.config['neopixel ' ~ led] %}
  {% if mode == 'progress' %}
  {% for i in range(my_neopixel.chain_count|int) %}
  SET_LED_TEMPLATE LED={led} INDEX={i+1} TEMPLATE={'led_' ~ type ~ '_' ~ mode} param_led_num={i+1} param_led_total={my_neopixel.chain_count|int}
  {% endfor %}
  {% endif %}
  {% if mode == 'glow' %}
  SET_LED_TEMPLATE LED={led} TEMPLATE={'led_' ~ type ~ '_' ~ mode}
  {% endif %}


[display_template led_extruder_temp_glow]
text:
  {% if printer.extruder.target > 0.0 %}
  {%  set temp = printer.extruder.target %}
  {% else %}
  {% set temp = printer.configfile.config.extruder.max_temp %}
  {% endif %}
  {% set ratio = printer.extruder.temperature / temp|float %}
  {ratio}, 0.0, {1-ratio}, 0.0


[display_template led_extruder_temp_progress]
param_led_num:  0
param_led_total: 1
text:
  {% if printer.extruder.target > 0.0 %}
  {%  set temp = printer.extruder.target %}
  {% else %}
  {% set temp = printer.configfile.config.extruder.max_temp %}
  {% endif %}
  {% set ratio = printer.extruder.temperature / temp|float %}
  {% set led_ratio = param_led_num|float / param_led_total %}
  {% if ratio > led_ratio %}
  {led_ratio}, 0.0, 0.0, 0.0
  {% else %}
  0.0, 0.0, 0.0, 0.0
  {% endif %}


[display_template led_bed_temp_glow]
text:
  {% if printer.heater_bed.target > 0.0 %}
  {%  set temp = printer.heater_bed.target %}
  {% else %}
  {% set temp = printer.configfile.config.heater_bed.max_temp %}
  {% endif %}
  {% set ratio = printer.heater_bed.temperature / temp|float %}
  {ratio}, 0.0, {1-ratio}, 0.0


[display_template led_bed_temp_progress]
param_led_num:  0
param_led_total: 1
text:
  {% if printer.heater_bed.target > 0.0 %}
  {%  set temp = printer.heater_bed.target %}
  {% else %}
  {% set temp = printer.configfile.config.heater_bed.max_temp %}
  {% endif %}
  {% set ratio = printer.heater_bed.temperature / temp|float %}
  {% set led_ratio = param_led_num|float / param_led_total %}
  {% if ratio > led_ratio %}
  {led_ratio}, 0.0, 0.0, 0.0
  {% else %}
  0.0, 0.0, 0.0, 0.0
  {% endif %}


[display_template led_print_percent_glow]
text:
  {% set ratio = printer.virtual_sdcard.progress %}
  0.0, {ratio}, 0.0, 0.0


[display_template led_print_percent_progress]
param_led_num:  0
param_led_total: 1
text:
  {% set ratio = printer.virtual_sdcard.progress %}
  {% set led_ratio   = param_led_num|float / param_led_total %}
  {% if ratio > led_ratio %}
  0.0, {led_ratio}, 0.0, 0.0
  {% else %}
  0.0, 0.0, 0.0, 0.0
  {% endif %}


[display_template led_printer_speed_glow]
text:
  {% set ratio  = printer.motion_report.live_velocity|float /  printer.configfile.config.printer.max_velocity|float %}
  0.0, {ratio}, 0.0, 0.0


[display_template led_printer_speed_progress]
param_led_num:  0
param_led_total: 1
text:
  {% set ratio  = printer.motion_report.live_velocity|float /  printer.configfile.config.printer.max_velocity|float %}
  {% set led_ratio    = param_led_num|float / param_led_total %}
  {% if ratio > led_ratio %}
  0.0, {led_ratio}, 0.0, 0.0
  {% else %}
  0.0, 0.0, 0.0, 0.0
  {% endif %}
