Last active
August 3, 2017 03:35
-
-
Save lacyrhoades/4569ea18ef7f34c4d6e9c9d2a0153f60 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "usb_dev.h" | |
const int pinLED = 13; | |
void setup() { | |
pinMode(pinLED, OUTPUT); | |
usb_init(); | |
while (usb_configuration == 0) { | |
delay(5000); | |
digitalWrite(pinLED, HIGH); | |
delay(5000); | |
digitalWrite(pinLED, LOW); | |
} | |
digitalWrite(pinLED, LOW); | |
} | |
void loop() { | |
uint8_t buffer[64] = { 0 }; | |
usb_rawhid_recv(&buffer, 10000); | |
for (int i = 0; i < 64; i++) { | |
if (buffer[i] > 0) { | |
// Short flashes signal "receieved" | |
digitalWrite(pinLED, HIGH); | |
delay(100); | |
digitalWrite(pinLED, LOW); | |
delay(100); | |
digitalWrite(pinLED, HIGH); | |
delay(100); | |
digitalWrite(pinLED, LOW); | |
delay(100); | |
digitalWrite(pinLED, HIGH); | |
delay(100); | |
digitalWrite(pinLED, LOW); | |
break; | |
} | |
} | |
// Long flash is "waiting" | |
digitalWrite(pinLED, HIGH); | |
delay(1000); | |
digitalWrite(pinLED, LOW); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdlib.h> | |
#include <stdarg.h> | |
#include <sys/ioctl.h> | |
#include <termios.h> | |
#include "hid.h" | |
int main() { | |
uint8_t buf[64]; | |
int r = rawhid_open(1, 0x16C0, 0x0486, 0xFFAB, 0x0200); | |
if (r <= 0) { | |
printf("No rawhid device found!\n"); | |
} else { | |
printf("Found rawhid device...\n"); | |
} | |
printf("Sending...\n"); | |
buf[0] = 0x01; | |
for (int i = 1; i < 64; i++) { | |
buf[i] = 0x01; | |
} | |
int result = rawhid_send(0, buf, 64, 100); | |
printf("Got rawhid_send result: %d\n", result); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
OS = MACOSX | |
PROG = rawhid_test | |
TARGET = $(PROG) | |
SDK = /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk | |
ARCH = -mmacosx-version-min=10.12 | |
CC = gcc | |
STRIP = strip | |
CFLAGS = -Wall -O0 -DOS_$(OS) -isysroot $(SDK) $(ARCH) | |
LIBS = $(ARCH) -Wl,-syslibroot,$(SDK) -framework IOKit -framework CoreFoundation | |
OBJS = $(PROG).o hid.o | |
all: $(TARGET) | |
$(PROG): $(OBJS) | |
$(CC) -o $(PROG) $(OBJS) $(LIBS) | |
$(STRIP) $(PROG) | |
hid.o: hid_$(OS).c hid.h | |
$(CC) $(CFLAGS) -c -o $@ $< | |
clean: | |
rm -f *.o $(PROG) $(PROG).exe $(PROG).dmg | |
rm -rf tmp | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Write to Teensy rawhid from Node.js | |
const hid = require('node-hid') | |
var devices = hid.devices().filter(function (eachDevice) { | |
return eachDevice.productId == 0x0486 && eachDevice.vendorId == 5824 && eachDevice.usage == 0x0200 | |
}) | |
var device = new hid.HID(devices[0].path) | |
device.write([0x00, 0x01, 0x01, 0x05, 0xff, 0xff]); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment