This commit is contained in:
plutoo 2018-03-07 18:51:41 +01:00
parent f1211ac816
commit a8e052bb72
16 changed files with 939 additions and 939 deletions

View File

@ -17,136 +17,136 @@
int main(int argc, char **argv) int main(int argc, char **argv)
{ {
Result rc = 0; Result rc = 0;
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);
AudioInBuffer audin_buf; AudioInBuffer audin_buf;
AudioOutBuffer audout_buf; AudioOutBuffer audout_buf;
AudioInBuffer *released_in_buffer; AudioInBuffer *released_in_buffer;
AudioOutBuffer *released_out_buffer; AudioOutBuffer *released_out_buffer;
u32 released_in_count; u32 released_in_count;
u32 released_out_count; u32 released_out_count;
// Make sure the sample buffer size is aligned to 0x1000 bytes. // Make sure the sample buffer size is aligned to 0x1000 bytes.
u32 data_size = (SAMPLECOUNT * CHANNELCOUNT * BYTESPERSAMPLE); u32 data_size = (SAMPLECOUNT * CHANNELCOUNT * BYTESPERSAMPLE);
u32 buffer_size = (data_size + 0xfff) & ~0xfff; u32 buffer_size = (data_size + 0xfff) & ~0xfff;
// Allocate the buffers. // Allocate the buffers.
u8* in_buf_data = memalign(0x1000, buffer_size); u8* in_buf_data = memalign(0x1000, buffer_size);
u8* out_buf_data = memalign(0x1000, buffer_size); u8* out_buf_data = memalign(0x1000, buffer_size);
// Ensure buffers were properly allocated. // Ensure buffers were properly allocated.
if ((in_buf_data == NULL) || (out_buf_data == NULL)) if ((in_buf_data == NULL) || (out_buf_data == NULL))
{ {
rc = MAKERESULT(Module_Libnx, LibnxError_OutOfMemory); rc = MAKERESULT(Module_Libnx, LibnxError_OutOfMemory);
printf("Failed to allocate sample data buffers\n"); printf("Failed to allocate sample data buffers\n");
} }
if (R_SUCCEEDED(rc)) if (R_SUCCEEDED(rc))
{ {
memset(in_buf_data, 0, buffer_size); memset(in_buf_data, 0, buffer_size);
memset(out_buf_data, 0, buffer_size); memset(out_buf_data, 0, buffer_size);
} }
if (R_SUCCEEDED(rc)) if (R_SUCCEEDED(rc))
{ {
// Initialize the default audio input device. // Initialize the default audio input device.
rc = audinInitialize(); rc = audinInitialize();
printf("audinInitialize() returned 0x%x\n", rc); printf("audinInitialize() returned 0x%x\n", rc);
} }
if (R_SUCCEEDED(rc)) if (R_SUCCEEDED(rc))
{ {
// Initialize the default audio output device. // Initialize the default audio output device.
rc = audoutInitialize(); rc = audoutInitialize();
printf("audoutInitialize() returned 0x%x\n", rc); printf("audoutInitialize() returned 0x%x\n", rc);
} }
if (R_SUCCEEDED(rc)) if (R_SUCCEEDED(rc))
{ {
// Start audio capture. // Start audio capture.
rc = audinStartAudioIn(); rc = audinStartAudioIn();
printf("audinStartAudioIn() returned 0x%x\n", rc); printf("audinStartAudioIn() returned 0x%x\n", rc);
} }
if (R_SUCCEEDED(rc)) if (R_SUCCEEDED(rc))
{ {
// Start audio playback. // Start audio playback.
rc = audoutStartAudioOut(); rc = audoutStartAudioOut();
printf("audoutStartAudioOut() returned 0x%x\n", rc); printf("audoutStartAudioOut() returned 0x%x\n", rc);
} }
// Prepare the input buffer. // Prepare the input buffer.
audin_buf.next = NULL; audin_buf.next = NULL;
audin_buf.buffer = in_buf_data; audin_buf.buffer = in_buf_data;
audin_buf.buffer_size = buffer_size; audin_buf.buffer_size = buffer_size;
audin_buf.data_size = data_size; audin_buf.data_size = data_size;
audin_buf.data_offset = 0; audin_buf.data_offset = 0;
// Prepare the output buffer. // Prepare the output buffer.
audout_buf.next = NULL; audout_buf.next = NULL;
audout_buf.buffer = out_buf_data; audout_buf.buffer = out_buf_data;
audout_buf.buffer_size = buffer_size; audout_buf.buffer_size = buffer_size;
audout_buf.data_size = data_size; audout_buf.data_size = data_size;
audout_buf.data_offset = 0; audout_buf.data_offset = 0;
// Prepare pointers and counters for released buffers. // Prepare pointers and counters for released buffers.
released_in_buffer = NULL; released_in_buffer = NULL;
released_out_buffer = NULL; released_out_buffer = NULL;
released_in_count = 0; released_in_count = 0;
released_out_count = 0; released_out_count = 0;
// Append the initial input buffer. // Append the initial input buffer.
rc = audinAppendAudioInBuffer(&audin_buf); rc = audinAppendAudioInBuffer(&audin_buf);
printf("audinAppendAudioInBuffer() returned 0x%x\n", rc); printf("audinAppendAudioInBuffer() returned 0x%x\n", rc);
// Append the initial output buffer. // Append the initial output buffer.
rc = audoutAppendAudioOutBuffer(&audout_buf); rc = audoutAppendAudioOutBuffer(&audout_buf);
printf("audoutAppendAudioOutBuffer() returned 0x%x\n", rc); printf("audoutAppendAudioOutBuffer() 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
hidScanInput(); hidScanInput();
//hidKeysDown returns information about which buttons have been just pressed (and they weren't in the previous frame) //hidKeysDown returns information about which buttons have been just pressed (and they weren't in the previous frame)
u32 kDown = hidKeysDown(CONTROLLER_P1_AUTO); u32 kDown = hidKeysDown(CONTROLLER_P1_AUTO);
if (kDown & KEY_PLUS) break; // break in order to return to hbmenu if (kDown & KEY_PLUS) break; // break in order to return to hbmenu
// Wait for audio capture and playback to finish. // Wait for audio capture and playback to finish.
audinWaitCaptureFinish(&released_in_buffer, &released_in_count, U64_MAX); audinWaitCaptureFinish(&released_in_buffer, &released_in_count, U64_MAX);
audoutWaitPlayFinish(&released_out_buffer, &released_out_count, U64_MAX); audoutWaitPlayFinish(&released_out_buffer, &released_out_count, U64_MAX);
// Copy the captured audio data into the playback buffer. // Copy the captured audio data into the playback buffer.
if ((released_in_buffer != NULL) && (released_out_buffer != NULL)) if ((released_in_buffer != NULL) && (released_out_buffer != NULL))
memcpy(released_out_buffer->buffer, released_in_buffer->buffer, released_in_buffer->data_size); memcpy(released_out_buffer->buffer, released_in_buffer->buffer, released_in_buffer->data_size);
// Append the released buffers again. // Append the released buffers again.
audinAppendAudioInBuffer(released_in_buffer); audinAppendAudioInBuffer(released_in_buffer);
audoutAppendAudioOutBuffer(released_out_buffer); audoutAppendAudioOutBuffer(released_out_buffer);
gfxFlushBuffers(); gfxFlushBuffers();
gfxSwapBuffers(); gfxSwapBuffers();
gfxWaitForVsync(); gfxWaitForVsync();
} }
// Stop audio capture. // Stop audio capture.
rc = audinStopAudioIn(); rc = audinStopAudioIn();
printf("audinStopAudioIn() returned 0x%x\n", rc); printf("audinStopAudioIn() returned 0x%x\n", rc);
// Stop audio playback. // Stop audio playback.
rc = audoutStopAudioOut(); rc = audoutStopAudioOut();
printf("audoutStopAudioOut() returned 0x%x\n", rc); printf("audoutStopAudioOut() returned 0x%x\n", rc);
// Terminate the default audio devices. // Terminate the default audio devices.
audinExit(); audinExit();
audoutExit(); audoutExit();
gfxExit(); gfxExit();
return 0; return 0;
} }

View File

