module Hardware.SiClock.MorseKeyer
where
import Control.Monad
import Control.Monad.IO.Class
import Control.Concurrent (threadDelay)
import Hardware.SiClock
test :: IO ()
test = runSynth $ sendMsg someFreq someMsg
someMsg :: String
someMsg ="-.-. --.- -.-. --.- ... .. ..... ...-- ..... .---- - . ... - .- -... -.-. -.."
someFreq :: Frequency
someFreq = 28004452
ditLen :: Int
ditLen = 60*1000
sendMsg :: Frequency -> String -> Synth ()
sendMsg freq msg = do
void $ setDividers PLL_A CLK_0 freq
pllReset
forM_ msg sendSym
sendSym :: Char -> Synth ()
sendSym sym = case sym of
'.' -> do rfOn >> ditDelay >> rfOff >> ditDelay
'-' -> do rfOn >> daDelay >> rfOff >> ditDelay
' ' -> do ditDelay >> ditDelay
other -> liftIO $ print ("ignoring Symbol",other)
ditDelay :: Synth ()
ditDelay = liftIO $ threadDelay ditLen
daDelay :: Synth ()
daDelay = ditDelay >> ditDelay >> ditDelay
rfOn :: Synth ()
rfOn = clk0_On
rfOff :: Synth ()
rfOff = clk0_Off