Starting sensor support
This commit is contained in:
		
							
								
								
									
										5
									
								
								TODO.md
									
									
									
									
									
								
							
							
						
						
									
										5
									
								
								TODO.md
									
									
									
									
									
								
							@@ -1,6 +1,11 @@
 | 
			
		||||
* [x] try unlink ELF file before uploading - didn't work
 | 
			
		||||
* [x] implement serialPoll
 | 
			
		||||
* [x] try some motors
 | 
			
		||||
* [ ] add `control.interrupt(ms, () => { ... sync function ... })` - running outside regular JS thread
 | 
			
		||||
* [ ] add `//% onlyWhenUsed` on global variable initializers
 | 
			
		||||
* [ ] parse Python field lists into offsets
 | 
			
		||||
 | 
			
		||||
## Further down
 | 
			
		||||
* [ ] have some protocol for restarting user app if it's running (flag file somewhere?)
 | 
			
		||||
* [ ] display panic code on the screen
 | 
			
		||||
* [ ] catch SIGSEGV and panic
 | 
			
		||||
							
								
								
									
										36
									
								
								libs/base/enums.d.ts
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										36
									
								
								libs/base/enums.d.ts
									
									
									
									
										vendored
									
									
										Normal file
									
								
							@@ -0,0 +1,36 @@
 | 
			
		||||
