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

View File

@ -12,191 +12,191 @@
#define BYTESPERSAMPLE 2
void fill_audio_buffer(void* audio_buffer, size_t offset, size_t size, int frequency) {
if (audio_buffer == NULL) return;
u32* dest = (u32*) audio_buffer;
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.
s16 sample = 0.3 * 0x7FFF * sin(frequency * (2 * M_PI) * (offset + i) / SAMPLERATE);
if (audio_buffer == NULL) return;
u32* dest = (u32*) audio_buffer;
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.
s16 sample = 0.3 * 0x7FFF * sin(frequency * (2 * M_PI) * (offset + i) / SAMPLERATE);
// Stereo samples are interleaved: left and right channels.
dest[i] = (sample << 16) | (sample & 0xffff);
}
// Stereo samples are interleaved: left and right channels.
dest[i] = (sample << 16) | (sample & 0xffff);
}
}
int main(int argc, char **argv)
{
Result rc = 0;
int notefreq[] = {
220,
440, 880, 1760, 3520, 7040,
14080,
7040, 3520, 1760, 880, 440
};
gfxInitDefault();
Result rc = 0;
int notefreq[] = {
220,
440, 880, 1760, 3520, 7040,
14080,
7040, 3520, 1760, 880, 440
};
gfxInitDefault();
// Initialize console. Using NULL as the second argument tells the console library to use the internal console structure as current one.
consoleInit(NULL);
AudioOutBuffer audout_buf;
AudioOutBuffer *audout_released_buf;
// Make sure the sample buffer size is aligned to 0x1000 bytes.
u32 data_size = (SAMPLECOUNT * CHANNELCOUNT * BYTESPERSAMPLE);
u32 buffer_size = (data_size + 0xfff) & ~0xfff;
// Allocate the buffer.
u8* out_buf_data = memalign(0x1000, buffer_size);
// Ensure buffers were properly allocated.
if (out_buf_data == NULL)
{
rc = MAKERESULT(Module_Libnx, LibnxError_OutOfMemory);
printf("Failed to allocate sample data buffers\n");
}
if (R_SUCCEEDED(rc))
memset(out_buf_data, 0, buffer_size);
if (R_SUCCEEDED(rc))
{
// Initialize the default audio output device.
rc = audoutInitialize();
printf("audoutInitialize() returned 0x%x\n", rc);
}
if (R_SUCCEEDED(rc))
{
printf("Sample rate: 0x%x\n", audoutGetSampleRate());
printf("Channel count: 0x%x\n", audoutGetChannelCount());
printf("PCM format: 0x%x\n", audoutGetPcmFormat());
printf("Device state: 0x%x\n", audoutGetDeviceState());
// Start audio playback.
rc = audoutStartAudioOut();
printf("audoutStartAudioOut() returned 0x%x\n", rc);
}
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");
while (appletMainLoop())
{
//Scan all the inputs. This should be done once for each frame
hidScanInput();
// Initialize console. Using NULL as the second argument tells the console library to use the internal console structure as current one.
consoleInit(NULL);
AudioOutBuffer audout_buf;
AudioOutBuffer *audout_released_buf;
// Make sure the sample buffer size is aligned to 0x1000 bytes.
u32 data_size = (SAMPLECOUNT * CHANNELCOUNT * BYTESPERSAMPLE);
u32 buffer_size = (data_size + 0xfff) & ~0xfff;
// Allocate the buffer.
u8* out_buf_data = memalign(0x1000, buffer_size);
// Ensure buffers were properly allocated.
if (out_buf_data == NULL)
{
rc = MAKERESULT(Module_Libnx, LibnxError_OutOfMemory);
printf("Failed to allocate sample data buffers\n");
}
if (R_SUCCEEDED(rc))
memset(out_buf_data, 0, buffer_size);
if (R_SUCCEEDED(rc))
{
// Initialize the default audio output device.
rc = audoutInitialize();
printf("audoutInitialize() returned 0x%x\n", rc);
}
if (R_SUCCEEDED(rc))
{
printf("Sample rate: 0x%x\n", audoutGetSampleRate());
printf("Channel count: 0x%x\n", audoutGetChannelCount());
printf("PCM format: 0x%x\n", audoutGetPcmFormat());
printf("Device state: 0x%x\n", audoutGetDeviceState());
// Start audio playback.
rc = audoutStartAudioOut();
printf("audoutStartAudioOut() returned 0x%x\n", rc);
}
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");
while (appletMainLoop())
{
//Scan all the inputs. This should be done once for each frame
hidScanInput();
//hidKeysDown returns information about which buttons have been just pressed (and they weren't in the previous frame)
u32 kDown = hidKeysDown(CONTROLLER_P1_AUTO);
//hidKeysDown returns information about which buttons have been just pressed (and they weren't in the previous frame)
u32 kDown = hidKeysDown(CONTROLLER_P1_AUTO);
if (kDown & KEY_PLUS) break; // break in order to return to hbmenu
if (kDown & KEY_A)
{
fill_audio_buffer(out_buf_data, 0, data_size, notefreq[0]);
play_tone = true;
}
if (kDown & KEY_B)
{
fill_audio_buffer(out_buf_data, 0, data_size, notefreq[1]);
play_tone = true;
}
if (kDown & KEY_Y)
{
fill_audio_buffer(out_buf_data, 0, data_size, notefreq[2]);
play_tone = true;
}
if (kDown & KEY_X)
{
fill_audio_buffer(out_buf_data, 0, data_size, notefreq[3]);
play_tone = true;
}
if (kDown & KEY_DLEFT)
{
fill_audio_buffer(out_buf_data, 0, data_size, notefreq[4]);
play_tone = true;
}
if (kDown & KEY_DUP)
{
fill_audio_buffer(out_buf_data, 0, data_size, notefreq[5]);
play_tone = true;
}
if (kDown & KEY_DRIGHT)
{
fill_audio_buffer(out_buf_data, 0, data_size, notefreq[6]);
play_tone = true;
}
if (kDown & KEY_DDOWN)
{
fill_audio_buffer(out_buf_data, 0, data_size, notefreq[7]);
play_tone = true;
}
if (kDown & KEY_L)
{
fill_audio_buffer(out_buf_data, 0, data_size, notefreq[8]);
play_tone = true;
}
if (kDown & KEY_R)
{
fill_audio_buffer(out_buf_data, 0, data_size, notefreq[9]);
play_tone = true;
}
if (kDown & KEY_ZL)
{
fill_audio_buffer(out_buf_data, 0, data_size, notefreq[10]);
play_tone = true;
}
if (kDown & KEY_ZR)
{
fill_audio_buffer(out_buf_data, 0, data_size, notefreq[11]);
play_tone = true;
}
if (R_SUCCEEDED(rc) && play_tone)
{
// Prepare the audio data source buffer.
audout_buf.next = NULL;
audout_buf.buffer = out_buf_data;
audout_buf.buffer_size = buffer_size;
audout_buf.data_size = data_size;
audout_buf.data_offset = 0;
// Prepare pointer for the released buffer.
audout_released_buf = NULL;
// Play the buffer.
rc = audoutPlayBuffer(&audout_buf, &audout_released_buf);
if (R_FAILED(rc))
printf("audoutPlayBuffer() returned 0x%x\n", rc);
play_tone = false;
}
gfxFlushBuffers();
gfxSwapBuffers();
gfxWaitForVsync();
}
// Stop audio playback.
rc = audoutStopAudioOut();
printf("audoutStopAudioOut() returned 0x%x\n", rc);
if (kDown & KEY_PLUS) break; // break in order to return to hbmenu
if (kDown & KEY_A)
{
fill_audio_buffer(out_buf_data, 0, data_size, notefreq[0]);
play_tone = true;
}
if (kDown & KEY_B)
{
fill_audio_buffer(out_buf_data, 0, data_size, notefreq[1]);
play_tone = true;
}
if (kDown & KEY_Y)
{
fill_audio_buffer(out_buf_data, 0, data_size, notefreq[2]);
play_tone = true;
}
if (kDown & KEY_X)
{
fill_audio_buffer(out_buf_data, 0, data_size, notefreq[3]);
play_tone = true;
}
if (kDown & KEY_DLEFT)
{
fill_audio_buffer(out_buf_data, 0, data_size, notefreq[4]);
play_tone = true;
}
if (kDown & KEY_DUP)
{
fill_audio_buffer(out_buf_data, 0, data_size, notefreq[5]);
play_tone = true;
}
if (kDown & KEY_DRIGHT)
{
fill_audio_buffer(out_buf_data, 0, data_size, notefreq[6]);
play_tone = true;
}
if (kDown & KEY_DDOWN)
{
fill_audio_buffer(out_buf_data, 0, data_size, notefreq[7]);
play_tone = true;
}
if (kDown & KEY_L)
{
fill_audio_buffer(out_buf_data, 0, data_size, notefreq[8]);
play_tone = true;
}
if (kDown & KEY_R)
{
fill_audio_buffer(out_buf_data, 0, data_size, notefreq[9]);
play_tone = true;
}
if (kDown & KEY_ZL)
{
fill_audio_buffer(out_buf_data, 0, data_size, notefreq[10]);
play_tone = true;
}
if (kDown & KEY_ZR)
{
fill_audio_buffer(out_buf_data, 0, data_size, notefreq[11]);
play_tone = true;
}
if (R_SUCCEEDED(rc) && play_tone)
{
// Prepare the audio data source buffer.
audout_buf.next = NULL;
audout_buf.buffer = out_buf_data;
audout_buf.buffer_size = buffer_size;
audout_buf.data_size = data_size;
audout_buf.data_offset = 0;
// Prepare pointer for the released buffer.
audout_released_buf = NULL;
// Play the buffer.
rc = audoutPlayBuffer(&audout_buf, &audout_released_buf);
if (R_FAILED(rc))
printf("audoutPlayBuffer() returned 0x%x\n", rc);
play_tone = false;
}
gfxFlushBuffers();
gfxSwapBuffers();
gfxWaitForVsync();
}
// Stop audio playback.
rc = audoutStopAudioOut();
printf("audoutStopAudioOut() returned 0x%x\n", rc);
// Terminate the default audio output device.
audoutExit();
gfxExit();
return 0;
// Terminate the default audio output device.
audoutExit();
gfxExit();
return 0;
}

