32 mb.config(&Serial, baud, SERIAL_8N1);
58 for(
int i = 0; i < MAX_REG_COUNT; i++) {
79 uint16_t CMD_ARGC =
mb.Hreg(0);
80 int cmd = highByte(CMD_ARGC);
81 int argc = lowByte(CMD_ARGC);
84 uint8_t *argv = (uint8_t *)malloc(
sizeof(uint8_t) * argc);
87 for(
int i = 0; i < argc; i++) {
88 uint16_t thisWord =
mb.Hreg(i/2 + 1);
91 argv[i] = (i % 2 == 0 ? highByte(thisWord) : lowByte(thisWord));
98 for(
int i = 0; i < result.
count; i++) {
99 uint16_t thisWord =
mb.Hreg(i/2 + 1);
100 uint8_t curResult = result.
value[i];
104 mb.Hreg(i/2 + 1, (i % 2 == 0 ? makeWord(curResult, 0) : thisWord | curResult));
109 if (result.
value !=
nullptr) free(result.
value);
122 return mb.task() && (highByte(
mb.Hreg(0)));
struct registers pinMode(uint8_t argc, uint8_t *argv)
Change the settings of the Arduino I/O pins.
struct registers spiSettings(uint8_t argc, uint8_t *argv)
Change the settings of the SPI connection.
struct registers wireSetClock(uint8_t argc, uint8_t *argv)
Change the clock speed settings of the I2C connection.
struct registers wireRead(uint8_t argc, uint8_t *argv)
Read data from the connected I2C peripheral.
struct registers servoRead(uint8_t argc, uint8_t *argv)
Read a value from the connected servo.
struct registers wireWrite(uint8_t argc, uint8_t *argv)
Write data to the connected I2C peripheral.
struct registers wireEnd(uint8_t argc, uint8_t *argv)
End an I2C connection between the Arduino and a peripheral.
struct registers spiBegin(uint8_t argc, uint8_t *argv)
Begin a SPI connection between the Arduino and a peripheral.
struct registers analogWrite(uint8_t argc, uint8_t *argv)
Write an analog value (0-255) to the Arduino I/O pins.
struct registers servoWrite(uint8_t argc, uint8_t *argv)
Write a value to the connected servo.
struct registers servoDetach(uint8_t argc, uint8_t *argv)
Detach a servo from the the control interface.
struct registers servoAttach(uint8_t argc, uint8_t *argv)
Attach a connected servo to a control interface.
struct registers analogRead(uint8_t argc, uint8_t *argv)
Read an analog value (0-1023) from the Arduino I/O pins.
struct registers digitalRead(uint8_t argc, uint8_t *argv)
Read a digital value (HIGH/LOW) from the Arduino I/O pins.
struct registers spiTransferBuf(uint8_t argc, uint8_t *argv)
Exchange data over the SPI connection (Read + Write)
struct registers digitalWrite(uint8_t argc, uint8_t *argv)
Write a digital (HIGH/LOW) value to the Arduino I/O pins.
struct registers spiEnd(uint8_t argc, uint8_t *argv)
End a SPI connection between the Arduino and a peripheral.
struct registers wireBegin(uint8_t argc, uint8_t *argv)
Begin an I2C connection between the Arduino and a peripheral.
A data structure to describe function arguments and return values.
Header file for 'Modmata.cpp'.
Base class for a host computer to control this (LattePanda's Arduino Leonardo) device.
void attach(uint8_t command, struct registers(*fn)(uint8_t argc, uint8_t *argv))
Assign a function to a command number. Standard commands have default functions, but those can be ove...
struct registers(* callbackFunctions[100])(uint8_t argc, uint8_t *argv)
An array of references to callback functions indexed by their function code number....
ModbusSerial mb
Object representing an interactive Modbus connection over Serial.
void processInput()
Read the command and args sent and execute the corresponding callback function, store the results of ...
void begin(int baud)
Begin listening for a Modmata connection over serial/USB.