elpeo / rbtemper Goto Github PK
View Code? Open in Web Editor NEWRuby TEMPer library
Ruby TEMPer library
Hi,
What version of libusb did you use?
I am wondering because you include a header file called usb.h.
The normal libusb header file is called libusb.h.
And you are using type names and function names that are not defined by the official libusb header file:
http://libusb.sourceforge.net/api-1.0/libusb_8h_source.html
Thus I am not able to compile the ruby extension.
Best Regards
Markus
I have a long running process that checks the temp regularly. After several hundred checks I am getting malloc and/or free memory corruption errors and my whole ruby process is dumping. I've isolated it to this library... any ideas?
I used some example code from another temper project to deal with negatives. This has been tested for my system only but seems to work.
static int interrupt_read_temperatura(usb_dev_handle *dev, float *tempC) {
int r,i, temperature;
char answer[reqIntLen];
bzero(answer, reqIntLen);
r = usb_interrupt_read(dev, 0x82, answer, reqIntLen, timeout);
if( r != reqIntLen )
{
if(debug){
printf("USB interrupt read");
}
return -1;
}
if(debug) {
for (i=0;i<reqIntLen; i++) printf("%02x ",answer[i] & 0xFF);
printf("\n");
}
temperature = (answer[3] & 0xFF) + (answer[2] << 8);
/* msb means the temperature is negative -- less than 0 Celsius -- and in 2'complement form.
* We can't be sure that the host uses 2's complement to store negative numbers
* so if the temperature is negative, we 'manually' get its magnitude
* by explicity getting it's 2's complement and then we return the negative of that.
*/
if ((answer[2] & 0x80)!=0) {
/* return the negative of magnitude of the temperature */
temperature = -((temperature ^ 0xffff)+1);
}
// end of the updates made for netgative temps
*tempC = temperature * (125.0 / 32000.0);
return 0;
}
static int get_temperature(usb_dev_handle *dev, float *tempC){
char buf[256];
int ret, i, temperature;
control_transfer(dev, uCmd1 );
control_transfer(dev, uCmd4 );
for(i = 0; i < 7; i++) {
control_transfer(dev, uCmd0 );
}
control_transfer(dev, uCmd2 );
ret = get_data(dev, buf, 256);
if(ret < 2) {
return -1;
}
temperature = (buf[1] & 0xFF) + (buf[0] << 8);
/* msb means the temperature is negative -- less than 0 Celsius -- and in 2'complement form.
* We can't be sure that the host uses 2's complement to store negative numbers
* so if the temperature is negative, we 'manually' get its magnitude
* by explicity getting it's 2's complement and then we return the negative of that.
*/
if ((buf[0] & 0x80)!=0) {
/* return the negative of magnitude of the temperature */
temperature = -((temperature ^ 0xffff)+1);
}
// end up the updates made.
*tempC = temperature * (125.0 / 32000.0);
return 0;
}
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.