View File

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

View File

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

View File

@ -5,32 +5,32 @@
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.
consoleInit(NULL);
//Initialize console. Using NULL as the second argument tells the console library to use the internal console structure as current one.
consoleInit(NULL);
//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
//the row and column where you want your cursor to move
printf("\x1b[16;20HHello 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
//the row and column where you want your cursor to move
printf("\x1b[16;20HHello World!");
while(appletMainLoop())
{
//Scan all the inputs. This should be done once for each frame
hidScanInput();
while(appletMainLoop())
{
//Scan all the inputs. This should be done once for each frame
hidScanInput();
//hidKeysDown returns information about which buttons have been just pressed (and they weren't in the previous frame)
u32 kDown = hidKeysDown(CONTROLLER_P1_AUTO);
//hidKeysDown returns information about which buttons have been just pressed (and they weren't in the previous frame)
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();
gfxSwapBuffers();
gfxWaitForVsync();
}
gfxFlushBuffers();
gfxSwapBuffers();
gfxWaitForVsync();
}
gfxExit();
return 0;
gfxExit();
return 0;
}

View File

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

View File

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

View File

@ -9,118 +9,118 @@
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;
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;
u32 width, height;
u32 ir_width, ir_height;
u32 pos, pos2=0;
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.
consoleInit(NULL);
//Initialize console. Using NULL as the second argument tells the console library to use the internal console structure as current one.
consoleInit(NULL);
ir_buffer = (u8*)malloc(ir_buffer_size);
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);
}
ir_buffer = (u8*)malloc(ir_buffer_size);
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))
{
rc = irsInitialize();
printf("irsInitialize() returned 0x%x\n", rc);
}
if (R_SUCCEEDED(rc))
{
rc = irsActivateIrsensor(1);
printf("irsActivateIrsensor() returned 0x%x\n", rc);
}
if (R_SUCCEEDED(rc))
{
rc = irsActivateIrsensor(1);
printf("irsActivateIrsensor() returned 0x%x\n", rc);
}
if (R_SUCCEEDED(rc))
{
rc = irsGetIrCameraHandle(&irhandle, CONTROLLER_PLAYER_1);
printf("irsGetIrCameraHandle() returned 0x%x\n", rc);
}
if (R_SUCCEEDED(rc))
{
rc = irsGetIrCameraHandle(&irhandle, CONTROLLER_PLAYER_1);
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))
{
irsGetDefaultImageTransferProcessorConfig(&config);
rc = irsRunImageTransferProcessor(irhandle, &config, 0x100000);
printf("irsRunImageTransferProcessor() returned 0x%x\n", rc);
}
if (R_SUCCEEDED(rc))
{
//Switch to using regular framebuffer.
consoleClear();
gfxSetMode(GfxMode_LinearDouble);
}
if (R_SUCCEEDED(rc))
{
//Switch to using regular framebuffer.
consoleClear();
gfxSetMode(GfxMode_LinearDouble);
}
while(appletMainLoop())
{
//Scan all the inputs. This should be done once for each frame
hidScanInput();
while(appletMainLoop())
{
//Scan all the inputs. This should be done once for each frame
hidScanInput();
//hidKeysDown returns information about which buttons have been just pressed (and they weren't in the previous frame)
u32 kDown = hidKeysDown(CONTROLLER_P1_AUTO);
//hidKeysDown returns information about which buttons have been just pressed (and they weren't in the previous frame)
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))
{
framebuf = (u32*) gfxGetFramebuffer((u32*)&width, (u32*)&height);
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);
//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());
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;
//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<ir_height; y++)//Access the buffer linearly.
{
for (x=0; x<ir_width; x++)
{
pos = y * width + x;
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);
}
}
}
}
u32 x, y;
for (y=0; y<ir_height; y++)//Access the buffer linearly.
{
for (x=0; x<ir_width; x++)
{
pos = y * width + x;
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);
}
}
}
}
gfxFlushBuffers();
gfxSwapBuffers();
gfxWaitForVsync();
}
gfxFlushBuffers();
gfxSwapBuffers();
gfxWaitForVsync();
}
irsStopImageProcessor(irhandle);
irsExit();
irsStopImageProcessor(irhandle);
irsExit();
free(ir_buffer);
free(ir_buffer);
gfxExit();
return 0;
gfxExit();
return 0;
}

