(bytes, position)
| 129 | this.buffer = buffer.slice(position); |
| 130 | } |
| 131 | onReceive(bytes, position) { |
| 132 | while (position < bytes.length) { |
| 133 | const available = bytes.length - position; |
| 134 | |
| 135 | let command = bytes[position], channel; |
| 136 | if (command < 0xF0) { |
| 137 | channel = command & 0x0F; |
| 138 | command &= 0xF0; |
| 139 | } |
| 140 | |
| 141 | switch (command) { |
| 142 | case 0x90: // DIGITAL_MESSAGE |
| 143 | if (available < 3) |
| 144 | return position; |
| 145 | |
| 146 | this.doDigitalWrite(channel, (bytes[position + 1] & 0x7F) | ((bytes[position + 2] & 1) << 7)); //@@ masking may be unnecesary |
| 147 | position += 3; |
| 148 | break; |
| 149 | |
| 150 | case 0xC0: // REPORT_ANALOG |
| 151 | if (available < 2) |
| 152 | return position; |
| 153 | |
| 154 | this.doReportAnalog(channel, bytes[position + 1]); |
| 155 | position += 2; |
| 156 | break; |
| 157 | |
| 158 | case 0xD0: // REPORT_DIGITAL |
| 159 | if (available < 2) |
| 160 | return position; |
| 161 | |
| 162 | this.doReportDigital(channel, bytes[position + 1]); |
| 163 | position += 2; |
| 164 | break; |
| 165 | |
| 166 | case 0xF0: { // SYSEX begin |
| 167 | let end = position, found; |
| 168 | while ((++end < bytes.length) && !found) |
| 169 | found = (0xF7 === bytes[end]) |
| 170 | if (!found) |
| 171 | return position; |
| 172 | this.onSysex(bytes.slice(position + 1, end - 1)); |
| 173 | position = end; |
| 174 | } break; |
| 175 | |
| 176 | case 0xF4: // PIN_MODE |
| 177 | if (available < 3) |
| 178 | return position; |
| 179 | this.doSetPinMode(bytes[position + 1], bytes[position + 2]) |
| 180 | position += 3; |
| 181 | break; |
| 182 | |
| 183 | case 0xF9: // REPORT_VERSION |
| 184 | this.write(0xF9); |
| 185 | this.write(FIRMATA_PROTOCOL_MAJOR_VERSION); |
| 186 | this.write(FIRMATA_PROTOCOL_MINOR_VERSION); |
| 187 | position += 1; |
| 188 | break; |
no test coverage detected