@ -12,191 +12,191 @@
#define BYTESPERSAMPLE 2 #define BYTESPERSAMPLE 2
void fill_audio_buffer(void* audio_buffer, size_t offset, size_t size, int frequency) { void fill_audio_buffer(void* audio_buffer, size_t offset, size_t size, int frequency) {
if (audio_buffer == NULL) return; if (audio_buffer == NULL) return;
u32* dest = (u32*) audio_buffer; u32* dest = (u32*) audio_buffer;
for (int i = 0; i < size; i++) { for (int i = 0; i < size; i++) {
// This is a simple sine wave, with a frequency of `frequency` Hz, and an amplitude 30% of maximum. // This is a simple sine wave, with a frequency of `frequency` Hz, and an amplitude 30% of maximum.
s16 sample = 0.3 * 0x7FFF * sin(frequency * (2 * M_PI) * (offset + i) / SAMPLERATE); s16 sample = 0.3 * 0x7FFF * sin(frequency * (2 * M_PI) * (offset + i) / SAMPLERATE);
// Stereo samples are interleaved: left and right channels. // Stereo samples are interleaved: left and right channels.
dest[i] = (sample << 16) | (sample & 0xffff); dest[i] = (sample << 16) | (sample & 0xffff);
} }
} }
int main(int argc, char **argv) int main(int argc, char **argv)
{ {
Result rc = 0; Result rc = 0;
int notefreq[] = { int notefreq[] = {
220, 220,
440, 880, 1760, 3520, 7040, 440, 880, 1760, 3520, 7040,
14080, 14080,
7040, 3520, 1760, 880, 440 7040, 3520, 1760, 880, 440
}; };
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);
AudioOutBuffer audout_buf; AudioOutBuffer audout_buf;
AudioOutBuffer *audout_released_buf; AudioOutBuffer *audout_released_buf;
// Make sure the sample buffer size is aligned to 0x1000 bytes. // Make sure the sample buffer size is aligned to 0x1000 bytes.
u32 data_size = (SAMPLECOUNT * CHANNELCOUNT * BYTESPERSAMPLE); u32 data_size = (SAMPLECOUNT * CHANNELCOUNT * BYTESPERSAMPLE);
u32 buffer_size = (data_size + 0xfff) & ~0xfff; u32 buffer_size = (data_size + 0xfff) & ~0xfff;
// Allocate the buffer. // Allocate the buffer.
u8* out_buf_data = memalign(0x1000, buffer_size); u8* out_buf_data = memalign(0x1000, buffer_size);
// Ensure buffers were properly allocated. // Ensure buffers were properly allocated.
if (out_buf_data == NULL) if (out_buf_data == NULL)
{ {
rc = MAKERESULT(Module_Libnx, LibnxError_OutOfMemory); rc = MAKERESULT(Module_Libnx, LibnxError_OutOfMemory);
printf("Failed to allocate sample data buffers\n"); printf("Failed to allocate sample data buffers\n");
} }
if (R_SUCCEEDED(rc)) if (R_SUCCEEDED(rc))
memset(out_buf_data, 0, buffer_size); memset(out_buf_data, 0, buffer_size);
if (R_SUCCEEDED(rc)) if (R_SUCCEEDED(rc))
{ {
// Initialize the default audio output device. // Initialize the default audio output device.
rc = audoutInitialize(); rc = audoutInitialize();
printf("audoutInitialize() returned 0x%x\n", rc); printf("audoutInitialize() returned 0x%x\n", rc);
} }
if (R_SUCCEEDED(rc)) if (R_SUCCEEDED(rc))
{ {
printf("Sample rate: 0x%x\n", audoutGetSampleRate()); printf("Sample rate: 0x%x\n", audoutGetSampleRate());
printf("Channel count: 0x%x\n", audoutGetChannelCount()); printf("Channel count: 0x%x\n", audoutGetChannelCount());
printf("PCM format: 0x%x\n", audoutGetPcmFormat()); printf("PCM format: 0x%x\n", audoutGetPcmFormat());
printf("Device state: 0x%x\n", audoutGetDeviceState()); printf("Device state: 0x%x\n", audoutGetDeviceState());
// Start audio playback. // Start audio playback.
rc = audoutStartAudioOut(); rc = audoutStartAudioOut();
printf("audoutStartAudioOut() returned 0x%x\n", rc); printf("audoutStartAudioOut() returned 0x%x\n", rc);
} }
bool play_tone = false; bool play_tone = false;
printf("Press A, B, Y, X, Left, Up, Right, Down, L, R, ZL or ZR to play a different tone.\n"); printf("Press A, B, Y, X, Left, Up, Right, Down, L, R, ZL or ZR to play a different tone.\n");
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
hidScanInput(); hidScanInput();
//hidKeysDown returns information about which buttons have been just pressed (and they weren't in the previous frame) //hidKeysDown returns information about which buttons have been just pressed (and they weren't in the previous frame)
u32 kDown = hidKeysDown(CONTROLLER_P1_AUTO); u32 kDown = hidKeysDown(CONTROLLER_P1_AUTO);
if (kDown & KEY_PLUS) break; // break in order to return to hbmenu if (kDown & KEY_PLUS) break; // break in order to return to hbmenu
if (kDown & KEY_A) if (kDown & KEY_A)
{ {
fill_audio_buffer(out_buf_data, 0, data_size, notefreq[0]); fill_audio_buffer(out_buf_data, 0, data_size, notefreq[0]);
play_tone = true; play_tone = true;
} }
if (kDown & KEY_B) if (kDown & KEY_B)
{ {
fill_audio_buffer(out_buf_data, 0, data_size, notefreq[1]); fill_audio_buffer(out_buf_data, 0, data_size, notefreq[1]);
play_tone = true; play_tone = true;
} }
if (kDown & KEY_Y) if (kDown & KEY_Y)
{ {
fill_audio_buffer(out_buf_data, 0, data_size, notefreq[2]); fill_audio_buffer(out_buf_data, 0, data_size, notefreq[2]);
play_tone = true; play_tone = true;
} }
if (kDown & KEY_X) if (kDown & KEY_X)
{ {
fill_audio_buffer(out_buf_data, 0, data_size, notefreq[3]); fill_audio_buffer(out_buf_data, 0, data_size, notefreq[3]);
play_tone = true; play_tone = true;
} }
if (kDown & KEY_DLEFT) if (kDown & KEY_DLEFT)
{ {
fill_audio_buffer(out_buf_data, 0, data_size, notefreq[4]); fill_audio_buffer(out_buf_data, 0, data_size, notefreq[4]);
play_tone = true; play_tone = true;
} }
if (kDown & KEY_DUP) if (kDown & KEY_DUP)
{ {
fill_audio_buffer(out_buf_data, 0, data_size, notefreq[5]); fill_audio_buffer(out_buf_data, 0, data_size, notefreq[5]);
play_tone = true; play_tone = true;
} }
if (kDown & KEY_DRIGHT) if (kDown & KEY_DRIGHT)
{ {
fill_audio_buffer(out_buf_data, 0, data_size, notefreq[6]); fill_audio_buffer(out_buf_data, 0, data_size, notefreq[6]);
play_tone = true; play_tone = true;
} }
if (kDown & KEY_DDOWN) if (kDown & KEY_DDOWN)
{ {
fill_audio_buffer(out_buf_data, 0, data_size, notefreq[7]); fill_audio_buffer(out_buf_data, 0, data_size, notefreq[7]);
play_tone = true; play_tone = true;
} }
if (kDown & KEY_L) if (kDown & KEY_L)
{ {
fill_audio_buffer(out_buf_data, 0, data_size, notefreq[8]); fill_audio_buffer(out_buf_data, 0, data_size, notefreq[8]);
play_tone = true; play_tone = true;
} }
if (kDown & KEY_R) if (kDown & KEY_R)
{ {
fill_audio_buffer(out_buf_data, 0, data_size, notefreq[9]); fill_audio_buffer(out_buf_data, 0, data_size, notefreq[9]);
play_tone = true; play_tone = true;
} }
if (kDown & KEY_ZL) if (kDown & KEY_ZL)
{ {
fill_audio_buffer(out_buf_data, 0, data_size, notefreq[10]); fill_audio_buffer(out_buf_data, 0, data_size, notefreq[10]);
play_tone = true; play_tone = true;
} }
if (kDown & KEY_ZR) if (kDown & KEY_ZR)
{ {
fill_audio_buffer(out_buf_data, 0, data_size, notefreq[11]); fill_audio_buffer(out_buf_data, 0, data_size, notefreq[11]);
play_tone = true; play_tone = true;
} }
if (R_SUCCEEDED(rc) && play_tone) if (R_SUCCEEDED(rc) && play_tone)
{ {
// Prepare the audio data source buffer. // Prepare the audio data source buffer.
audout_buf.next = NULL; audout_buf.next = NULL;
audout_buf.buffer = out_buf_data; audout_buf.buffer = out_buf_data;
audout_buf.buffer_size = buffer_size; audout_buf.buffer_size = buffer_size;
audout_buf.data_size = data_size; audout_buf.data_size = data_size;
audout_buf.data_offset = 0; audout_buf.data_offset = 0;
// Prepare pointer for the released buffer. // Prepare pointer for the released buffer.
audout_released_buf = NULL; audout_released_buf = NULL;
// Play the buffer. // Play the buffer.
rc = audoutPlayBuffer(&audout_buf, &audout_released_buf); rc = audoutPlayBuffer(&audout_buf, &audout_released_buf);
if (R_FAILED(rc)) if (R_FAILED(rc))
printf("audoutPlayBuffer() returned 0x%x\n", rc); printf("audoutPlayBuffer() returned 0x%x\n", rc);
play_tone = false; play_tone = false;
} }
gfxFlushBuffers(); gfxFlushBuffers();
gfxSwapBuffers(); gfxSwapBuffers();
gfxWaitForVsync(); gfxWaitForVsync();
} }
// Stop audio playback. // Stop audio playback.
rc = audoutStopAudioOut(); rc = audoutStopAudioOut();
printf("audoutStopAudioOut() returned 0x%x\n", rc); printf("audoutStopAudioOut() returned 0x%x\n", rc);
// Terminate the default audio output device. // Terminate the default audio output device.
audoutExit(); audoutExit();
gfxExit(); gfxExit();
return 0; return 0;
} }