View File

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

View File

@ -7,57 +7,57 @@
int main(int argc, char **argv)
{
u32 prev_touchcount=0;
u32 prev_touchcount=0;
gfxInitDefault();
consoleInit(NULL);
gfxInitDefault();
consoleInit(NULL);
printf("\x1b[1;1HPress PLUS to exit.");
printf("\x1b[2;1HTouch Screen position:");
printf("\x1b[1;1HPress PLUS to exit.");
printf("\x1b[2;1HTouch Screen position:");
// Main loop
while(appletMainLoop())
{
//Scan all the inputs. This should be done once for each frame
hidScanInput();
// Main loop
while(appletMainLoop())
{
//Scan all the inputs. This should be done once for each frame
hidScanInput();
//hidKeysDown returns information about which buttons have been just pressed (and they weren't in the previous frame)
u32 kDown = hidKeysDown(CONTROLLER_P1_AUTO);
//hidKeysDown returns information about which buttons have been just pressed (and they weren't in the previous frame)
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 touch_count = hidTouchCount();
u32 i;
u32 touch_count = hidTouchCount();
if (touch_count != prev_touchcount)
{
prev_touchcount = touch_count;
if (touch_count != prev_touchcount)
{
prev_touchcount = touch_count;
consoleClear();
consoleClear();
printf("\x1b[1;1HPress PLUS to exit.");
printf("\x1b[2;1HTouch Screen position:");
}
printf("\x1b[1;1HPress PLUS to exit.");
printf("\x1b[2;1HTouch Screen position:");
}
printf("\x1b[3;1H");
printf("\x1b[3;1H");
for(i=0; i<touch_count; i++)
{
//Read the touch screen coordinates
hidTouchRead(&touch, i);
for(i=0; i<touch_count; i++)
{
//Read the touch screen coordinates
hidTouchRead(&touch, i);
//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);
}
//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);
}
gfxFlushBuffers();
gfxSwapBuffers();
gfxWaitForVsync();
}
gfxFlushBuffers();
gfxSwapBuffers();
gfxWaitForVsync();
}
gfxExit();
return 0;
gfxExit();
return 0;
}

