Skip to content

Instantly share code, notes, and snippets.

@svensken
Created May 16, 2011 03:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save svensken/973898 to your computer and use it in GitHub Desktop.
Save svensken/973898 to your computer and use it in GitHub Desktop.
library bridges
/*
compile with Visual Studio C++ command prompt using:
cl -LD dlllauschen.cpp -Felauschen.dll
*/
#include <stdio.h>
#include <stdlib.h>
#include <windows.h>
#include "hidapi.h"
#pragma comment(lib, "hidapi.lib")
__declspec(dllexport)
int main(void)
{
hid_device *handle;
handle = hid_open(0x04d8, 0xfa25, NULL);
if (!handle) {
return -1;
}
hid_close(handle);
return 0;
}
/*
compile with Visual Studio C++ command prompt using:
cl -LD dlltemperature.cpp -Fetemperature.dll
*/
#include <stdio.h>
#include <stdlib.h>
#include <windows.h>
#include "hidapi.h"
#pragma comment(lib, "hidapi.lib")
__declspec(dllexport)
int main(void)
{
int res;
unsigned char buf[256];
hid_device *handle;
char mop[3];
long int adc_val;
handle = hid_open(0x04d8, 0xfa25, NULL);
if (!handle) {
return -1;
}
memset(buf,0,sizeof(buf));
buf[1] = 0x82;
res = hid_write(handle, buf, 65);
if (res < 0) {
return -2;
}
hid_set_nonblocking(handle, 1);
res = 0;
while(res == 0) {
res = hid_read(handle, buf, sizeof(buf));
if (res < 0) return -3;
}
hid_close(handle);
sprintf(mop, "%02x%02x", buf[1], buf[2]);
adc_val = strtol(mop, NULL, 16);
return adc_val;
}
/*
compile with Visual Studio C++ command prompt using:
cl -LD dlltoggle.cpp -Fetoggle.dll
*/
#include <stdio.h>
#include <stdlib.h>
#include <windows.h>
#include "hidapi.h"
#pragma comment(lib, "hidapi.lib")
__declspec(dllexport)
int main(void)
{
int res;
unsigned char buf[256];
hid_device *handle;
handle = hid_open(0x04d8, 0xfa25, NULL);
if (!handle) {
return -1;
}
memset(buf,0,sizeof(buf));
buf[1] = 0x80;
res = hid_write(handle, buf, 65);
if (res < 0) {
return -2;
}
hid_close(handle);
return 0;
}
/*
compile with Visual Studio C++ command prompt using:
cl -LD dlltoggle.cpp -Fetoggle.dll
*/
#include <stdio.h>
#include <stdlib.h>
#include <windows.h>
#include "hidapi.h"
#pragma comment(lib, "hidapi.lib")
__declspec(dllexport)
int main(int cycles,
double tempI,
double tempD,
double tempA,
double tempE,
double tempF,
int timeI,
int timeD,
int timeA,
int timeE,
int timeF)
{
int res;
unsigned char buf[256];
hid_device *handle;
handle = hid_open(0x04d8, 0xfa25, NULL);
if (!handle) {
return -1;
}
memset(buf,0,sizeof(buf));
// buf[] values cannot exceed 0xff (255)
/* HID can't pass decimals, so for now we'll just multiply
the temperature values by 2, and halv them in the firmware.
This only works with a resolution of half a degree. For
more specific values, define 5 more buf[]s that serve as
the decimal 'indicators', and add each of them up in the
firmware... i guess... */
buf[1] = 0x81;
buf[2] = cycles;
buf[3] = 2*tempI;
buf[4] = 2*tempD;
buf[5] = 2*tempA;
buf[6] = 2*tempE;
buf[7] = 2*tempF;
buf[8] = timeI;
buf[9] = timeD;
buf[10] = timeA;
buf[11] = timeE;
buf[12] = timeF;
res = hid_write(handle, buf, 65);
if (res < 0) {
return -2;
}
hid_close(handle);
return 0;
}
/* on mac, compile into shared library toggle.so with command:
g++ -shared hid.o lauschen.o -framework IOKit -framework CoreFoundation -o lauschen.so
where hid.o comes from hidapi/mac/hid.c */
/* on linux, compile into shared library toggle.so with command:
g++ -shared $(pkg-config libusb-1.0 --libs) hid-libusb.o \
lauschen.o -o lauschen.so
where hid.o comes from hidapi/linux/hid.c */
#include <stdio.h>
#include <wchar.h>
#include <string.h>
#include <stdlib.h>
#include "hidapi.h"
#include <unistd.h>
int res;
unsigned char buf[256];
hid_device *handle;
int main(void)
{
handle = hid_open(0x04d8, 0xfa25, NULL);
if (!handle) {
return -1;
}
hid_close(handle);
return 0;
}
/* on mac, compile into shared library temperature.so with command:
g++ -shared hid.o temperature.o -framework IOKit -framework CoreFoundation -o temperature.so
where hid.o comes from HIDAPI's hid.c */
#include <stdio.h>
#include <wchar.h>
#include <string.h>
#include <stdlib.h>
#include <sstream>
#include <iostream>
#include "hidapi.h"
#include <unistd.h>
int res;
unsigned char buf[256];
hid_device *handle;
char mop[3];
long int adc_val;
int main(void)
{
handle = hid_open(0x04d8, 0xfa25, NULL);
if (!handle) {
return -1;
}
memset(buf,0,sizeof(buf));
//send command
buf[1] = 0x82;
res = hid_write(handle, buf, 65);
if (res < 0) {
return -2;
}
//read dat shit
hid_set_nonblocking(handle, 1);
res = 0;
while (res == 0) {
res = hid_read(handle, buf, sizeof(buf));
if (res < 0) return -3;
}
hid_close(handle);
// buf[0] is always 0x82
//printf("high - %02x ... low - %02x\n", buf[1], buf[2]);
// store hex as string
sprintf(mop, "%02x%02x", buf[1], buf[2]);
adc_val = strtol(mop, NULL, 16);
//printf("intger = %li\n", adc_val);
return adc_val;
}
/* on mac, compile into shared library toggle.so with command:
g++ -shared hid.o toggle.o -framework IOKit -framework CoreFoundation -o toggle.so
where hid.o comes from HIDAPI's hid.c */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include "hidapi.h"
int res;
unsigned char buf[256];
hid_device *handle;
int main(void)//int seconds)
{
handle = hid_open(0x04d8, 0xfa25, NULL);
if (!handle) {
return -1;
}
memset(buf,0,sizeof(buf));
buf[1] = 0x80;
//buf[2] = seconds; // doesnt work yet
res = hid_write(handle, buf, 65);
if (res < 0) {
return -2;
}
hid_close(handle);
return 0;
}
/* on mac, compile into shared library toggle.so with command:
g++ -shared hid.o toggle.o -framework IOKit -framework CoreFoundation -o toggle.so
where hid.o comes from HIDAPI's hid.c */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include "hidapi.h"
int res;
unsigned char buf[256];
hid_device *handle;
int main( int cycles,
double tempI,
double tempD,
double tempA,
double tempE,
double tempF,
int timeI,
int timeD,
int timeA,
int timeE,
int timeF )
{
handle = hid_open(0x04d8, 0xfa25, NULL);
if (!handle) {
return -1;
}
memset(buf,0,sizeof(buf));
// buf[] values cannot exceed 0xff (255)
/* HID can't pass decimals, so for now we'll just multiply
the temperature values by 2, and halv them in the firmware.
This only works with a resolution of half a degree. For
more specific values, define 5 more buf[]s that serve as
the decimal 'indicators', and add each of them up in the
firmware... i guess... */
buf[1] = 0x81;
buf[2] = cycles;
buf[3] = 2*tempI;
buf[4] = 2*tempD;
buf[5] = 2*tempA;
buf[6] = 2*tempE;
buf[7] = 2*tempF;
buf[8] = timeI;
buf[9] = timeD;
buf[10] = timeA;
buf[11] = timeE;
buf[12] = timeF;
res = hid_write(handle, buf, 65);
if (res < 0) {
return -2;
}
hid_close(handle);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment