Skip to content

Instantly share code, notes, and snippets.

@saisasidhar
Created June 8, 2016 12:51
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 saisasidhar/0c4b81bcfc5ca5e2cfbf290a2fec6901 to your computer and use it in GitHub Desktop.
Save saisasidhar/0c4b81bcfc5ca5e2cfbf290a2fec6901 to your computer and use it in GitHub Desktop.
// gcc -o demo demo.c api.c usb.c -L. -lhidapi-libusb -lrt -lusb-1.0 -ldlpspec -lm -fno-stack-protector
#include <stdio.h>
#include "common.h"
#include "usb.h"
#include "api.h"
int main()
{
USB_Init();
if(USB_Open() <0 )
{
printf("Failed to open USB device\n");
return -1;
}
DEBUG_PRINT printf("Pointer to USB Handle %p\n", USB_getDeviceHandle());
DEBUG_PRINT {
int amb, det;
if(FAIL == NNO_ReadTemp(&amb, &det))
{
printf("Failed to read temperature\n");
goto fail;
}
printf("Amb: %f, Det: %f\n",(double)amb/100, (double)det/100);
}
DEBUG_PRINT {
printf("No. of scan configurations present: %d\n",NNO_GetNumScanCfg());
printf("Current active scan configuration: %d\n",NNO_GetActiveScanIndex());
int size = sizeof(scanConfig)*2;
void* buf = malloc(size);
if(FAIL == NNO_GetScanCfg(1, buf, &size))
{
printf("Failed to read active scan configuration\n");
goto fail;
}
dlpspec_scan_read_configuration(buf, size);
scanConfig * scanConfig_buffer = (scanConfig*)buf;
printf("Num Patterns: %d\n",scanConfig_buffer->num_patterns);
printf("WL Start: %d nm\n",scanConfig_buffer->wavelength_start_nm);
printf("WL End: %d nm\n",scanConfig_buffer->wavelength_end_nm);
printf("Num repeats: %d\n",scanConfig_buffer->num_repeats);
}
// NNO_SetActiveScanIndex(1);
// @param Store in SD Card
NNO_PerformScan(false);
int status;
do {
status = NNO_GetScanComplete();
sleep(1);
}while(status == 0);
int scan_result_bytes = NNO_GetFileSizeToRead(NNO_FILE_SCAN_DATA);
if(scan_result_bytes <= 0)
{
printf("An error occured while reading file size\n");
goto fail;
}
DEBUG_PRINT printf("Result File Size: %d\n", scan_result_bytes);
unsigned char * scan_data = malloc(scan_result_bytes);
int bytes_read;
bytes_read = NNO_GetFile((unsigned char *)scan_data, scan_result_bytes);
if(bytes_read != scan_result_bytes)
{
printf("Received data is not equal to file size\n");
goto fail;
}
scanResults scan_result;
/*
FILE *handle;
handle = fopen("record.dat","w");
fwrite(bin_data, 1, scan_result_bytes, handle);
*/
int ret = dlpspec_scan_interpret(scan_data, bytes_read, &scan_result);
if(DLPSPEC_PASS != ret)
{
printf("Failed to interpret data\n");
goto fail;
}
DEBUG_PRINT {
printf("Scan Name: %s\n", scan_result.scan_name);
printf("Scan Index ID: %d\n",scan_result.scanDataIndex);
// printf("Num of valid elements: %d\n", scan_result.length); This is 0 always.
}
printf("Wavelenth[X],Intensity[X]\n");
for(int i=0; i<ADC_DATA_LEN; i++)
{
if(scan_result.wavelength[i]>=899 && scan_result.wavelength[i] <=1701)
//printf("%f,%d\n",scan_result.wavelength[i],scan_result.intensity[i]);
if(scan_result.wavelength[i] > 1701)
break;
}
USB_Close();
return 0;
fail:
USB_Close();
return -1;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment