Interface layer for the mbed boards ready for the JAVA library
Dependencies: C12832 LM75B MMA7660 mbed FXOS8700Q
Fork of frdm_serial by
comms.cpp@4:39e949908fc5, 2015-12-01 (annotated)
- Committer:
- Condo2k4
- Date:
- Tue Dec 01 15:00:12 2015 +0000
- Revision:
- 4:39e949908fc5
- Child:
- 5:d9f8c2f63323
Various updates.; - LEDs, LCD and Temp working.; - Interrupts cannot interfere with data transmits.; - Can read from mag and accel, but cannot confirm returned values are correct yet.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Condo2k4 | 4:39e949908fc5 | 1 | |
Condo2k4 | 4:39e949908fc5 | 2 | #include "comms.h" |
Condo2k4 | 4:39e949908fc5 | 3 | |
Condo2k4 | 4:39e949908fc5 | 4 | DataSerial::DataSerial(PinName tx, PinName rx) : Serial(tx,rx,NULL) {} |
Condo2k4 | 4:39e949908fc5 | 5 | |
Condo2k4 | 4:39e949908fc5 | 6 | DataSerial::~DataSerial() {} |
Condo2k4 | 4:39e949908fc5 | 7 | |
Condo2k4 | 4:39e949908fc5 | 8 | void DataSerial::sendFloat(float &f) { |
Condo2k4 | 4:39e949908fc5 | 9 | sendData(&f,sizeof(float)); |
Condo2k4 | 4:39e949908fc5 | 10 | } |
Condo2k4 | 4:39e949908fc5 | 11 | |
Condo2k4 | 4:39e949908fc5 | 12 | void DataSerial::sendInt16(uint16_t &i) { |
Condo2k4 | 4:39e949908fc5 | 13 | sendData(&i,sizeof(uint16_t)); |
Condo2k4 | 4:39e949908fc5 | 14 | } |
Condo2k4 | 4:39e949908fc5 | 15 | |
Condo2k4 | 4:39e949908fc5 | 16 | void DataSerial::sendChar(char c) { |
Condo2k4 | 4:39e949908fc5 | 17 | putc(1); putc(c); |
Condo2k4 | 4:39e949908fc5 | 18 | } |
Condo2k4 | 4:39e949908fc5 | 19 | |
Condo2k4 | 4:39e949908fc5 | 20 | float DataSerial::readFloat() { |
Condo2k4 | 4:39e949908fc5 | 21 | float f; |
Condo2k4 | 4:39e949908fc5 | 22 | readData(&f,sizeof(float)); |
Condo2k4 | 4:39e949908fc5 | 23 | return f; |
Condo2k4 | 4:39e949908fc5 | 24 | } |
Condo2k4 | 4:39e949908fc5 | 25 | |
Condo2k4 | 4:39e949908fc5 | 26 | uint16_t DataSerial::readInt16() { |
Condo2k4 | 4:39e949908fc5 | 27 | uint16_t i; |
Condo2k4 | 4:39e949908fc5 | 28 | readData(&i,sizeof(uint16_t)); |
Condo2k4 | 4:39e949908fc5 | 29 | return i; |
Condo2k4 | 4:39e949908fc5 | 30 | } |
Condo2k4 | 4:39e949908fc5 | 31 | |
Condo2k4 | 4:39e949908fc5 | 32 | char DataSerial::readChar() { |
Condo2k4 | 4:39e949908fc5 | 33 | return getc(); |
Condo2k4 | 4:39e949908fc5 | 34 | } |
Condo2k4 | 4:39e949908fc5 | 35 | |
Condo2k4 | 4:39e949908fc5 | 36 | void DataSerial::sendData(void* data, uint8_t len) { |
Condo2k4 | 4:39e949908fc5 | 37 | putc(len); |
Condo2k4 | 4:39e949908fc5 | 38 | for(char* c = (char*)data;len--;) |
Condo2k4 | 4:39e949908fc5 | 39 | putc(*(c++)); |
Condo2k4 | 4:39e949908fc5 | 40 | } |
Condo2k4 | 4:39e949908fc5 | 41 | |
Condo2k4 | 4:39e949908fc5 | 42 | void DataSerial::readData(void* data, uint8_t len) { |
Condo2k4 | 4:39e949908fc5 | 43 | char* c = (char*)data; |
Condo2k4 | 4:39e949908fc5 | 44 | while(len>0) { |
Condo2k4 | 4:39e949908fc5 | 45 | *c = getc(); |
Condo2k4 | 4:39e949908fc5 | 46 | c++; |
Condo2k4 | 4:39e949908fc5 | 47 | len--; |
Condo2k4 | 4:39e949908fc5 | 48 | } |
Condo2k4 | 4:39e949908fc5 | 49 | } |
Condo2k4 | 4:39e949908fc5 | 50 | |
Condo2k4 | 4:39e949908fc5 | 51 | void DataSerial::sendSpecialCommand(char char1, char char2) { |
Condo2k4 | 4:39e949908fc5 | 52 | putc(0); putc(char1); putc(char2); |
Condo2k4 | 4:39e949908fc5 | 53 | } |