View File

@ -5,60 +5,60 @@
void printfile(const char* path) void printfile(const char* path)
{ {
FILE* f = fopen(path, "r"); FILE* f = fopen(path, "r");
if (f) if (f)
{ {
char mystring[100]; char mystring[100];
while (fgets(mystring, sizeof(mystring), f)) while (fgets(mystring, sizeof(mystring), f))
{ {
int a = strlen(mystring); int a = strlen(mystring);
if (mystring[a-1] == '\n') if (mystring[a-1] == '\n')
{ {
mystring[a-1] = 0; mystring[a-1] = 0;
if (mystring[a-2] == '\r') if (mystring[a-2] == '\r')
mystring[a-2] = 0; mystring[a-2] = 0;
} }
puts(mystring); puts(mystring);
} }
printf(">>EOF<<\n"); printf(">>EOF<<\n");
fclose(f); fclose(f);
} }
} }
int main(int argc, char **argv) int main(int argc, char **argv)
{ {
gfxInitDefault(); gfxInitDefault();
consoleInit(NULL); consoleInit(NULL);
Result rc = romfsInit(); Result rc = romfsInit();
if (rc) if (rc)
printf("romfsInit: %08X\n", rc); printf("romfsInit: %08X\n", rc);
else else
{ {
printf("romfs Init Successful!\n"); printf("romfs Init Successful!\n");
printfile("romfs:/folder/file.txt"); printfile("romfs:/folder/file.txt");
// Test reading a file with non-ASCII characters in the name // Test reading a file with non-ASCII characters in the name
printfile("romfs:/フォルダ/ファイル.txt"); printfile("romfs:/フォルダ/ファイル.txt");
} }
// Main loop // Main loop
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
hidScanInput(); hidScanInput();
//hidKeysDown returns information about which buttons have been just pressed (and they weren't in the previous frame) //hidKeysDown returns information about which buttons have been just pressed (and they weren't in the previous frame)
u32 kDown = hidKeysDown(CONTROLLER_P1_AUTO); u32 kDown = hidKeysDown(CONTROLLER_P1_AUTO);
if (kDown & KEY_PLUS) break; // break in order to return to hbmenu if (kDown & KEY_PLUS) break; // break in order to return to hbmenu
gfxFlushBuffers(); gfxFlushBuffers();
gfxSwapBuffers(); gfxSwapBuffers();
gfxWaitForVsync(); gfxWaitForVsync();
} }
romfsExit(); romfsExit();
gfxExit(); gfxExit();
return 0; return 0;
} }

View File

@ -9,45 +9,45 @@
int main(int argc, char **argv) int main(int argc, char **argv)
{ {
gfxInitDefault(); gfxInitDefault();
consoleInit(NULL); consoleInit(NULL);
DIR* dir; DIR* dir;
struct dirent* ent; struct dirent* ent;
dir = opendir("");//Open current-working-directory. dir = opendir("");//Open current-working-directory.
if(dir==NULL) if(dir==NULL)
{ {
printf("Failed to open dir.\n"); printf("Failed to open dir.\n");
} }
else else
{ {
printf("Dir-listing for '':\n"); printf("Dir-listing for '':\n");
while ((ent = readdir(dir))) while ((ent = readdir(dir)))
{ {
printf("d_name: %s\n", ent->d_name); printf("d_name: %s\n", ent->d_name);
} }
closedir(dir); closedir(dir);
printf("Done.\n"); printf("Done.\n");
} }
// Main loop // Main loop
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
hidScanInput(); hidScanInput();
//hidKeysDown returns information about which buttons have been just pressed (and they weren't in the previous frame) //hidKeysDown returns information about which buttons have been just pressed (and they weren't in the previous frame)
u32 kDown = hidKeysDown(CONTROLLER_P1_AUTO); u32 kDown = hidKeysDown(CONTROLLER_P1_AUTO);
if (kDown & KEY_PLUS) break; // break in order to return to hbmenu if (kDown & KEY_PLUS) break; // break in order to return to hbmenu
gfxFlushBuffers(); gfxFlushBuffers();
gfxSwapBuffers(); gfxSwapBuffers();
gfxWaitForVsync(); gfxWaitForVsync();
} }
gfxExit(); gfxExit();
return 0; return 0;
} }

View File

@ -5,32 +5,32 @@
int main(int argc, char **argv) int main(int argc, char **argv)
{ {
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);
//Move the cursor to row 16 and column 20 and then prints "Hello World!" //Move the cursor to row 16 and column 20 and then prints "Hello World!"
//To move the cursor you have to print "\x1b[r;cH", where r and c are respectively //To move the cursor you have to print "\x1b[r;cH", where r and c are respectively
//the row and column where you want your cursor to move //the row and column where you want your cursor to move
printf("\x1b[16;20HHello World!"); printf("\x1b[16;20HHello World!");
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
hidScanInput(); hidScanInput();
//hidKeysDown returns information about which buttons have been just pressed (and they weren't in the previous frame) //hidKeysDown returns information about which buttons have been just pressed (and they weren't in the previous frame)
u32 kDown = hidKeysDown(CONTROLLER_P1_AUTO); u32 kDown = hidKeysDown(CONTROLLER_P1_AUTO);
if (kDown & KEY_PLUS) break; // break in order to return to hbmenu if (kDown & KEY_PLUS) break; // break in order to return to hbmenu
gfxFlushBuffers(); gfxFlushBuffers();
gfxSwapBuffers(); gfxSwapBuffers();
gfxWaitForVsync(); gfxWaitForVsync();
} }
gfxExit(); gfxExit();
return 0; return 0;
} }

View File

@ -5,80 +5,80 @@
int main(int argc, char **argv) int main(int argc, char **argv)
{ {
gfxInitDefault(); gfxInitDefault();
consoleInit(NULL); consoleInit(NULL);
// clear screen and home cursor // clear screen and home cursor
printf( CONSOLE_ESC(2J) ); printf( CONSOLE_ESC(2J) );
// Set print co-ordinates // Set print co-ordinates
// /x1b[row;columnH // /x1b[row;columnH
printf(CONSOLE_ESC(10;10H) "VT52 codes demo"); printf(CONSOLE_ESC(10;10H) "VT52 codes demo");
// move cursor up // move cursor up
// /x1b[linesA // /x1b[linesA
printf(CONSOLE_ESC(10A)"Line 0"); printf(CONSOLE_ESC(10A)"Line 0");
// move cursor left // move cursor left
// /x1b[columnsD // /x1b[columnsD
printf(CONSOLE_ESC(28D)"Column 0"); printf(CONSOLE_ESC(28D)"Column 0");
// move cursor down // move cursor down
// /x1b[linesB // /x1b[linesB
printf(CONSOLE_ESC(19B)"Line 19"); printf(CONSOLE_ESC(19B)"Line 19");
// move cursor right // move cursor right
// /x1b[columnsC // /x1b[columnsC
printf(CONSOLE_ESC(5C)"Column 20"); printf(CONSOLE_ESC(5C)"Column 20");
printf("\n"); printf("\n");
// Color codes and attributes // Color codes and attributes
for(int i=0; i<8; i++) for(int i=0; i<8; i++)
{ {
printf( CONSOLE_ESC(%1$d;1m) /* Set color */ printf( CONSOLE_ESC(%1$d;1m) /* Set color */
"Default " "Default "
CONSOLE_ESC(1m) "Bold " CONSOLE_ESC(1m) "Bold "
CONSOLE_ESC(7m) "Reversed " CONSOLE_ESC(7m) "Reversed "
CONSOLE_ESC(0m) /* revert attributes*/ CONSOLE_ESC(0m) /* revert attributes*/
CONSOLE_ESC(%1$d;1m) CONSOLE_ESC(%1$d;1m)
CONSOLE_ESC(2m) "Light " CONSOLE_ESC(2m) "Light "
CONSOLE_ESC(7m) "Reversed " CONSOLE_ESC(7m) "Reversed "
CONSOLE_ESC(0m) /* revert attributes*/ CONSOLE_ESC(0m) /* revert attributes*/
CONSOLE_ESC(%1$d;1m) CONSOLE_ESC(%1$d;1m)
CONSOLE_ESC(4m) "Underline " CONSOLE_ESC(4m) "Underline "
CONSOLE_ESC(0m) /* revert attributes*/ CONSOLE_ESC(0m) /* revert attributes*/
CONSOLE_ESC(%1$d;1m) CONSOLE_ESC(%1$d;1m)
CONSOLE_ESC(9m) "Strikethrough " CONSOLE_ESC(9m) "Strikethrough "
"\n" "\n"
CONSOLE_ESC(0m) /* revert attributes*/ CONSOLE_ESC(0m) /* revert attributes*/
, i + 30); , i + 30);
} }
// Main loop // Main loop
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
hidScanInput(); hidScanInput();
// Your code goes here // Your code goes here
//hidKeysDown returns information about which buttons have been just pressed (and they weren't in the previous frame) //hidKeysDown returns information about which buttons have been just pressed (and they weren't in the previous frame)
u32 kDown = hidKeysDown(CONTROLLER_P1_AUTO); u32 kDown = hidKeysDown(CONTROLLER_P1_AUTO);
if (kDown & KEY_PLUS) break; // break in order to return to hbmenu if (kDown & KEY_PLUS) break; // break in order to return to hbmenu
gfxFlushBuffers(); gfxFlushBuffers();
gfxSwapBuffers(); gfxSwapBuffers();
gfxWaitForVsync(); gfxWaitForVsync();
} }
gfxExit(); gfxExit();
return 0; return 0;
} }

