Hi eveyone here is an update on this. So I'm stil lnot able to have Prusa's macro to work, in the meantime I did two things , one is working the second remains to be tested. I needed to implement the first solution in deamon.g to accomodate an ongoing long print (2weeks) that didn't have a single macro called on tool changes.
This assumes that succesive layer times have little variations (successive tool work times are approximately similar) which is the case for me with variations from layer to layer being a couple tens of seceonds at max . The thing is, every tool is going to be preheated regardless of their future usage, which is OK in my case as both tools are used until the last layers
Here is what i have in deamon.g
if state.status == "processing"
if exists(global.previousTool)
if state.currentTool != global.previousTool ; executes right after tool change
G10 P{abs(state.currentTool - 1)} R160
if exists(global.newToolchangeTime) ; intitialize previous tool change time with last know tool change time
if !exists(global.previousToolchangeTime)
global previousToolchangeTime = global.newToolchangeTime
else
set global.previousToolchangeTime = global.newToolchangeTime
if !exists(global.newToolchangeTime) ; update tool change time
global newToolchangeTime = state.time
else
set global.newToolchangeTime = state.time
echo "Last Toolchange time was :", global.previousToolchangeTime ; see if it works as intended
echo "New Toolchange time is :", global.newToolchangeTime
if exists(global.newToolchangeTime) && exists(global.previousToolchangeTime)
echo "Calculating time between last tool changes..."
if state.currentTool == 0
if !exists(global.lasttoolworkduration0)
global lasttoolworkduration1 = global.newToolchangeTime - global.previousToolchangeTime
else
set global.lasttoolworkduration1 = global.newToolchangeTime - global.previousToolchangeTime
if state.currentTool == 1
if !exists(global.lasttoolworkduration1)
global lasttoolworkduration0 = global.newToolchangeTime - global.previousToolchangeTime
else
set global.lasttoolworkduration0 = global.newToolchangeTime - global.previousToolchangeTime
if exists(global.lasttoolworkduration0)
echo "It took", global.lasttoolworkduration1, "s between two tool changes from 1 to 0"
else
echo "Not enough tool changes were sampled"
if exists(global.lasttoolworkduration1)
echo "It took", global.lasttoolworkduration0, "s between two tool changes from 0 to 1"
else
echo "Not enough tool changes were sampled"
if !exists(global.previousTool)
global previousTool = state.currentTool
else
set global.previousTool = state.currentTool
if !exists(global.preheatingoffset)
global preheatingoffset = 40
else
set global.preheatingoffset = 40 ; start heating up 60 seconds before next layer
if exists(global.previousLayerTime) && exists(global.lasttoolworkduration0) && exists(global.lasttoolworkduration1)
if state.currentTool == 1 && state.time >= global.newToolchangeTime + global.lasttoolworkduration1 - global.preheatingoffset
echo "Preheating extruder ", abs(state.currentTool - 1), "..."
G10 P{abs(state.currentTool - 1)} R{heat.heaters[abs(state.currentTool -1) + 1].active}
;G10 P{state.currentTool} R150
elif state.currentTool == 0 && state.time >= global.newToolchangeTime + global.lasttoolworkduration0 - global.preheatingoffset
echo "Preheating extruder ", abs(state.currentTool - 1), "..."
G10 P{abs(state.currentTool - 1)} R{heat.heaters[abs(state.currentTool -1) + 1].active}
;G10 P{state.currentTool} R150
Now the goal, and second solution will be to execute a macro called preheatextruders.g in prusaslicer tool change custom gcode that will handle the Time globals
and let deamon.g do the regular checks
It's DIY and has a rather narrow scope i know but I hope it can help others in similar situations