From 3cac8340c7c822ecda3783286196c6bc4cdec66a Mon Sep 17 00:00:00 2001 From: Mart Lubbers Date: Mon, 23 Jan 2017 10:31:52 +0100 Subject: [PATCH] Button implemented --- Makefile | 6 +++++- int/interface.c | 5 ++++- int/interface_linux.c | 2 +- int/interpret.c | 3 +-- int/main.c | 11 +++++------ mTaskInterpret.icl | 8 ++++---- miTask.icl | 36 +++++++++++++++++++++++++----------- 7 files changed, 45 insertions(+), 26 deletions(-) diff --git a/Makefile b/Makefile index 5f19a89..6ca4681 100644 --- a/Makefile +++ b/Makefile @@ -25,9 +25,12 @@ CLMLIBS:=\ BINARIES:= mTaskExamples mTaskInterpret miTask -all: $(BINARIES) int/mTaskSymbols.h +all: CleanSerial/Clean\ System\ Files/TTY.o $(BINARIES) int/mTaskSymbols.h + +CleanSerial/Clean\ System\ Files/TTY.o: make -C CleanSerial + int/mTaskSymbols.h: mTaskMakeSymbols ./$< -nr > $@ @@ -37,3 +40,4 @@ int/mTaskSymbols.h: mTaskMakeSymbols clean: $(RM) -r $(BINARIES) Clean\ System\ Files miTask-data + make -C CleanSerial clean diff --git a/int/interface.c b/int/interface.c index 7fcc148..bec4f09 100644 --- a/int/interface.c +++ b/int/interface.c @@ -39,6 +39,9 @@ void write_dpin(uint8_t i, bool b) bool read_dpin(uint8_t i) { + if(i == 3){ + return palReadLine(LINE_BUTTON) == PAL_HIGH; + } return palReadLine(dpins[i]) == PAL_HIGH; } @@ -72,13 +75,13 @@ void setup(void) void debug(char *fmt, ...) { +#ifdef DEBUG unsigned int i; write_byte('m'); for(i = 0; ilastrun = cyclestart; -// write_byte('\n'); + write_byte('\n'); } } @@ -93,16 +95,13 @@ int main(int argc, char *argv[]){ sds_init(); task_init(); - while(!input_available()){ - delay(100); - } debug("booting up"); - + write_byte('\n'); while(true){ //Check for newetasks debug("loop"); loop(); - delay(10); + delay(100); } return 0; } diff --git a/mTaskInterpret.icl b/mTaskInterpret.icl index d88c318..21b53c9 100644 --- a/mTaskInterpret.icl +++ b/mTaskInterpret.icl @@ -105,8 +105,8 @@ fmp :: ([BC] -> [BC]) (ByteCode a p) -> ByteCode a q 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] @@ -114,8 +114,8 @@ instance toByteCode String where toByteCode s = undef 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 diff --git a/miTask.icl b/miTask.icl index 6aace41..a1f6e56 100644 --- a/miTask.icl +++ b/miTask.icl @@ -47,10 +47,15 @@ deviceSelectorSerial = accWorld getDevices 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 ||- ( ( @@ -101,21 +106,28 @@ mTaskTask 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) ) )} @@ -128,7 +140,9 @@ mTaskTask ch = 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 @! () -- 2.20.1