File tree Expand file tree Collapse file tree 1 file changed +39
-2
lines changed
examples/peripherals/slot2/source Expand file tree Collapse file tree 1 file changed +39
-2
lines changed Original file line number Diff line number Diff line change 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+
1047int 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)
You can’t perform that action at this time.
0 commit comments