// Auto-generated. Do not edit.
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    declare enum NumberFormat {
 | 
			
		||||
    Int8LE = 1,
 | 
			
		||||
    UInt8LE = 2,
 | 
			
		||||
    Int16LE = 3,
 | 
			
		||||
    UInt16LE = 4,
 | 
			
		||||
    Int32LE = 5,
 | 
			
		||||
    Int8BE = 6,
 | 
			
		||||
    UInt8BE = 7,
 | 
			
		||||
    Int16BE = 8,
 | 
			
		||||
    UInt16BE = 9,
 | 
			
		||||
    Int32BE = 10,
 | 
			
		||||
 | 
			
		||||
    UInt32LE = 11,
 | 
			
		||||
    UInt32BE = 12,
 | 
			
		||||
    Float32LE = 13,
 | 
			
		||||
    Float64LE = 14,
 | 
			
		||||
    Float32BE = 15,
 | 
			
		||||
    Float64BE = 16,
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    declare enum ValType {
 | 
			
		||||
    Undefined = 0,
 | 
			
		||||
    Boolean = 1,
 | 
			
		||||
    Number = 2,
 | 
			
		||||
    String = 3,
 | 
			
		||||
    Object = 4,
 | 
			
		||||
    Function = 5,
 | 
			
		||||
    }
 | 
			
		||||
declare namespace serial {
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// Auto-generated. Do not edit. Really.
 | 
			
		||||
							
								
								
									
										74
									
								
								libs/core/analog.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										74
									
								
								libs/core/analog.ts
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,74 @@
 | 
			
		||||
namespace input {
 | 
			
		||||
    let analogMM: MMap
 | 
			
		||||
 | 
			
		||||
    /*
 | 
			
		||||
    struct_anon_76._fields_ = [
 | 
			
		||||
        ('InPin1', DATA16 * 4),
 | 
			
		||||
        ('InPin6', DATA16 * 4),
 | 
			
		||||
        ('OutPin5', DATA16 * 4),
 | 
			
		||||
        ('BatteryTemp', DATA16),
 | 
			
		||||
        ('MotorCurrent', DATA16),
 | 
			
		||||
        ('BatteryCurrent', DATA16),
 | 
			
		||||
        ('Cell123456', DATA16),
 | 
			
		||||
        ('Pin1', (DATA16 * 300) * 4),
 | 
			
		||||
        ('Pin6', (DATA16 * 300) * 4),
 | 
			
		||||
        ('Actual', UWORD * 4),
 | 
			
		||||
        ('LogIn', UWORD * 4),
 | 
			
		||||
        ('LogOut', UWORD * 4),
 | 
			
		||||
        ('NxtCol', COLORSTRUCT * 4),
 | 
			
		||||
        ('OutPin5Low', DATA16 * 4),
 | 
			
		||||
        ('Updated', DATA8 * 4),
 | 
			
		||||
        ('InDcm', DATA8 * 4),
 | 
			
		||||
        ('InConn', DATA8 * 4),
 | 
			
		||||
        ('OutDcm', DATA8 * 4),
 | 
			
		||||
        ('OutConn', DATA8 * 4),
 | 
			
		||||
    ]
 | 
			
		||||
    */
 | 
			
		||||
 | 
			
		||||
    function init() {
 | 
			
		||||
        if (analogMM) return
 | 
			
		||||
        analogMM = control.mmap("/dev/lms_analog", 1024, 0)
 | 
			
		||||
        if (!analogMM) control.fail("no analog sensor")
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    export function readAnalogPin6(port: number) {
 | 
			
		||||
        init()
 | 
			
		||||
        port = Math.clamp(0, 3, port | 0)
 | 
			
		||||
        return analogMM.getNumber(NumberFormat.UInt16LE, 2 * (port + 4))
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
namespace input {
 | 
			
		||||
    let uartMM: MMap
 | 
			
		||||
 | 
			
		||||
    /*
 | 
			
		||||
    DEVCON = [
 | 
			
		||||
    ('Connection', DATA8 * 4),
 | 
			
		||||
    ('Type', DATA8 * 4),
 | 
			
		||||
    ('Mode', DATA8 * 4),
 | 
			
		||||
    ]
 | 
			
		||||
 | 
			
		||||
    UART = [
 | 
			
		||||
    ('TypeData', (TYPES * 8) * 4),
 | 
			
		||||
    ('Repeat', (UWORD * 300) * 4),
 | 
			
		||||
    ('Raw', ((DATA8 * 32) * 300) * 4),
 | 
			
		||||
    ('Actual', UWORD * 4),
 | 
			
		||||
    ('LogIn', UWORD * 4),
 | 
			
		||||
    ('Status', DATA8 * 4),
 | 
			
		||||
    ('Output', (DATA8 * 32) * 4),
 | 
			
		||||
    ('OutputLength', DATA8 * 4),
 | 
			
		||||
    ]
 | 
			
		||||
    */
 | 
			
		||||
 | 
			
		||||
    function init() {
 | 
			
		||||
        if (uartMM) return
 | 
			
		||||
        uartMM = control.mmap("/dev/lms_uart", 1024, 0)
 | 
			
		||||
        if (!uartMM) control.fail("no uart sensor")
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    function setUartMode(port: number, mode: number) {
 | 
			
		||||
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
@@ -5,6 +5,7 @@
 | 
			
		||||
#include <sys/types.h>
 | 
			
		||||
#include <sys/stat.h>
 | 
			
		||||
#include <fcntl.h>
 | 
			
		||||
#include <sys/ioctl.h>
 | 
			
		||||
 | 
			
		||||
namespace pxt {
 | 
			
		||||
PXT_VTABLE_CTOR(MMap) {
 | 
			
		||||
@@ -28,6 +29,7 @@ namespace control {
 | 
			
		||||
/** Create new file mapping in memory */
 | 
			
		||||
//%
 | 
			
		||||
MMap *mmap(String filename, int size, int offset) {
 | 
			
		||||
    DMESG("mmap %s len=%d off=%d", filename->data, size, offset);
 | 
			
		||||
    int fd = open(filename->data, O_RDWR, 0);
 | 
			
		||||
    if (fd < 0)
 | 
			
		||||
        return 0;
 | 
			
		||||
@@ -41,7 +43,7 @@ MMap *mmap(String filename, int size, int offset) {
 | 
			
		||||
    auto r = new MMap();
 | 
			
		||||
    r->fd = fd;
 | 
			
		||||
    r->length = size;
 | 
			
		||||
    r->data = (uint8_t*)data;
 | 
			
		||||
    r->data = (uint8_t *)data;
 | 
			
		||||
    return r;
 | 
			
		||||
}
 | 
			
		||||
}
 | 
			
		||||
@@ -73,4 +75,11 @@ TNumber getNumber(MMap *buf, NumberFormat format, int offset) {
 | 
			
		||||
int length(MMap *s) {
 | 
			
		||||
    return s->length;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/** Perform ioctl(2) on the underlaying file */
 | 
			
		||||
//%
 | 
			
		||||
void ioctl(MMap *mmap, uint32_t id, Buffer data) {
 | 
			
		||||
    ::ioctl(mmap->fd, id, data->data);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
@@ -14,6 +14,7 @@
 | 
			
		||||
        "screen.ts",
 | 
			
		||||
        "output.cpp",
 | 
			
		||||
        "output.ts",
 | 
			
		||||
        "analog.ts",
 | 
			
		||||
        "shims.d.ts",
 | 
			
		||||
        "enums.d.ts",
 | 
			
		||||
        "dal.d.ts",
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										4
									
								
								libs/core/shims.d.ts
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										4
									
								
								libs/core/shims.d.ts
									
									
									
									
										vendored
									
									
								
							@@ -23,6 +23,10 @@ declare interface MMap {
 | 
			
		||||
    /** Returns the length of a Buffer object. */
 | 
			
		||||
    //% property shim=MMapMethods::length
 | 
			
		||||
    length: int32;
 | 
			
		||||
 | 
			
		||||
    /** Perform ioctl(2) on the underlaying file */
 | 
			
		||||
    //% shim=MMapMethods::ioctl
 | 
			
		||||
    ioctl(id: uint32, data: Buffer): void;
 | 
			
		||||
}
 | 
			
		||||
declare namespace control {
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user