View File

@ -7,78 +7,78 @@
int main(int argc, char **argv)
{
u32 VibrationDeviceHandles[2];
Result rc = 0, rc2 = 0;
u32 VibrationDeviceHandles[2];
Result rc = 0, rc2 = 0;
HidVibrationValue VibrationValue;
HidVibrationValue VibrationValue_stop;
HidVibrationValue VibrationValue;
HidVibrationValue VibrationValue_stop;
gfxInitDefault();
consoleInit(NULL);
gfxInitDefault();
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.
rc = hidInitializeVibrationDevices(VibrationDeviceHandles, 2, CONTROLLER_PLAYER_1, LAYOUT_DEFAULT);
printf("hidInitializeVibrationDevice() returned: 0x%x\n", rc);
//Two VibrationDeviceHandles are returned: first one for left-joycon, second one for right-joycon.
rc = hidInitializeVibrationDevices(VibrationDeviceHandles, 2, CONTROLLER_PLAYER_1, LAYOUT_DEFAULT);
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.freq_low = 10.0f;
VibrationValue.amp_high = 0.2f;
VibrationValue.freq_high = 10.0f;
VibrationValue.amp_low = 0.2f;
VibrationValue.freq_low = 10.0f;
VibrationValue.amp_high = 0.2f;
VibrationValue.freq_high = 10.0f;
memset(&VibrationValue_stop, 0, sizeof(HidVibrationValue));
// Switch like stop behavior with muted band channels and frequencies set to default.
VibrationValue_stop.freq_low = 160.0f;
memset(&VibrationValue_stop, 0, sizeof(HidVibrationValue));
// Switch like stop behavior with muted band channels and frequencies set to default.
VibrationValue_stop.freq_low = 160.0f;
VibrationValue_stop.freq_high = 320.0f;
// Main loop
while(appletMainLoop())
{
//Scan all the inputs. This should be done once for each frame
hidScanInput();
// Main loop
while(appletMainLoop())
{
//Scan all the inputs. This should be done once for each frame
hidScanInput();
//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 kHeld = hidKeysHeld(CONTROLLER_P1_AUTO);
u32 kUp = hidKeysUp(CONTROLLER_P1_AUTO);
//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 kHeld = hidKeysHeld(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))
{
//Calling hidSendVibrationValue is really only needed when sending a new VibrationValue.
if (R_SUCCEEDED(rc) && (kHeld & KEY_R))
{
//Calling hidSendVibrationValue is really only needed when sending a new VibrationValue.
//left-joycon
rc2 = hidSendVibrationValue(&VibrationDeviceHandles[0], &VibrationValue);
if (R_FAILED(rc2)) printf("hidSendVibrationValue() returned: 0x%x\n", rc2);
//left-joycon
rc2 = hidSendVibrationValue(&VibrationDeviceHandles[0], &VibrationValue);
if (R_FAILED(rc2)) printf("hidSendVibrationValue() returned: 0x%x\n", rc2);
//right-joycon
rc2 = hidSendVibrationValue(&VibrationDeviceHandles[1], &VibrationValue);
if (R_FAILED(rc2)) printf("hidSendVibrationValue() returned: 0x%x\n", rc2);
//right-joycon
rc2 = hidSendVibrationValue(&VibrationDeviceHandles[1], &VibrationValue);
if (R_FAILED(rc2)) printf("hidSendVibrationValue() returned: 0x%x\n", rc2);
if (kDown & KEY_A) VibrationValue.amp_low += 0.1f;
if (kDown & KEY_B) VibrationValue.freq_low += 5.0f;
if (kDown & KEY_X) VibrationValue.amp_high += 0.1f;
if (kDown & KEY_Y) VibrationValue.freq_high += 12.0f;
}
else if(kUp & KEY_R)//Stop vibration.
{
rc2 = hidSendVibrationValue(&VibrationDeviceHandles[0], &VibrationValue_stop);
if (R_FAILED(rc2)) printf("hidSendVibrationValue() for stop returned: 0x%x\n", rc2);
if (kDown & KEY_A) VibrationValue.amp_low += 0.1f;
if (kDown & KEY_B) VibrationValue.freq_low += 5.0f;
if (kDown & KEY_X) VibrationValue.amp_high += 0.1f;
if (kDown & KEY_Y) VibrationValue.freq_high += 12.0f;
}
else if(kUp & KEY_R)//Stop vibration.
{
rc2 = hidSendVibrationValue(&VibrationDeviceHandles[0], &VibrationValue_stop);
if (R_FAILED(rc2)) printf("hidSendVibrationValue() for stop returned: 0x%x\n", rc2);
rc2 = hidSendVibrationValue(&VibrationDeviceHandles[1], &VibrationValue_stop);
if (R_FAILED(rc2)) printf("hidSendVibrationValue() for stop returned: 0x%x\n", rc2);
}
rc2 = hidSendVibrationValue(&VibrationDeviceHandles[1], &VibrationValue_stop);
if (R_FAILED(rc2)) printf("hidSendVibrationValue() for stop returned: 0x%x\n", rc2);
}
gfxFlushBuffers();
gfxSwapBuffers();
gfxWaitForVsync();
}
gfxFlushBuffers();
gfxSwapBuffers();
gfxWaitForVsync();
}
gfxExit();
return 0;
gfxExit();
return 0;
}

