Download libraries/Firmata/utility/SerialFirmata.h from Beifengdo/Arduino-Development: direct link, hf CLI and curl.
- Browser
- Download file 5.84 kB
-
https://huggingface.co/datasets/Beifengdo/Arduino-Development/resolve/main/libraries/Firmata/utility/SerialFirmata.h
- Command line
-
hf download hf://datasets/Beifengdo/Arduino-Development/libraries/Firmata/utility/SerialFirmata.h
-
curl -L -o SerialFirmata.h https://huggingface.co/datasets/Beifengdo/Arduino-Development/resolve/main/libraries/Firmata/utility/SerialFirmata.h
5.84 kB
| /* | |
| SerialFirmata.h | |
| Copyright (C) 2016 Jeff Hoefs. All rights reserved. | |
| This library is free software; you can redistribute it and/or | |
| modify it under the terms of the GNU Lesser General Public | |
| License as published by the Free Software Foundation; either | |
| version 2.1 of the License, or (at your option) any later version. | |
| See file LICENSE.txt for further informations on licensing terms. | |
| This version of SerialFirmata.h differs from the ConfigurableFirmata | |
| version in the following ways: | |
| - Defines FIRMATA_SERIAL_FEATURE (could add to Configurable version as well) | |
| - Imports Firmata.h rather than ConfigurableFirmata.h | |
| Last updated October 16th, 2016 | |
| */ | |
| // SoftwareSerial is currently only supported for AVR-based boards and the Arduino 101. | |
| // Limited to Arduino 1.6.6 or higher because Arduino builder cannot find SoftwareSerial | |
| // prior to this release. | |
| // Serial port Ids | |
| // extensible up to 0x07 | |
| // extensible up to 0x0F | |
| // map configuration query response resolution value to serial pin type | |
| // Serial command bytes | |
| // Serial read modes | |
| namespace { | |
| struct serial_pins { | |
| uint8_t rx; | |
| uint8_t tx; | |
| }; | |
| /* | |
| * Get the serial serial pin type (RX1, TX1, RX2, TX2, etc) for the specified pin. | |
| */ | |
| inline uint8_t getSerialPinType(uint8_t pin) { | |
| // TODO when use of HW_SERIAL0 is enabled | |
| if (pin == PIN_SERIAL1_RX) return RES_RX1; | |
| if (pin == PIN_SERIAL1_TX) return RES_TX1; | |
| if (pin == PIN_SERIAL2_RX) return RES_RX2; | |
| if (pin == PIN_SERIAL2_TX) return RES_TX2; | |
| if (pin == PIN_SERIAL3_RX) return RES_RX3; | |
| if (pin == PIN_SERIAL3_TX) return RES_TX3; | |
| if (pin == PIN_SERIAL4_RX) return RES_RX4; | |
| if (pin == PIN_SERIAL4_TX) return RES_TX4; | |
| if (pin == PIN_SERIAL5_RX) return RES_RX5; | |
| if (pin == PIN_SERIAL5_TX) return RES_TX5; | |
| if (pin == PIN_SERIAL6_RX) return RES_RX6; | |
| if (pin == PIN_SERIAL6_TX) return RES_TX6; | |
| return 0; | |
| } | |
| /* | |
| * Get the RX and TX pins numbers for the specified HW serial port. | |
| */ | |
| inline serial_pins getSerialPinNumbers(uint8_t portId) { | |
| serial_pins pins; | |
| switch (portId) { | |
| // case HW_SERIAL0: | |
| // // TODO when use of HW_SERIAL0 is enabled | |
| // break; | |
| case HW_SERIAL1: | |
| pins.rx = PIN_SERIAL1_RX; | |
| pins.tx = PIN_SERIAL1_TX; | |
| break; | |
| case HW_SERIAL2: | |
| pins.rx = PIN_SERIAL2_RX; | |
| pins.tx = PIN_SERIAL2_TX; | |
| break; | |
| case HW_SERIAL3: | |
| pins.rx = PIN_SERIAL3_RX; | |
| pins.tx = PIN_SERIAL3_TX; | |
| break; | |
| case HW_SERIAL4: | |
| pins.rx = PIN_SERIAL4_RX; | |
| pins.tx = PIN_SERIAL4_TX; | |
| break; | |
| case HW_SERIAL5: | |
| pins.rx = PIN_SERIAL5_RX; | |
| pins.tx = PIN_SERIAL5_TX; | |
| break; | |
| case HW_SERIAL6: | |
| pins.rx = PIN_SERIAL6_RX; | |
| pins.tx = PIN_SERIAL6_TX; | |
| break; | |
| default: | |
| pins.rx = 0; | |
| pins.tx = 0; | |
| } | |
| return pins; | |
| } | |
| } // end namespace | |
| class SerialFirmata: public FirmataFeature | |
| { | |
| public: | |
| SerialFirmata(); | |
| boolean handlePinMode(byte pin, int mode); | |
| void handleCapability(byte pin); | |
| boolean handleSysex(byte command, byte argc, byte* argv); | |
| void update(); | |
| void reset(); | |
| void checkSerial(); | |
| private: | |
| byte reportSerial[MAX_SERIAL_PORTS]; | |
| int serialBytesToRead[SERIAL_READ_ARR_LEN]; | |
| signed char serialIndex; | |
| Stream *swSerial0; | |
| Stream *swSerial1; | |
| Stream *swSerial2; | |
| Stream *swSerial3; | |
| Stream* getPortFromId(byte portId); | |
| }; | |