View File

@ -10,63 +10,63 @@
int main(int argc, char **argv) int main(int argc, char **argv)
{ {
u32* framebuf; u32* framebuf;
u32 cnt=0; u32 cnt=0;
#ifdef DISPLAY_IMAGE #ifdef DISPLAY_IMAGE
u8* imageptr = (u8*)image_bin; u8* imageptr = (u8*)image_bin;
#endif #endif
//Enable max-1080p support. Remove for 720p-only resolution. //Enable max-1080p support. Remove for 720p-only resolution.
//gfxInitResolutionDefault(); //gfxInitResolutionDefault();
gfxInitDefault(); gfxInitDefault();
//Set current resolution automatically depending on current/changed OperationMode. Only use this when using gfxInitResolution*(). //Set current resolution automatically depending on current/changed OperationMode. Only use this when using gfxInitResolution*().
//gfxConfigureAutoResolutionDefault(true); //gfxConfigureAutoResolutionDefault(true);
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
hidScanInput(); hidScanInput();
//hidKeysDown returns information about which buttons have been just pressed (and they weren't in the previous frame) //hidKeysDown returns information about which buttons have been just pressed (and they weren't in the previous frame)
u32 kDown = hidKeysDown(CONTROLLER_P1_AUTO); u32 kDown = hidKeysDown(CONTROLLER_P1_AUTO);
if (kDown & KEY_PLUS) break; // break in order to return to hbmenu if (kDown & KEY_PLUS) break; // break in order to return to hbmenu
u32 width, height; u32 width, height;
u32 pos; u32 pos;
framebuf = (u32*) gfxGetFramebuffer((u32*)&width, (u32*)&height); framebuf = (u32*) gfxGetFramebuffer((u32*)&width, (u32*)&height);
if(cnt==60) if(cnt==60)
{ {
cnt=0; cnt=0;
} }
else else
{ {
cnt++; cnt++;
} }
//Each pixel is 4-bytes due to RGBA8888. //Each pixel is 4-bytes due to RGBA8888.
u32 x, y; u32 x, y;
for (y=0; y<height; y++)//Access the buffer linearly. for (y=0; y<height; y++)//Access the buffer linearly.
{ {
for (x=0; x<width; x++) for (x=0; x<width; x++)
{ {
pos = y * width + x; pos = y * width + x;
#ifdef DISPLAY_IMAGE #ifdef DISPLAY_IMAGE
framebuf[pos] = RGBA8_MAXALPHA(imageptr[pos*3+0]+(cnt*4), imageptr[pos*3+1], imageptr[pos*3+2]); framebuf[pos] = RGBA8_MAXALPHA(imageptr[pos*3+0]+(cnt*4), imageptr[pos*3+1], imageptr[pos*3+2]);
#else #else
framebuf[pos] = 0x01010101 * cnt * 4;//Set framebuf to different shades of grey. framebuf[pos] = 0x01010101 * cnt * 4;//Set framebuf to different shades of grey.
#endif #endif
} }
} }
gfxFlushBuffers(); gfxFlushBuffers();
gfxSwapBuffers(); gfxSwapBuffers();
gfxWaitForVsync(); gfxWaitForVsync();
} }
gfxExit(); gfxExit();
return 0; return 0;
} }

View File

@ -9,118 +9,118 @@
int main(int argc, char **argv) int main(int argc, char **argv)
{ {
Result rc=0; Result rc=0;
Result rc2=0; Result rc2=0;
u32 irhandle=0; u32 irhandle=0;
irsImageTransferProcessorConfig config; irsImageTransferProcessorConfig config;
irsImageTransferProcessorState state; irsImageTransferProcessorState state;
size_t ir_buffer_size = 0x12c00; size_t ir_buffer_size = 0x12c00;
u8 *ir_buffer = NULL; u8 *ir_buffer = NULL;
u32 width, height; u32 width, height;
u32 ir_width, ir_height; u32 ir_width, ir_height;
u32 pos, pos2=0; u32 pos, pos2=0;
u32* framebuf; u32* framebuf;
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);
ir_buffer = (u8*)malloc(ir_buffer_size); ir_buffer = (u8*)malloc(ir_buffer_size);
if (ir_buffer==NULL) if (ir_buffer==NULL)
{ {
rc = MAKERESULT(Module_Libnx, LibnxError_OutOfMemory); rc = MAKERESULT(Module_Libnx, LibnxError_OutOfMemory);
printf("Failed to allocate memory for ir_buffer.\n"); printf("Failed to allocate memory for ir_buffer.\n");
} }
else else
{ {
memset(ir_buffer, 0, ir_buffer_size); memset(ir_buffer, 0, ir_buffer_size);
} }
if (R_SUCCEEDED(rc)) if (R_SUCCEEDED(rc))
{ {
rc = irsInitialize(); rc = irsInitialize();
printf("irsInitialize() returned 0x%x\n", rc); printf("irsInitialize() returned 0x%x\n", rc);
} }
if (R_SUCCEEDED(rc)) if (R_SUCCEEDED(rc))
{ {
rc = irsActivateIrsensor(1); rc = irsActivateIrsensor(1);
printf("irsActivateIrsensor() returned 0x%x\n", rc); printf("irsActivateIrsensor() returned 0x%x\n", rc);
} }
if (R_SUCCEEDED(rc)) if (R_SUCCEEDED(rc))
{ {
rc = irsGetIrCameraHandle(&irhandle, CONTROLLER_PLAYER_1); rc = irsGetIrCameraHandle(&irhandle, CONTROLLER_PLAYER_1);
printf("irsGetIrCameraHandle() returned 0x%x\n", rc); printf("irsGetIrCameraHandle() returned 0x%x\n", rc);
} }
if (R_SUCCEEDED(rc)) if (R_SUCCEEDED(rc))
{ {
irsGetDefaultImageTransferProcessorConfig(&config); irsGetDefaultImageTransferProcessorConfig(&config);
rc = irsRunImageTransferProcessor(irhandle, &config, 0x100000); rc = irsRunImageTransferProcessor(irhandle, &config, 0x100000);
printf("irsRunImageTransferProcessor() returned 0x%x\n", rc); printf("irsRunImageTransferProcessor() returned 0x%x\n", rc);
} }
if (R_SUCCEEDED(rc)) if (R_SUCCEEDED(rc))
{ {
//Switch to using regular framebuffer. //Switch to using regular framebuffer.
consoleClear(); consoleClear();
gfxSetMode(GfxMode_LinearDouble); gfxSetMode(GfxMode_LinearDouble);
} }
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
hidScanInput(); hidScanInput();
//hidKeysDown returns information about which buttons have been just pressed (and they weren't in the previous frame) //hidKeysDown returns information about which buttons have been just pressed (and they weren't in the previous frame)
u32 kDown = hidKeysDown(CONTROLLER_P1_AUTO); u32 kDown = hidKeysDown(CONTROLLER_P1_AUTO);
if (kDown & KEY_PLUS) break; // break in order to return to hbmenu if (kDown & KEY_PLUS) break; // break in order to return to hbmenu
if (R_SUCCEEDED(rc)) if (R_SUCCEEDED(rc))
{ {
framebuf = (u32*) gfxGetFramebuffer((u32*)&width, (u32*)&height); 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. //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. //This will return an error when no image is available yet.
rc2 = irsGetImageTransferProcessorState(irhandle, ir_buffer, ir_buffer_size, &state); rc2 = irsGetImageTransferProcessorState(irhandle, ir_buffer, ir_buffer_size, &state);
if (R_SUCCEEDED(rc2)) if (R_SUCCEEDED(rc2))
{ {
memset(framebuf, 0, gfxGetFramebufferSize()); memset(framebuf, 0, gfxGetFramebufferSize());
//IR image width/height with the default config. //IR image width/height with the default config.
//The image is grayscale (1 byte per pixel / 8bits, with 1 color-component). //The image is grayscale (1 byte per pixel / 8bits, with 1 color-component).
ir_width = 240; ir_width = 240;
ir_height = 320; ir_height = 320;
u32 x, y; u32 x, y;
for (y=0; y<ir_height; y++)//Access the buffer linearly. for (y=0; y<ir_height; y++)//Access the buffer linearly.
{ {
for (x=0; x<ir_width; x++) for (x=0; x<ir_width; x++)
{ {
pos = y * width + x; pos = y * width + x;
pos2 = x * ir_height + y;//The IR image/camera is sideways with the joycon held flat. pos2 = x * ir_height + y;//The IR image/camera is sideways with the joycon held flat.
framebuf[pos] = RGBA8_MAXALPHA(/*ir_buffer[pos2]*/0, ir_buffer[pos2], /*ir_buffer[pos2]*/0); framebuf[pos] = RGBA8_MAXALPHA(/*ir_buffer[pos2]*/0, ir_buffer[pos2], /*ir_buffer[pos2]*/0);
} }
} }
} }
} }
gfxFlushBuffers(); gfxFlushBuffers();
gfxSwapBuffers(); gfxSwapBuffers();
gfxWaitForVsync(); gfxWaitForVsync();
} }
irsStopImageProcessor(irhandle); irsStopImageProcessor(irhandle);
irsExit(); irsExit();
free(ir_buffer); free(ir_buffer);
gfxExit(); gfxExit();
return 0; return 0;
} }

