Button implemented
authorMart Lubbers <mart@martlubbers.net>
Mon, 23 Jan 2017 09:31:52 +0000 (10:31 +0100)
committerMart Lubbers <mart@martlubbers.net>
Mon, 23 Jan 2017 09:31:52 +0000 (10:31 +0100)
Makefile
int/interface.c
int/interface_linux.c
int/interpret.c
int/main.c
mTaskInterpret.icl
miTask.icl

index 5f19a89..6ca4681 100644 (file)
--- 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
index 7fcc148..bec4f09 100644 (file)
@@ -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; i<strlen(fmt); i++){
                write_byte((uint8_t)fmt[i]);
        }
        write_byte('\n');
-#ifdef DEBUG
 #endif
        (void)fmt;
 }
index 1ec9347..381df88 100644 (file)
@@ -49,7 +49,6 @@ bool input_available(void){
                pdie("select");
        if(!FD_ISSET(fd, &fds))
                return false;
-       read(fd, &bt, 1);
        return true;
 }
 
@@ -149,6 +148,7 @@ void debug(char *fmt, ...)
        va_list ap;
        va_start(ap, fmt);
        vfprintf(stderr, fmt, ap);
+       fprintf(stderr, "\n");
        va_end(ap);
 }
 
index 0a92dd0..c3c6bd1 100644 (file)
@@ -10,8 +10,7 @@
 #ifdef STM
 #define trace(op, ...) ;
 #else
-#define trace(op, ...) ;
-//printf("pc: %d, sp: %d, op: " op "\n", pc, sp, ##__VA_ARGS__);
+#define trace(op, ...) printf("pc: %d, sp: %d, op: " op "\n", pc, sp, ##__VA_ARGS__);
 #endif
 
 void run_task(struct task *t)
index dddd328..9b6a88b 100644 (file)
@@ -40,7 +40,9 @@ void read_message(void)
                        break;
                case MSG_GET_TASK:
                        debug("Receiving a task");
+                       write_dpin(0, true);
                        task_register();
+                       write_dpin(0, false);
                        break;
                case '\0':
                        break;
@@ -76,7 +78,7 @@ void loop(void)
                debug("Current task to run: %d", ct);
                run_task(curtask);
                curtask->lastrun = 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;
 }
index d88c318..21b53c9 100644 (file)
@@ -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
index 6aace41..a1f6e56 100644 (file)
@@ -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 @! ()