Updated irsensor example.

This commit is contained in:
yellows8 2018-03-01 19:15:41 -05:00
parent 3693998cbc
commit 8cbf348876

View File

@ -1,22 +1,42 @@
#include <string.h> #include <string.h>
#include <stdio.h> #include <stdio.h>
#include <malloc.h>
#include <switch.h> #include <switch.h>
//TODO: Implement image-transfer in libnx and in this example. //TODO: Implement image-transfer in libnx and in this example.
u8 *ir_buffer = NULL;
int main(int argc, char **argv) int main(int argc, char **argv)
{ {
Result rc=0; Result rc=0;
u32 irhandle=0; u32 irhandle=0;
irsImageTransferProcessorConfig config;
irsImageTransferProcessorState state;
size_t ir_buffer_size = 0x100000;
gfxInitDefault(); gfxInitDefault();
//Initialize console. Using NULL as the second argument tells the console library to use the internal console structure as current one. //Initialize console. Using NULL as the second argument tells the console library to use the internal console structure as current one.
consoleInit(NULL); consoleInit(NULL);
rc = irsInitialize(); ir_buffer = (u8*)malloc(ir_buffer_size);
printf("irsInitialize() returned 0x%x\n", rc); if (ir_buffer==NULL)
{
rc = MAKERESULT(Module_Libnx, LibnxError_OutOfMemory);
printf("Failed to allocate memory for ir_buffer.\n");
}
else
{
memset(ir_buffer, 0, ir_buffer_size);
}
if (R_SUCCEEDED(rc))
{
rc = irsInitialize();
printf("irsInitialize() returned 0x%x\n", rc);
}
if (R_SUCCEEDED(rc)) if (R_SUCCEEDED(rc))
{ {
@ -30,6 +50,20 @@ int main(int argc, char **argv)
printf("irsGetIrCameraHandle() returned 0x%x\n", rc); printf("irsGetIrCameraHandle() returned 0x%x\n", rc);
} }
if (R_SUCCEEDED(rc))
{
irsGetDefaultImageTransferProcessorConfig(&config);
rc = irsRunImageTransferProcessor(irhandle, &config, 0x100000);
printf("irsRunImageTransferProcessor() returned 0x%x\n", rc);
}
if (R_SUCCEEDED(rc))
{
//TODO: Why does this fail?
rc = irsGetImageTransferProcessorState(irhandle, ir_buffer, ir_buffer_size, &state);
printf("irsGetImageTransferProcessorState() returned 0x%x\n", rc);
}
while(appletMainLoop()) while(appletMainLoop())
{ {
//Scan all the inputs. This should be done once for each frame //Scan all the inputs. This should be done once for each frame
@ -45,8 +79,11 @@ int main(int argc, char **argv)
gfxWaitForVsync(); gfxWaitForVsync();
} }
irsStopImageProcessor(irhandle);
irsExit(); irsExit();
free(ir_buffer);
gfxExit(); gfxExit();
return 0; return 0;
} }