WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content

Commit e31742e

Browse files
committed
examples: Support edge-triggered rumble in Slot-2 example
1 parent 6ddf453 commit e31742e

File tree

1 file changed

+39
-2
lines changed
  • examples/peripherals/slot2/source

1 file changed

+39
-2
lines changed

examples/peripherals/slot2/source/main.c

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,49 @@
11
// SPDX-License-Identifier: CC0-1.0
22
//
3-
// SPDX-FileContributor: Antonio Niño Díaz, 2023
3+
// SPDX-FileContributor: Antonio Niño Díaz, 2023-2025
44
// SPDX-FileContributor: Adrian "asie" Siekierka, 2023
55

66
#include <nds.h>
77
#include <stdbool.h>
88
#include <stdio.h>
99

10+
static bool rumble_toggle = false;
11+
static uint8_t rumble_strength = 0;
12+
13+
void rumble_toggler(void)
14+
{
15+
if (rumble_toggle)
16+
setRumble(rumble_strength);
17+
else
18+
setRumble(0);
19+
20+
rumble_toggle = !rumble_toggle;
21+
}
22+
23+
void example_set_rumble(int strength)
24+
{
25+
if (strength == 0)
26+
{
27+
timerStop(0);
28+
setRumble(0);
29+
return;
30+
}
31+
32+
if (peripheralSlot2GetSupportMask() & SLOT2_PERIPHERAL_RUMBLE_EDGE)
33+
{
34+
// If we're using an edge-triggered rumble cartridge we need to switch
35+
// between on and off at a high frequency to actually feel the
36+
// vibration. This starts a timer that will cause an interrupt 100 times
37+
// per second.
38+
rumble_strength = strength;
39+
timerStart(0, ClockDivider_256, timerFreqToTicks_256(100), rumble_toggler);
40+
}
41+
else
42+
{
43+
setRumble(strength);
44+
}
45+
}
46+
1047
int main(int argc, char **argv)
1148
{
1249
consoleDemoInit();
@@ -67,7 +104,7 @@ int main(int argc, char **argv)
67104
if (keys_down & KEY_A)
68105
{
69106
rumble = (rumble + 1) % (rumbleGetMaxRawStrength() + 1);
70-
setRumble(rumble);
107+
example_set_rumble(rumble);
71108
}
72109

73110
// Go to the start of the line (it will stop at X=0)

0 commit comments

Comments
 (0)