View File

@ -7,86 +7,86 @@
int main(int argc, char **argv) int main(int argc, char **argv)
{ {
//Matrix containing the name of each key. Useful for printing when a key is pressed //Matrix containing the name of each key. Useful for printing when a key is pressed
char keysNames[32][32] = { char keysNames[32][32] = {
"KEY_A", "KEY_B", "KEY_X", "KEY_Y", "KEY_A", "KEY_B", "KEY_X", "KEY_Y",
"KEY_LSTICK", "KEY_RSTICK", "KEY_L", "KEY_R", "KEY_LSTICK", "KEY_RSTICK", "KEY_L", "KEY_R",
"KEY_ZL", "KEY_ZR", "KEY_PLUS", "KEY_MINUS", "KEY_ZL", "KEY_ZR", "KEY_PLUS", "KEY_MINUS",
"KEY_DLEFT", "KEY_DUP", "KEY_DRIGHT", "KEY_DDOWN", "KEY_DLEFT", "KEY_DUP", "KEY_DRIGHT", "KEY_DDOWN",
"KEY_LSTICK_LEFT", "KEY_LSTICK_UP", "KEY_LSTICK_RIGHT", "KEY_LSTICK_DOWN", "KEY_LSTICK_LEFT", "KEY_LSTICK_UP", "KEY_LSTICK_RIGHT", "KEY_LSTICK_DOWN",
"KEY_RSTICK_LEFT", "KEY_RSTICK_UP", "KEY_RSTICK_RIGHT", "KEY_RSTICK_DOWN", "KEY_RSTICK_LEFT", "KEY_RSTICK_UP", "KEY_RSTICK_RIGHT", "KEY_RSTICK_DOWN",
"KEY_SL", "KEY_SR", "KEY_TOUCH", "", "KEY_SL", "KEY_SR", "KEY_TOUCH", "",
"", "", "", "" "", "", "", ""
}; };
gfxInitDefault(); gfxInitDefault();
consoleInit(NULL); consoleInit(NULL);
u32 kDownOld = 0, kHeldOld = 0, kUpOld = 0; //In these variables there will be information about keys detected in the previous frame u32 kDownOld = 0, kHeldOld = 0, kUpOld = 0; //In these variables there will be information about keys detected in the previous frame
printf("\x1b[1;1HPress PLUS to exit."); printf("\x1b[1;1HPress PLUS to exit.");
printf("\x1b[2;1HLeft joystick position:"); printf("\x1b[2;1HLeft joystick position:");
printf("\x1b[4;1HRight joystick position:"); printf("\x1b[4;1HRight joystick position:");
// Main loop // Main loop
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
hidScanInput(); hidScanInput();
//hidKeysDown returns information about which buttons have been just pressed (and they weren't in the previous frame) //hidKeysDown returns information about which buttons have been just pressed (and they weren't in the previous frame)
u32 kDown = hidKeysDown(CONTROLLER_P1_AUTO); u32 kDown = hidKeysDown(CONTROLLER_P1_AUTO);
//hidKeysHeld returns information about which buttons have are held down in this frame //hidKeysHeld returns information about which buttons have are held down in this frame
u32 kHeld = hidKeysHeld(CONTROLLER_P1_AUTO); u32 kHeld = hidKeysHeld(CONTROLLER_P1_AUTO);
//hidKeysUp returns information about which buttons have been just released //hidKeysUp returns information about which buttons have been just released
u32 kUp = hidKeysUp(CONTROLLER_P1_AUTO); u32 kUp = hidKeysUp(CONTROLLER_P1_AUTO);
if (kDown & KEY_PLUS) break; // break in order to return to hbmenu if (kDown & KEY_PLUS) break; // break in order to return to hbmenu
//Do the keys printing only if keys have changed //Do the keys printing only if keys have changed
if (kDown != kDownOld || kHeld != kHeldOld || kUp != kUpOld) if (kDown != kDownOld || kHeld != kHeldOld || kUp != kUpOld)
{ {
//Clear console //Clear console
consoleClear(); consoleClear();
//These two lines must be rewritten because we cleared the whole console //These two lines must be rewritten because we cleared the whole console
printf("\x1b[1;1HPress PLUS to exit."); printf("\x1b[1;1HPress PLUS to exit.");
printf("\x1b[2;1HLeft joystick position:"); printf("\x1b[2;1HLeft joystick position:");
printf("\x1b[4;1HRight joystick position:"); printf("\x1b[4;1HRight joystick position:");
printf("\x1b[6;1H"); //Move the cursor to the sixth row because on the previous ones we'll write the joysticks' position printf("\x1b[6;1H"); //Move the cursor to the sixth row because on the previous ones we'll write the joysticks' position
//Check if some of the keys are down, held or up //Check if some of the keys are down, held or up
int i; int i;
for (i = 0; i < 32; i++) for (i = 0; i < 32; i++)
{ {
if (kDown & BIT(i)) printf("%s down\n", keysNames[i]); if (kDown & BIT(i)) printf("%s down\n", keysNames[i]);
if (kHeld & BIT(i)) printf("%s held\n", keysNames[i]); if (kHeld & BIT(i)) printf("%s held\n", keysNames[i]);
if (kUp & BIT(i)) printf("%s up\n", keysNames[i]); if (kUp & BIT(i)) printf("%s up\n", keysNames[i]);
} }
} }
//Set keys old values for the next frame //Set keys old values for the next frame
kDownOld = kDown; kDownOld = kDown;
kHeldOld = kHeld; kHeldOld = kHeld;
kUpOld = kUp; kUpOld = kUp;
JoystickPosition pos_left, pos_right; JoystickPosition pos_left, pos_right;
//Read the joysticks' position //Read the joysticks' position
hidJoystickRead(&pos_left, CONTROLLER_P1_AUTO, JOYSTICK_LEFT); hidJoystickRead(&pos_left, CONTROLLER_P1_AUTO, JOYSTICK_LEFT);
hidJoystickRead(&pos_right, CONTROLLER_P1_AUTO, JOYSTICK_RIGHT); hidJoystickRead(&pos_right, CONTROLLER_P1_AUTO, JOYSTICK_RIGHT);
//Print the joysticks' position //Print the joysticks' position
printf("\x1b[3;1H%04d; %04d", pos_left.dx, pos_left.dy); printf("\x1b[3;1H%04d; %04d", pos_left.dx, pos_left.dy);
printf("\x1b[5;1H%04d; %04d", pos_right.dx, pos_right.dy); printf("\x1b[5;1H%04d; %04d", pos_right.dx, pos_right.dy);
gfxFlushBuffers(); gfxFlushBuffers();
gfxSwapBuffers(); gfxSwapBuffers();
gfxWaitForVsync(); gfxWaitForVsync();
} }
gfxExit(); gfxExit();
return 0; return 0;
} }

View File