View File

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

View File

@ -5,30 +5,30 @@
int main(int argc, char **argv)
{
gfxInitDefault();
consoleInit(NULL);
gfxInitDefault();
consoleInit(NULL);
printf("Hello World!");
printf("Hello World!");
// Main loop
while(appletMainLoop())
{
//Scan all the inputs. This should be done once for each frame
hidScanInput();
// Main loop
while(appletMainLoop())
{
//Scan all the inputs. This should be done once for each frame
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)
u32 kDown = hidKeysDown(CONTROLLER_P1_AUTO);
//hidKeysDown returns information about which buttons have been just pressed (and they weren't in the previous frame)
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();
gfxSwapBuffers();
gfxWaitForVsync();
}
gfxFlushBuffers();
gfxSwapBuffers();
gfxWaitForVsync();
}
gfxExit();
return 0;
gfxExit();
return 0;
}

View File

@ -1,6 +1,6 @@
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)
{
gfxInitDefault();
consoleInit(NULL);
gfxInitDefault();
consoleInit(NULL);
printf("\x1b[16;16HPress PLUS to exit.");
printf("\x1b[16;16HPress PLUS to exit.");
// Main loop
while(appletMainLoop())
{
//Scan all the inputs. This should be done once for each frame
hidScanInput();
// Main loop
while(appletMainLoop())
{
//Scan all the inputs. This should be done once for each frame
hidScanInput();
//hidKeysDown returns information about which buttons have been just pressed (and they weren't in the previous frame)
u32 kDown = hidKeysDown(CONTROLLER_P1_AUTO);
//hidKeysDown returns information about which buttons have been just pressed (and they weren't in the previous frame)
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
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).
//Print current time
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).
int hours = timeStruct->tm_hour;
int minutes = timeStruct->tm_min;
int seconds = timeStruct->tm_sec;
int day = timeStruct->tm_mday;
int month = timeStruct->tm_mon;
int year = timeStruct->tm_year +1900;
int wday = timeStruct->tm_wday;
int hours = timeStruct->tm_hour;
int minutes = timeStruct->tm_min;
int seconds = timeStruct->tm_sec;
int day = timeStruct->tm_mday;
int month = timeStruct->tm_mon;
int year = timeStruct->tm_year +1900;
int wday = timeStruct->tm_wday;
printf("\x1b[1;1H%02i:%02i:%02i", hours, minutes, seconds);
printf("\n%s %s %i %i", weekDays[wday], months[month], day, year);
printf("\x1b[1;1H%02i:%02i:%02i", hours, minutes, seconds);
printf("\n%s %s %i %i", weekDays[wday], months[month], day, year);
gfxFlushBuffers();
gfxSwapBuffers();
gfxWaitForVsync();
}
gfxFlushBuffers();
gfxSwapBuffers();
gfxWaitForVsync();
}
gfxExit();
return 0;
gfxExit();
return 0;
}

View File

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