From d04a002c10c8056256ece44dd53e3e60bdbe4e56 Mon Sep 17 00:00:00 2001 From: yellows8 Date: Mon, 5 Mar 2018 22:48:37 -0500 Subject: [PATCH] Updated irsensor example with working image-transfer + image-display. --- hid/irsensor/source/main.c | 46 ++++++++++++++++++++++++++++++++++---- 1 file changed, 42 insertions(+), 4 deletions(-) diff --git a/hid/irsensor/source/main.c b/hid/irsensor/source/main.c index d24ba78..38fe1c8 100644 --- a/hid/irsensor/source/main.c +++ b/hid/irsensor/source/main.c @@ -4,15 +4,23 @@ #include -u8 *ir_buffer = NULL; +//Joy-con IR-sensor example, displays the image from the IR camera. +//The Joy-con must be detached from the system. int main(int argc, char **argv) { Result rc=0; + Result rc2=0; u32 irhandle=0; irsImageTransferProcessorConfig config; irsImageTransferProcessorState state; size_t ir_buffer_size = 0x12c00; + u8 *ir_buffer = NULL; + + u32 width, height; + u32 ir_width, ir_height; + u32 pos, pos2=0; + u32* framebuf; gfxInitDefault(); @@ -57,9 +65,9 @@ int main(int argc, char **argv) if (R_SUCCEEDED(rc)) { - //TODO: Why does this fail? Maybe we need to use certain hid-serv cmd(s)? - rc = irsGetImageTransferProcessorState(irhandle, ir_buffer, ir_buffer_size, &state); - printf("irsGetImageTransferProcessorState() returned 0x%x\n", rc); + //Switch to using regular framebuffer. + consoleClear(); + gfxSetMode(GfxMode_LinearDouble); } while(appletMainLoop()) @@ -72,6 +80,36 @@ int main(int argc, char **argv) if (kDown & KEY_PLUS) break; // break in order to return to hbmenu + if (R_SUCCEEDED(rc)) + { + framebuf = (u32*) gfxGetFramebuffer((u32*)&width, (u32*)&height); + + //Note that the image is updated every few seconds. Likewise, it takes a few seconds for the initial image to become available. + //This will return an error when no image is available yet. + rc2 = irsGetImageTransferProcessorState(irhandle, ir_buffer, ir_buffer_size, &state); + + if (R_SUCCEEDED(rc2)) + { + memset(framebuf, 0, gfxGetFramebufferSize()); + + //IR image width/height with the default config. + //The image is grayscale (1 byte per pixel / 8bits, with 1 color-component). + ir_width = 240; + ir_height = 320; + + u32 x, y; + for (y=0; y