module Data.GCode.Canon where
import Data.ByteString (ByteString)
import Data.GCode.Types (Axes, zeroAxes)
import qualified Data.Map
data Plane = XY | YZ | ZX | UV | WU | VW
deriving (Show, Eq, Ord)
data CutterCompenstationSide =
CutterCompensationRight
| CutterCompensationLeft
| CutterCompensationOff
deriving (Show, Eq, Ord)
type Speed = Double
type Seconds = Double
data RotationDirection = ClockWise | CounterClockWise
deriving (Show, Eq, Ord)
data LengthUnit = Inches | MilliMeters | CentiMeters | Meters
deriving (Show, Eq, Ord)
data HeaterType = HeatedExtruder | HeatedBed | HeatedChamber
deriving (Show, Eq, Ord)
data Heater = Heater HeaterType (Maybe Int)
deriving (Show, Eq, Ord)
data CompensationMode =
NoCompensation
| LengthTable
| Dynamic Axes
| Add Int
deriving (Show, Eq, Ord)
data ArcParams = ArcParams {
arcFirstEnd :: Double
, arcSecondEnd :: Double
, arcFirstAxis :: Double
, arcSecondAxis :: Double
, arcRotation :: Int
, arcAxisEndPoint :: Double
, arcA :: Double
, arcB :: Double
, arcC :: Double
, arcU :: Double
, arcV :: Double
, arcW :: Double
} deriving (Eq, Show, Ord)
data Canon =
StraightTraverse Axes
| StraightFeed Axes
| StraightProbe Axes
| SetCoords Axes
| ArcFeed ArcParams
| ProgramEnd
| SetFeedRate Speed
| SetTraverseRate Speed
| PlaneSelect Plane
| PauseSeconds Double
| SpindleStart {
spindleDirection :: RotationDirection
, spindleWaitForSpeed :: Bool
}
| SpindleStop
| SpindleSpeed Speed
| CoolantMist
| CoolantFlood
| CoolantStop
| ToolSelect Int
| ToolChange
| ToolLengthCompensation CompensationMode
| FanOn
| FanOff
| SetTemperature Heater Double
| SetTemperatureWait Heater Double
| CancelWaitTemperature
| LevelBed
| DisableMotors Axes
| DisplayMessage ByteString
| Comment ByteString
deriving (Show, Eq, Ord)
data CanonState = CanonState {
canonPosition :: Axes
, canonTraverseRate :: Speed
, canonFeedRate :: Speed
, canonPlane :: Plane
} deriving (Show, Eq, Ord)
initCanonState :: CanonState
initCanonState = CanonState {
canonPosition = zeroAxes
, canonTraverseRate = 0
, canonFeedRate = 0
, canonPlane = XY
}
stepCanon :: CanonState -> Canon -> CanonState
stepCanon s (StraightTraverse a) = s { canonPosition = Data.Map.union a (canonPosition s) }
stepCanon s (StraightFeed a) = s { canonPosition = Data.Map.union a (canonPosition s) }
stepCanon s (SetFeedRate r) = s { canonFeedRate = r }
stepCanon s (SetTraverseRate r) = s { canonTraverseRate = r }
stepCanon s (SetCoords a) = s { canonPosition = Data.Map.union a (canonPosition s) }
stepCanon s (PlaneSelect p) = s { canonPlane = p }
evalCanon :: (CanonState -> CanonState -> Canon -> [a])
-> [Canon]
-> [a]
evalCanon f cs = go initCanonState cs
where
go _ [] = []
go st (c:rest) =
let
newSt = stepCanon st c
in (f st newSt c) ++ (go newSt rest)