/*JSON{  "type":"method", "class": "Serial", "name" : "println",
         "description" : "Print a line to the serial port (newline character sent are '\r\n')",
         "generate" : "jswrap_serial_println",
         "params" : [ [ "string", "JsVar", "A String to print"] ]
}*/
void _jswrap_serial_print(JsVar *parent, JsVar *str, bool newLine) {
  NOT_USED(parent);
  IOEventFlags device = jsiGetDeviceFromClass(parent);
  str = jsvAsString(str, false);
  jsiTransmitStringVar(device,str);
  jsvUnLock(str);
  if (newLine) {
    jshTransmit(device, (unsigned char)'\r');
    jshTransmit(device, (unsigned char)'\n');
  }
}
/*JSON{ "type":"method", "class": "Serial", "name" : "write",
         "description" : "Write a character or array of characters to the serial port - without a line feed",
         "generate" : "jswrap_serial_write",
         "params" : [ [ "data", "JsVar", "A byte, a string, or an array of bytes to write"] ]
}*/
void jswrap_serial_write(JsVar *parent, JsVar *data) {
  NOT_USED(parent);
  IOEventFlags device = jsiGetDeviceFromClass(parent);
  if (jsvIsNumeric(data)) {
    jshTransmit(device, (unsigned char)jsvGetInteger(data));
  } else if (jsvIsIterable(data)) {
    JsvIterator it;
    jsvIteratorNew(&it, data);
    while (jsvIteratorHasElement(&it)) {
      jshTransmit(device, (unsigned char)jsvIteratorGetIntegerValue(&it));
      jsvIteratorNext(&it);
    }
    jsvIteratorFree(&it);
  } else {
    jsWarn("Data supplied was not an integer - or iterable");
  }
}
示例#3
0
/** Send data through the given SPI device (if data>=0), and return the result
 * of the previous send (or -1). If data<0, no data is sent and the function
 * waits for data to be returned */
int jshSPISend(IOEventFlags device, int data) {
  jshTransmit(device, (unsigned char)data);
  // FIXME
  // use jshPopIOEventOfType(device) but be aware that it may return >1 char!
  return -1;
}
示例#4
0
static void _jswrap_serial_print_cb(int data, void *userData) {
  IOEventFlags device = *(IOEventFlags*)userData;
  jshTransmit(device, (unsigned char)data);
}