@ -7,57 +7,57 @@
int main(int argc, char **argv) int main(int argc, char **argv)
{ {
u32 prev_touchcount=0; u32 prev_touchcount=0;
gfxInitDefault(); gfxInitDefault();
consoleInit(NULL); consoleInit(NULL);
printf("\x1b[1;1HPress PLUS to exit."); printf("\x1b[1;1HPress PLUS to exit.");
printf("\x1b[2;1HTouch Screen position:"); printf("\x1b[2;1HTouch Screen position:");
// Main loop // Main loop
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
hidScanInput(); hidScanInput();
//hidKeysDown returns information about which buttons have been just pressed (and they weren't in the previous frame) //hidKeysDown returns information about which buttons have been just pressed (and they weren't in the previous frame)
u32 kDown = hidKeysDown(CONTROLLER_P1_AUTO); u32 kDown = hidKeysDown(CONTROLLER_P1_AUTO);
if (kDown & KEY_PLUS) break; // break in order to return to hbmenu if (kDown & KEY_PLUS) break; // break in order to return to hbmenu
touchPosition touch; touchPosition touch;
u32 i; u32 i;
u32 touch_count = hidTouchCount(); u32 touch_count = hidTouchCount();
if (touch_count != prev_touchcount) if (touch_count != prev_touchcount)
{ {
prev_touchcount = touch_count; prev_touchcount = touch_count;
consoleClear(); consoleClear();
printf("\x1b[1;1HPress PLUS to exit."); printf("\x1b[1;1HPress PLUS to exit.");
printf("\x1b[2;1HTouch Screen position:"); printf("\x1b[2;1HTouch Screen position:");
} }
printf("\x1b[3;1H"); printf("\x1b[3;1H");
for(i=0; i<touch_count; i++) for(i=0; i<touch_count; i++)
{ {
//Read the touch screen coordinates //Read the touch screen coordinates
hidTouchRead(&touch, i); hidTouchRead(&touch, i);
//Print the touch screen coordinates //Print the touch screen coordinates
printf("[point_id=%d] px=%03d, py=%03d, dx=%03d, dy=%03d, angle=%03d\n", i, touch.px, touch.py, touch.dx, touch.dy, touch.angle); printf("[point_id=%d] px=%03d, py=%03d, dx=%03d, dy=%03d, angle=%03d\n", i, touch.px, touch.py, touch.dx, touch.dy, touch.angle);
} }
gfxFlushBuffers(); gfxFlushBuffers();
gfxSwapBuffers(); gfxSwapBuffers();
gfxWaitForVsync(); gfxWaitForVsync();
} }
gfxExit(); gfxExit();
return 0; return 0;
} }

View File

@ -7,78 +7,78 @@
int main(int argc, char **argv) int main(int argc, char **argv)
{ {
u32 VibrationDeviceHandles[2]; u32 VibrationDeviceHandles[2];
Result rc = 0, rc2 = 0; Result rc = 0, rc2 = 0;
HidVibrationValue VibrationValue; HidVibrationValue VibrationValue;
HidVibrationValue VibrationValue_stop; HidVibrationValue VibrationValue_stop;
gfxInitDefault(); gfxInitDefault();
consoleInit(NULL); consoleInit(NULL);
printf("Press PLUS to exit.\n"); printf("Press PLUS to exit.\n");
//Two VibrationDeviceHandles are returned: first one for left-joycon, second one for right-joycon. //Two VibrationDeviceHandles are returned: first one for left-joycon, second one for right-joycon.
rc = hidInitializeVibrationDevices(VibrationDeviceHandles, 2, CONTROLLER_PLAYER_1, LAYOUT_DEFAULT); rc = hidInitializeVibrationDevices(VibrationDeviceHandles, 2, CONTROLLER_PLAYER_1, LAYOUT_DEFAULT);
printf("hidInitializeVibrationDevice() returned: 0x%x\n", rc); printf("hidInitializeVibrationDevice() returned: 0x%x\n", rc);
if (R_SUCCEEDED(rc)) printf("Hold R to vibrate, and press A/B/X/Y to adjust values.\n"); if (R_SUCCEEDED(rc)) printf("Hold R to vibrate, and press A/B/X/Y to adjust values.\n");
VibrationValue.amp_low = 0.2f; VibrationValue.amp_low = 0.2f;
VibrationValue.freq_low = 10.0f; VibrationValue.freq_low = 10.0f;
VibrationValue.amp_high = 0.2f; VibrationValue.amp_high = 0.2f;
VibrationValue.freq_high = 10.0f; VibrationValue.freq_high = 10.0f;
memset(&VibrationValue_stop, 0, sizeof(HidVibrationValue)); memset(&VibrationValue_stop, 0, sizeof(HidVibrationValue));
// Switch like stop behavior with muted band channels and frequencies set to default. // Switch like stop behavior with muted band channels and frequencies set to default.
VibrationValue_stop.freq_low = 160.0f; VibrationValue_stop.freq_low = 160.0f;
VibrationValue_stop.freq_high = 320.0f; VibrationValue_stop.freq_high = 320.0f;
// Main loop // Main loop
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
hidScanInput(); hidScanInput();
//hidKeysDown returns information about which buttons have been just pressed (and they weren't in the previous frame) //hidKeysDown returns information about which buttons have been just pressed (and they weren't in the previous frame)
u32 kDown = hidKeysDown(CONTROLLER_P1_AUTO); u32 kDown = hidKeysDown(CONTROLLER_P1_AUTO);
u32 kHeld = hidKeysHeld(CONTROLLER_P1_AUTO); u32 kHeld = hidKeysHeld(CONTROLLER_P1_AUTO);
u32 kUp = hidKeysUp(CONTROLLER_P1_AUTO); u32 kUp = hidKeysUp(CONTROLLER_P1_AUTO);
if (kDown & KEY_PLUS) break; // break in order to return to hbmenu if (kDown & KEY_PLUS) break; // break in order to return to hbmenu
if (R_SUCCEEDED(rc) && (kHeld & KEY_R)) if (R_SUCCEEDED(rc) && (kHeld & KEY_R))
{ {
//Calling hidSendVibrationValue is really only needed when sending a new VibrationValue. //Calling hidSendVibrationValue is really only needed when sending a new VibrationValue.
//left-joycon //left-joycon
rc2 = hidSendVibrationValue(&VibrationDeviceHandles[0], &VibrationValue); rc2 = hidSendVibrationValue(&VibrationDeviceHandles[0], &VibrationValue);
if (R_FAILED(rc2)) printf("hidSendVibrationValue() returned: 0x%x\n", rc2); if (R_FAILED(rc2)) printf("hidSendVibrationValue() returned: 0x%x\n", rc2);
//right-joycon //right-joycon
rc2 = hidSendVibrationValue(&VibrationDeviceHandles[1], &VibrationValue); rc2 = hidSendVibrationValue(&VibrationDeviceHandles[1], &VibrationValue);
if (R_FAILED(rc2)) printf("hidSendVibrationValue() returned: 0x%x\n", rc2); if (R_FAILED(rc2)) printf("hidSendVibrationValue() returned: 0x%x\n", rc2);
if (kDown & KEY_A) VibrationValue.amp_low += 0.1f; if (kDown & KEY_A) VibrationValue.amp_low += 0.1f;
if (kDown & KEY_B) VibrationValue.freq_low += 5.0f; if (kDown & KEY_B) VibrationValue.freq_low += 5.0f;
if (kDown & KEY_X) VibrationValue.amp_high += 0.1f; if (kDown & KEY_X) VibrationValue.amp_high += 0.1f;
if (kDown & KEY_Y) VibrationValue.freq_high += 12.0f; if (kDown & KEY_Y) VibrationValue.freq_high += 12.0f;
} }
else if(kUp & KEY_R)//Stop vibration. else if(kUp & KEY_R)//Stop vibration.
{ {
rc2 = hidSendVibrationValue(&VibrationDeviceHandles[0], &VibrationValue_stop); rc2 = hidSendVibrationValue(&VibrationDeviceHandles[0], &VibrationValue_stop);
if (R_FAILED(rc2)) printf("hidSendVibrationValue() for stop returned: 0x%x\n", rc2); if (R_FAILED(rc2)) printf("hidSendVibrationValue() for stop returned: 0x%x\n", rc2);
rc2 = hidSendVibrationValue(&VibrationDeviceHandles[1], &VibrationValue_stop); rc2 = hidSendVibrationValue(&VibrationDeviceHandles[1], &VibrationValue_stop);
if (R_FAILED(rc2)) printf("hidSendVibrationValue() for stop returned: 0x%x\n", rc2); if (R_FAILED(rc2)) printf("hidSendVibrationValue() for stop returned: 0x%x\n", rc2);
} }
gfxFlushBuffers(); gfxFlushBuffers();
gfxSwapBuffers(); gfxSwapBuffers();
gfxWaitForVsync(); gfxWaitForVsync();
} }
gfxExit(); gfxExit();
return 0; return 0;
} }

View File

