LINE_ARD_D14, LINE_ARD_D15};
void write_dpin(uint8_t i, bool b)
{
- if(i == 0){ palWriteLine(LINE_LED1, b ? PAL_HIGH : PAL_LOW);
- } else if(i == 1){ palWriteLine(LINE_LED2, b ? PAL_HIGH : PAL_LOW);
- } else if(i == 2){ palWriteLine(LINE_LED3, b ? PAL_HIGH : PAL_LOW);
- }
palWriteLine(dpins[i], b ? PAL_HIGH : PAL_LOW);
}
(void) i;
}
+void led_on(uint8_t i)
+{
+ if(i == 0){
+ palWriteLine(LINE_LED1, PAL_HIGH);
+ } else if(i == 1){
+ palWriteLine(LINE_LED2, PAL_HIGH);
+ } else if(i == 2){
+ palWriteLine(LINE_LED3, PAL_HIGH);
+ }
+}
+
+void led_off(uint8_t i)
+{
+ if(i == 0){
+ palWriteLine(LINE_LED1, PAL_LOW);
+ } else if(i == 1){
+ palWriteLine(LINE_LED2, PAL_LOW);
+ } else if(i == 2){
+ palWriteLine(LINE_LED3, PAL_LOW);
+ }
+}
+
long millis(void){
return ST2MS(chVTGetSystemTime());
}
void write_apin(uint8_t i, uint8_t a);
uint8_t read_apin(uint8_t i);
+void led_on(uint8_t i);
+void led_off(uint8_t i);
+
long millis(void);
bool input_available(void);
void delay(long ms);
write_dpin(program[pc++], stack[sp-1]);
sp--;
break;
+ case BCLEDON: trace("LedOn(%d)", program[pc]);
+ led_on(program[pc++]);
+ break;
+ case BCLEDOFF: trace("LedOn(%d)", program[pc]);
+ led_off(program[pc++]);
+ break;
default:
trace("unrecognized");
die("Unrecognized command: %d", program[pc-1]);
#define BCJMP 20
#define BCJMPT 21
#define BCJMPF 22
-#define BCSERIALAVAIL 23
-#define BCSERIALPRINT 24
-#define BCSERIALPRINTLN 25
-#define BCSERIALREAD 26
-#define BCSERIALPARSEINT 27
-#define BCANALOGREAD 28
-#define BCANALOGWRITE 29
-#define BCDIGITALREAD 30
-#define BCDIGITALWRITE 31
-#define BCTEST 32
+#define BCLEDON 23
+#define BCLEDOFF 24
+#define BCSERIALAVAIL 25
+#define BCSERIALPRINT 26
+#define BCSERIALPRINTLN 27
+#define BCSERIALREAD 28
+#define BCSERIALPARSEINT 29
+#define BCANALOGREAD 30
+#define BCANALOGWRITE 31
+#define BCDIGITALREAD 32
+#define BCDIGITALWRITE 33
+#define BCTEST 34
#endif
:: DigitalPin
= D0 | D1 | D2 | D3 | D4 | D5 |D6 | D7 | D8 | D9 | D10 | D11 | D12 | D13
:: AnalogPin = A0 | A1 | A2 | A3 | A4 | A5
+:: UserLED = LED1 | LED2 | LED3
:: PinMode = INPUT | OUTPUT | INPUT_PULLUP
:: Pin = Digital DigitalPin | Analog AnalogPin
delay :: (v Long p) -> (v Long Expr)
millis :: (v Long Expr)
+class userLed v where
+ ledOn :: UserLED -> (v () Stmt)
+ ledOff :: UserLED -> (v () Stmt)
+
class pio p t where pio :: p -> v t Upd | aIO v & dIO v
instance pio AnalogPin Int
instance pio AnalogPin Bool
| BCJmp Int
| BCJmpT Int
| BCJmpF Int
+ //UserLED
+ | BCLedOn [Char]
+ | BCLedOff [Char]
//Serial
| BCSerialAvail
| BCSerialPrint
instance toByteCode String
instance toByteCode Long
instance toByteCode Button
+instance toByteCode UserLED
instance toChar Pin
instance arith ByteCode
instance boolExpr ByteCode
instance analogIO ByteCode
instance digitalIO ByteCode
+instance userLed ByteCode
//instance If ByteCode Stmt Stmt Stmt
//instance If ByteCode e Stmt Stmt
//instance If ByteCode Stmt e Stmt
bclength (BCAnalogWrite _) = 2
bclength (BCDigitalRead _) = 2
bclength (BCDigitalWrite _) = 2
+bclength (BCLedOn _) = 2
+bclength (BCLedOff _) = 2
bclength (BCJmp i) = 2
bclength (BCJmpT i) = 2
bclength (BCJmpF i) = 2
(BCAnalogWrite i) = [toChar i]
(BCDigitalRead i) = [toChar i]
(BCDigitalWrite i) = [toChar i]
+ (BCLedOn i) = i
+ (BCLedOff i) = i
(BCJmp i) = [toChar i]
(BCJmpT i) = [toChar i]
(BCJmpF i) = [toChar i]
instance toByteCode Char where toByteCode c = [c]
instance toByteCode String where toByteCode s = undef
instance toByteCode Button where toByteCode s = [toChar $ consIndex{|*|} s]
+instance toByteCode UserLED where toByteCode s = [toChar $ consIndex{|*|} s]
instance toChar Pin where
toChar (Digital p) = toChar $ consIndex{|*|} p
toChar (Analog p) = toChar $ consIndex{|*|} p
derive gPrint BC, AnalogPin, Pin, DigitalPin
-derive consIndex BC, Pin, Button
+derive consIndex BC, Pin, Button, UserLED
derive consName BC, Pin, Button
instance arith ByteCode where
serialRead = retrn [BCSerialRead]
serialParseInt = retrn [BCSerialParseInt]
+instance userLed ByteCode where
+ ledOn l = retrn [BCLedOn $ toByteCode l]
+ ledOff l = retrn [BCLedOff $ toByteCode l]
+
instance zero BCState where
zero = {freshl=[1..], freshs=[1..], sdss=[]}
# (bc, gtmap) = computeGotos bc 0
= (join "\n" $ map readable (map (implGotos gtmap) bc), st)
-//Start :: String
-//Start = toReadableByteCode bc
-// where
-// bc :: ByteCode Int Expr
-// bc = (lit 36 +. lit 42) +. lit 44
toMessages :: Int (String, BCState) -> ([MTaskMSGSend], BCState)
toMessages interval (bytes, st=:{sdss}) = ([MTSds i (toString b)\\(i,b)<-sdss] ++ [MTTask interval bytes], st)
toSDSUpdate i v = [MTUpd i (to16bit v)]
Start = toMessages 500 $ toRealByteCode (unMain bc)
-//Start = fst $ toReadableByteCode $ unMain bc
where
bc = sds \x=5 In
sds \y=4 In
{main = If (y ==. lit 0) (pub x) (x =. x *. y :. y =. y -. lit 1)}
-//pub :: (ByteCode a b) -> ByteCode a b
-//pub x = fmp makePub x
-
to16bit :: Int -> String
to16bit i = toString (toChar (i/256)) +++ toString (toChar (i rem 256))
import TTY
derive class iTask Queue, TTYSettings, Parity, BaudRate, ByteSize
-derive class iTask MTaskMSGRecv, MTaskMSGSend, SerTCP
+derive class iTask MTaskMSGRecv, MTaskMSGSend, SerTCP, UserLED
:: SerTCP = Serial | TCP
:: *Resource | TTYd !*TTY
noOp
) :.
IF (pinnetje ==. lit 1) (
- digitalWrite D0 (lit True)
+ ledOn LED1
) (
IF (pinnetje ==. lit 2) (
- digitalWrite D1 (lit True)
+ ledOn LED2
) (
- digitalWrite D2 (lit True)
+ ledOn LED3
)
)}
-bc2 :: DigitalPin -> Main (ByteCode () Stmt)
-bc2 d = {main = digitalWrite d (lit True) :. noOp}
+bc2 :: UserLED -> Main (ByteCode () Stmt)
+bc2 d = {main = ledOn d}
-bc3 :: DigitalPin -> Main (ByteCode () Stmt)
-bc3 d = {main = digitalWrite d (lit False) :. noOp}
+bc3 :: UserLED -> Main (ByteCode () Stmt)
+bc3 d = {main = ledOff d}
withDevice :: ((Shared ([MTaskMSGRecv],[MTaskMSGSend],Bool)) -> Task a) -> Task a | iTask a
withDevice \ch->
sendMsg msgs ch
||- processMessages ch messageShare sdsShares
- ||- forever (enterChoice "Choose led to enable" [] [D0, D1, D2]
+ ||- forever (enterChoice "Choose led to enable" [] [LED1, LED2, LED3]
>>= \p->sendMsg (fst (makeMsgs 0 (bc2 p))) ch)
- ||- forever (enterChoice "Choose led to disable" [] [D0, D1, D2]
+ ||- forever (enterChoice "Choose led to disable" [] [LED1, LED2, LED3]
>>= \p->sendMsg (fst (makeMsgs 0 (bc3 p))) ch)
||- viewSharedInformation "channels" [ViewWith lens] ch
||- viewSharedInformation "messages" [] messageShare
| id == i = set ((toInt d.[0])*265 + toInt d.[1]) sh @! ()
= updateSDSs xs m n
updateSDSs _ m mtm = case mtm of
- MTMessage s = upd (\l->take 20 [s:l]) m @! ()
- mta=:(MTTaskAdded _) = upd (\l->take 20 [toString mta:l]) m @! ()
+ MTMessage s = upd (\l->take 5 [s:l]) m @! ()
+ mta=:(MTTaskAdded _) = upd (\l->take 5 [toString mta:l]) m @! ()
_ = return ()
lens :: ([MTaskMSGRecv], [MTaskMSGSend],Bool) -> ([String], [String])