fmp f b = BC \s->let (bc, s`) = runBC b s in (f bc, s`)
instance toByteCode Bool where
- toByteCode True = [toChar 1]
- toByteCode False = [toChar 0]
+ toByteCode True = [toChar 0, toChar 1]
+ toByteCode False = [toChar 0, toChar 0]
instance toByteCode Int where toByteCode n = map toChar [n/256,n rem 256]
instance toByteCode Long where toByteCode (L n) = toByteCode n
instance toByteCode Char where toByteCode c = [c]
instance toByteCode Button where toByteCode s = [toChar $ consIndex{|*|} s]
instance toChar Pin where
- toChar (Digital p) = toChar $ consIndex{|*|} p + 1
- toChar (Analog p) = toChar $ consIndex{|*|} p + 1
+ toChar (Digital p) = toChar $ consIndex{|*|} p
+ toChar (Analog p) = toChar $ consIndex{|*|} p
derive gPrint BC, AnalogPin, Pin, DigitalPin
derive consIndex BC, Pin, Button
isTTY s = not (isEmpty (filter (flip startsWith s) prefixes))
prefixes = ["ttyS", "ttyACM", "ttyUSB", "tty.usbserial"]
+derive class iTask SerTCP
+:: SerTCP = Serial | TCP
+
mTaskTask :: (Shared ([MTaskMSGRecv],Bool,[MTaskMSGSend],Bool)) -> Task ()
mTaskTask ch =
-// deviceSelectorNetwork >>= \(p,h)->syncNetworkChannel h p "\n" decode encode ch ||-
- deviceSelectorSerial >>= \(s,set)->syncSerialChannel s set decode encode ch ||-
+ (enterInformation "Choose" [] >>= \st->case st of
+ Serial = deviceSelectorSerial >>= \(s,set)->syncSerialChannel s set decode encode ch
+ TCP = deviceSelectorNetwork >>= \(p,h)->syncNetworkChannel h p "\n" decode encode ch
+ ) ||-
sendMsg msgs ch ||-
(
(
sdsShares = makeShares st
- (msgs, st) = toMessages 1000 (toRealByteCode (unMain bc))
+ (msgs, st) = toMessages 500 (toRealByteCode (unMain bc))
bc :: Main (ByteCode () Stmt)
bc = sds \x=1 In sds \pinnetje=1 In {main =
- x =. x +. pinnetje :.
- pub x :.
- digitalWrite D0 (lit False) :.
- digitalWrite D1 (lit False) :.
- digitalWrite D2 (lit False) :.
+ IF (digitalRead D3 ==. lit True) (
+ x =. x +. lit 1 :.
+ pub x
+ ) (
+ noOp
+ ) :.
IF (pinnetje ==. lit 1) (
- digitalWrite D0 (lit True)
+ digitalWrite D0 (lit True) :.
+ digitalWrite D1 (lit False) :.
+ digitalWrite D2 (lit False)
) (
IF (pinnetje ==. lit 2) (
- digitalWrite D1 (lit True)
+ digitalWrite D0 (lit False) :.
+ digitalWrite D1 (lit True) :.
+ digitalWrite D2 (lit False)
) (
+ digitalWrite D0 (lit False) :.
+ digitalWrite D1 (lit False) :.
digitalWrite D2 (lit True)
)
)}
makeShares :: BCState -> [(Int, Shared Int)]
makeShares {sdss=[]} = []
makeShares s=:{sdss=[(i,d):xs]} =
- [(i, sharedStore ("mTaskSDS-" +++ toString i) 1):makeShares {s & sdss=xs}]
+ [(i, ms ("mTaskSDS-" +++ toString i) 1):makeShares {s & sdss=xs}]
+ where
+ ms name i = sdsFocus name (memoryStore name (Just i))
sendMsg :: [MTaskMSGSend] (Shared ([MTaskMSGRecv],Bool,[MTaskMSGSend],Bool)) -> Task ()
sendMsg m ch = upd (\(r,rs,s,ss)->(r,rs,s ++ m,ss)) ch @! ()