maybe fixed read-temp

master
Dario Ernst 15 years ago
parent 2726d543b5
commit 7881bd39a2

@ -26,6 +26,10 @@ respectively.
#include "../firmware/masterchip/usbdrv/usbconfig.h" /* device's VID/PID and names */ #include "../firmware/masterchip/usbdrv/usbconfig.h" /* device's VID/PID and names */
void usage() {
printf("Usage: read-temp [spi|temp] [opcode] [addr] [value]\n");
}
int main(int argc, char **argv) int main(int argc, char **argv)
{ {
usb_dev_handle *handle = NULL; usb_dev_handle *handle = NULL;
@ -41,6 +45,7 @@ int cnt, vid, pid;
/* The following function is in opendevice.c: */ /* The following function is in opendevice.c: */
if(usbOpenDevice(&handle, vid, vendor, pid, product, NULL, NULL, NULL) != 0){ if(usbOpenDevice(&handle, vid, vendor, pid, product, NULL, NULL, NULL) != 0){
fprintf(stderr, "Could not find USB device \"%s\" with vid=0x%x pid=0x%x\n", product, vid, pid); fprintf(stderr, "Could not find USB device \"%s\" with vid=0x%x pid=0x%x\n", product, vid, pid);
usage();
exit(1); exit(1);
} }
/* Since we use only control endpoint 0, we don't need to choose a /* Since we use only control endpoint 0, we don't need to choose a
@ -86,10 +91,17 @@ int cnt, vid, pid;
rxIndex = ((int)buffer[3] & 0xff) | (((int)buffer[2] & 0xff) << 8); rxIndex = ((int)buffer[3] & 0xff) | (((int)buffer[2] & 0xff) << 8);
fprintf(stderr, "%3d.%02d*C ", rxValue/100, rxValue%100); fprintf(stderr, "%3d.%02d*C ", rxValue/100, rxValue%100);
fprintf(stderr, "%3d.%02d*C \n", rxIndex/100, rxIndex%100); fprintf(stderr, "%3d.%02d*C \n", rxIndex/100, rxIndex%100);
} else { } else if(strcasecmp(argv[1], "spi") == 0) {
if(argc != 5) {
usage();
return 0;
}
int opcode, addr, value; int opcode, addr, value;
int i=0; int i=0;
sscanf(argv[1], "%i %i %i", &opcode, &addr, &value); opcode = atoi(argv[2]);
addr = atoi(argv[3]);
value = atoi(argv[4]);
cnt = usb_control_msg(handle, USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_ENDPOINT_IN, opcode, addr, value, buffer, sizeof(buffer), 5000); cnt = usb_control_msg(handle, USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_ENDPOINT_IN, opcode, addr, value, buffer, sizeof(buffer), 5000);
if(cnt < 0){ if(cnt < 0){
fprintf(stderr, "\nUSB error in iteration %d: %s\n", i, usb_strerror()); fprintf(stderr, "\nUSB error in iteration %d: %s\n", i, usb_strerror());
@ -100,11 +112,10 @@ int cnt, vid, pid;
fprintf(stderr, "request = 0x%04x\n", opcode); fprintf(stderr, "request = 0x%04x\n", opcode);
fprintf(stderr, "rxValue = 0x%04x value = 0x%04x\n", rxValue, addr); fprintf(stderr, "rxValue = 0x%04x value = 0x%04x\n", rxValue, addr);
fprintf(stderr, "rxIndex = 0x%04x index = 0x%04x\n", rxIndex, value); fprintf(stderr, "rxIndex = 0x%04x index = 0x%04x\n", rxIndex, value);
} else {
usage();
} }
usb_close(handle); usb_close(handle);
return 0; return 0;
} }

Loading…
Cancel
Save