@ -7,64 +7,64 @@
int main(int argc, char **argv) int main(int argc, char **argv)
{ {
u64 LanguageCode=0; u64 LanguageCode=0;
s32 Language=0; s32 Language=0;
gfxInitDefault(); gfxInitDefault();
consoleInit(NULL); consoleInit(NULL);
Result rc = setInitialize(); Result rc = setInitialize();
if (R_FAILED(rc)) printf("setInitialize() failed: 0x%x.\n", rc); if (R_FAILED(rc)) printf("setInitialize() failed: 0x%x.\n", rc);
if (R_SUCCEEDED(rc)) if (R_SUCCEEDED(rc))
{ {
//Get system language. //Get system language.
rc = setGetSystemLanguage(&LanguageCode); rc = setGetSystemLanguage(&LanguageCode);
if (R_FAILED(rc)) printf("setGetSystemLanguage() failed: 0x%x.\n", rc); if (R_FAILED(rc)) printf("setGetSystemLanguage() failed: 0x%x.\n", rc);
} }
if (R_SUCCEEDED(rc)) if (R_SUCCEEDED(rc))
{ {
printf("setGetSystemLanguage() LanguageCode: %s\n", (char*)&LanguageCode); printf("setGetSystemLanguage() LanguageCode: %s\n", (char*)&LanguageCode);
// Convert LanguageCode to Language. Use this if you need IDs, not strings. // Convert LanguageCode to Language. Use this if you need IDs, not strings.
rc = setMakeLanguage(LanguageCode, &Language); rc = setMakeLanguage(LanguageCode, &Language);
if (R_FAILED(rc)) printf("setMakeLanguage() failed: 0x%x.\n", rc); if (R_FAILED(rc)) printf("setMakeLanguage() failed: 0x%x.\n", rc);
} }
if (R_SUCCEEDED(rc)) if (R_SUCCEEDED(rc))
{ {
printf("Language: %d\n", Language); printf("Language: %d\n", Language);
// Converts the input Language to LanguageCode. // Converts the input Language to LanguageCode.
rc = setMakeLanguageCode(SetLanguage_JA, &LanguageCode); rc = setMakeLanguageCode(SetLanguage_JA, &LanguageCode);
if (R_FAILED(rc)) printf("setMakeLanguageCode() failed: 0x%x.\n", rc); if (R_FAILED(rc)) printf("setMakeLanguageCode() failed: 0x%x.\n", rc);
} }
if (R_SUCCEEDED(rc)) printf("New LanguageCode: %s\n", (char*)&LanguageCode); if (R_SUCCEEDED(rc)) printf("New LanguageCode: %s\n", (char*)&LanguageCode);
// Main loop // Main loop
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
hidScanInput(); hidScanInput();
// Your code goes here // Your code goes here
//hidKeysDown returns information about which buttons have been just pressed (and they weren't in the previous frame) //hidKeysDown returns information about which buttons have been just pressed (and they weren't in the previous frame)
u32 kDown = hidKeysDown(CONTROLLER_P1_AUTO); u32 kDown = hidKeysDown(CONTROLLER_P1_AUTO);
if (kDown & KEY_PLUS) break; // break in order to return to hbmenu if (kDown & KEY_PLUS) break; // break in order to return to hbmenu
gfxFlushBuffers(); gfxFlushBuffers();
gfxSwapBuffers(); gfxSwapBuffers();
gfxWaitForVsync(); gfxWaitForVsync();
} }
setExit(); setExit();
gfxExit(); gfxExit();
return 0; return 0;
} }

View File

@ -5,30 +5,30 @@
int main(int argc, char **argv) int main(int argc, char **argv)
{ {
gfxInitDefault(); gfxInitDefault();
consoleInit(NULL); consoleInit(NULL);
printf("Hello World!"); printf("Hello World!");
// Main loop // Main loop
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
hidScanInput(); hidScanInput();
// Your code goes here // Your code goes here
//hidKeysDown returns information about which buttons have been just pressed (and they weren't in the previous frame) //hidKeysDown returns information about which buttons have been just pressed (and they weren't in the previous frame)
u32 kDown = hidKeysDown(CONTROLLER_P1_AUTO); u32 kDown = hidKeysDown(CONTROLLER_P1_AUTO);
if (kDown & KEY_PLUS) break; // break in order to return to hbmenu if (kDown & KEY_PLUS) break; // break in order to return to hbmenu
gfxFlushBuffers(); gfxFlushBuffers();
gfxSwapBuffers(); gfxSwapBuffers();
gfxWaitForVsync(); gfxWaitForVsync();
} }
gfxExit(); gfxExit();
return 0; return 0;
} }

View File

@ -1,6 +1,6 @@
int myLibFunction() { int myLibFunction() {
return 42; return 42;
} }

View File

@ -10,43 +10,43 @@ const char* const weekDays[7] = {"Sunday", "Monday", "Tuesday", "Wednesday", "Th
int main(int argc, char **argv) int main(int argc, char **argv)
{ {
gfxInitDefault(); gfxInitDefault();
consoleInit(NULL); consoleInit(NULL);
printf("\x1b[16;16HPress PLUS to exit."); printf("\x1b[16;16HPress PLUS to exit.");
// Main loop // Main loop
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
hidScanInput(); hidScanInput();
//hidKeysDown returns information about which buttons have been just pressed (and they weren't in the previous frame) //hidKeysDown returns information about which buttons have been just pressed (and they weren't in the previous frame)
u32 kDown = hidKeysDown(CONTROLLER_P1_AUTO); u32 kDown = hidKeysDown(CONTROLLER_P1_AUTO);
if (kDown & KEY_PLUS) break; // break in order to return to hbmenu if (kDown & KEY_PLUS) break; // break in order to return to hbmenu
//Print current time //Print current time
time_t unixTime = time(NULL); time_t unixTime = time(NULL);
struct tm* timeStruct = gmtime((const time_t *)&unixTime);//Gets UTC time. Currently localtime() will also return UTC (timezones not supported). struct tm* timeStruct = gmtime((const time_t *)&unixTime);//Gets UTC time. Currently localtime() will also return UTC (timezones not supported).
int hours = timeStruct->tm_hour; int hours = timeStruct->tm_hour;
int minutes = timeStruct->tm_min; int minutes = timeStruct->tm_min;
int seconds = timeStruct->tm_sec; int seconds = timeStruct->tm_sec;
int day = timeStruct->tm_mday; int day = timeStruct->tm_mday;
int month = timeStruct->tm_mon; int month = timeStruct->tm_mon;
int year = timeStruct->tm_year +1900; int year = timeStruct->tm_year +1900;
int wday = timeStruct->tm_wday; int wday = timeStruct->tm_wday;
printf("\x1b[1;1H%02i:%02i:%02i", hours, minutes, seconds); printf("\x1b[1;1H%02i:%02i:%02i", hours, minutes, seconds);
printf("\n%s %s %i %i", weekDays[wday], months[month], day, year); printf("\n%s %s %i %i", weekDays[wday], months[month], day, year);
gfxFlushBuffers(); gfxFlushBuffers();
gfxSwapBuffers(); gfxSwapBuffers();
gfxWaitForVsync(); gfxWaitForVsync();
} }
gfxExit(); gfxExit();
return 0; return 0;
} }

View File

@ -10,136 +10,136 @@
Result usbds_test(u8 *tmpbuf) Result usbds_test(u8 *tmpbuf)
{ {
Result ret=0; Result ret=0;
s32 tmpindex=0; s32 tmpindex=0;
UsbDsInterface* interface = NULL; UsbDsInterface* interface = NULL;
UsbDsEndpoint *endpoint_in = NULL, *endpoint_out = NULL; UsbDsEndpoint *endpoint_in = NULL, *endpoint_out = NULL;
struct usb_interface_descriptor interface_descriptor = { struct usb_interface_descriptor interface_descriptor = {
.bLength = USB_DT_INTERFACE_SIZE, .bLength = USB_DT_INTERFACE_SIZE,
.bDescriptorType = USB_DT_INTERFACE, .bDescriptorType = USB_DT_INTERFACE,
.bInterfaceNumber = USBDS_DEFAULT_InterfaceNumber, .bInterfaceNumber = USBDS_DEFAULT_InterfaceNumber,
.bInterfaceClass = USB_CLASS_VENDOR_SPEC, .bInterfaceClass = USB_CLASS_VENDOR_SPEC,
.bInterfaceSubClass = USB_CLASS_VENDOR_SPEC, .bInterfaceSubClass = USB_CLASS_VENDOR_SPEC,
.bInterfaceProtocol = USB_CLASS_VENDOR_SPEC, .bInterfaceProtocol = USB_CLASS_VENDOR_SPEC,
}; };
struct usb_endpoint_descriptor endpoint_descriptor_in = { struct usb_endpoint_descriptor endpoint_descriptor_in = {
.bLength = USB_DT_ENDPOINT_SIZE, .bLength = USB_DT_ENDPOINT_SIZE,
.bDescriptorType = USB_DT_ENDPOINT, .bDescriptorType = USB_DT_ENDPOINT,
.bEndpointAddress = USB_ENDPOINT_IN, .bEndpointAddress = USB_ENDPOINT_IN,
.bmAttributes = USB_TRANSFER_TYPE_BULK, .bmAttributes = USB_TRANSFER_TYPE_BULK,
.wMaxPacketSize = 0x200, .wMaxPacketSize = 0x200,
}; };
struct usb_endpoint_descriptor endpoint_descriptor_out = { struct usb_endpoint_descriptor endpoint_descriptor_out = {
.bLength = USB_DT_ENDPOINT_SIZE, .bLength = USB_DT_ENDPOINT_SIZE,
.bDescriptorType = USB_DT_ENDPOINT, .bDescriptorType = USB_DT_ENDPOINT,
.bEndpointAddress = USB_ENDPOINT_OUT, .bEndpointAddress = USB_ENDPOINT_OUT,
.bmAttributes = USB_TRANSFER_TYPE_BULK, .bmAttributes = USB_TRANSFER_TYPE_BULK,
.wMaxPacketSize = 0x200, .wMaxPacketSize = 0x200,
}; };
//Setup interface. //Setup interface.
ret = usbDsGetDsInterface(&interface, &interface_descriptor, "usb"); ret = usbDsGetDsInterface(&interface, &interface_descriptor, "usb");
if(R_FAILED(ret))return ret; if(R_FAILED(ret))return ret;
//Setup endpoints. //Setup endpoints.
ret = usbDsInterface_GetDsEndpoint(interface, &endpoint_in, &endpoint_descriptor_in);//device->host ret = usbDsInterface_GetDsEndpoint(interface, &endpoint_in, &endpoint_descriptor_in);//device->host
if(R_FAILED(ret))return ret; if(R_FAILED(ret))return ret;
ret = usbDsInterface_GetDsEndpoint(interface, &endpoint_out, &endpoint_descriptor_out);//host->device ret = usbDsInterface_GetDsEndpoint(interface, &endpoint_out, &endpoint_descriptor_out);//host->device
if(R_FAILED(ret))return ret; if(R_FAILED(ret))return ret;
ret = usbDsInterface_EnableInterface(interface); ret = usbDsInterface_EnableInterface(interface);
if(R_FAILED(ret))return ret; if(R_FAILED(ret))return ret;
//Wait for initialization to finish where data-transfer is usable. This includes waiting for the usb cable to be inserted if it's not already. //Wait for initialization to finish where data-transfer is usable. This includes waiting for the usb cable to be inserted if it's not already.
ret = usbDsWaitReady(); ret = usbDsWaitReady();
if(R_FAILED(ret))return ret; if(R_FAILED(ret))return ret;
u32 somepos; u32 somepos;
for(somepos=0; somepos<0x101; somepos++) for(somepos=0; somepos<0x101; somepos++)
{ {
memset(tmpbuf, 0, 0x1000); memset(tmpbuf, 0, 0x1000);
char *strptr = "\n";//"Hello World!\n"; char *strptr = "\n";//"Hello World!\n";
tmpbuf[0] = 0x11; tmpbuf[0] = 0x11;
tmpbuf[1] = 0x1; tmpbuf[1] = 0x1;
if(somepos==0 || somepos==0x101) if(somepos==0 || somepos==0x101)
{ {
strncpy((char*)&tmpbuf[2], strptr, 0x1000-2); strncpy((char*)&tmpbuf[2], strptr, 0x1000-2);
ret = usbDsEndpoint_PostBufferAsync(endpoint_in, tmpbuf, 2+strlen(strptr), NULL); ret = usbDsEndpoint_PostBufferAsync(endpoint_in, tmpbuf, 2+strlen(strptr), NULL);
} }
else else
{ {
tmpbuf[2] = somepos-1; tmpbuf[2] = somepos-1;
ret = usbDsEndpoint_PostBufferAsync(endpoint_in, tmpbuf, 2+1, NULL); ret = usbDsEndpoint_PostBufferAsync(endpoint_in, tmpbuf, 2+1, NULL);
} }
//Start a device->host transfer. //Start a device->host transfer.
//ret = usbDsEndpoint_PostBufferAsync(endpoint_in, tmpbuf, 2+1, NULL); //ret = usbDsEndpoint_PostBufferAsync(endpoint_in, tmpbuf, 2+1, NULL);
//ret = usbDsEndpoint_PostBufferAsync(endpoint_in, tmpbuf, 2+strlen(strptr), NULL); //ret = usbDsEndpoint_PostBufferAsync(endpoint_in, tmpbuf, 2+strlen(strptr), NULL);
if(R_FAILED(ret))return ret; if(R_FAILED(ret))return ret;
//Wait for the transfer to finish. //Wait for the transfer to finish.
svcWaitSynchronization(&tmpindex, &endpoint_in->CompletionEvent, 1, U64_MAX); svcWaitSynchronization(&tmpindex, &endpoint_in->CompletionEvent, 1, U64_MAX);
svcClearEvent(endpoint_in->CompletionEvent); svcClearEvent(endpoint_in->CompletionEvent);
} }
//Start a host->device transfer. //Start a host->device transfer.
ret = usbDsEndpoint_PostBufferAsync(endpoint_out, tmpbuf, 0x200, NULL); ret = usbDsEndpoint_PostBufferAsync(endpoint_out, tmpbuf, 0x200, NULL);
if(R_FAILED(ret))return ret; if(R_FAILED(ret))return ret;
//Wait for the transfer to finish. //Wait for the transfer to finish.
svcWaitSynchronization(&tmpindex, &endpoint_out->CompletionEvent, 1, U64_MAX); svcWaitSynchronization(&tmpindex, &endpoint_out->CompletionEvent, 1, U64_MAX);
svcClearEvent(endpoint_out->CompletionEvent); svcClearEvent(endpoint_out->CompletionEvent);
memcpy(&tmpbuf[0x400], tmpbuf, 0x200-2); memcpy(&tmpbuf[0x400], tmpbuf, 0x200-2);
tmpbuf[0] = 0x11; tmpbuf[0] = 0x11;
tmpbuf[1] = 0x1; tmpbuf[1] = 0x1;
memcpy(&tmpbuf[2], &tmpbuf[0x400], 0x200-2); memcpy(&tmpbuf[2], &tmpbuf[0x400], 0x200-2);
//Start a device->host transfer. //Start a device->host transfer.
ret = usbDsEndpoint_PostBufferAsync(endpoint_in, tmpbuf, 0x2+1, NULL); ret = usbDsEndpoint_PostBufferAsync(endpoint_in, tmpbuf, 0x2+1, NULL);
if(R_FAILED(ret))return ret; if(R_FAILED(ret))return ret;
//Wait for the transfer to finish. //Wait for the transfer to finish.
svcWaitSynchronization(&tmpindex, &endpoint_in->CompletionEvent, 1, U64_MAX); svcWaitSynchronization(&tmpindex, &endpoint_in->CompletionEvent, 1, U64_MAX);
svcClearEvent(endpoint_in->CompletionEvent); svcClearEvent(endpoint_in->CompletionEvent);
svcSleepThread(5000000000);//Delay 5s svcSleepThread(5000000000);//Delay 5s
return 0; return 0;
} }
int main(int argc, char **argv) int main(int argc, char **argv)
{ {
Result ret; Result ret;
usbDsDeviceInfo deviceinfo = { usbDsDeviceInfo deviceinfo = {
.idVendor = 0x0403, // "Future Technology Devices International, Ltd" .idVendor = 0x0403, // "Future Technology Devices International, Ltd"
.idProduct = 0x6001, // "FT232 USB-Serial (UART) IC" .idProduct = 0x6001, // "FT232 USB-Serial (UART) IC"
.bcdDevice = 0x0200, .bcdDevice = 0x0200,
.Manufacturer = "libnx", .Manufacturer = "libnx",
.Product = "usbds-example", .Product = "usbds-example",
.SerialNumber = "1337", .SerialNumber = "1337",
}; };
ret = usbDsInitialize(UsbComplexId_Default, &deviceinfo); ret = usbDsInitialize(UsbComplexId_Default, &deviceinfo);
if (R_SUCCEEDED(ret)) { if (R_SUCCEEDED(ret)) {
u8 *tmpbuf = memalign(0x1000, 0x1000);//The buffer for PostBufferAsync commands must be 0x1000-byte aligned. u8 *tmpbuf = memalign(0x1000, 0x1000);//The buffer for PostBufferAsync commands must be 0x1000-byte aligned.
if(tmpbuf==NULL)ret = -4; if(tmpbuf==NULL)ret = -4;
if (R_SUCCEEDED(ret)) ret = usbds_test(tmpbuf); if (R_SUCCEEDED(ret)) ret = usbds_test(tmpbuf);
usbDsExit(); usbDsExit();
} }
if(R_FAILED(ret))fatalSimple(ret); if(R_FAILED(ret))fatalSimple(ret);
svcSleepThread(5000000000);//Delay 5s svcSleepThread(5000000000);//Delay 5s
return 0; return 0;
} }