]> Chaos Git - corbenik/corbenik.git/commitdiff
Use libctr9_io's input functionality
authorchaoskagami <chaos.kagami@gmail.com>
Fri, 15 Jul 2016 06:29:46 +0000 (02:29 -0400)
committerchaoskagami <chaos.kagami@gmail.com>
Fri, 15 Jul 2016 06:29:46 +0000 (02:29 -0400)
source/display.c
source/input.c
source/input.h
source/main.c

index ffcd83d6931288f9b328d8010ab50ca501c4865a..dba94815962033ff731dfa80d770cfad054543e5 100644 (file)
@@ -114,35 +114,35 @@ show_menu(struct options_s *options, uint8_t *toggles)
         uint32_t key = wait_key(1);
 
         switch (key) {
-            case BUTTON_UP:
+            case CTR_HID_UP:
                 if (cursor_min == cursor_max)
                     break;
                 cursor_y -= 1;
                 while ((options[cursor_y].allowed == not_option || (options[cursor_y].allowed == boolean_val_n3ds && !is_n3ds)) && cursor_y >= cursor_min && !less_mode)
                     cursor_y--;
                 break;
-            case BUTTON_DOWN:
+            case CTR_HID_DOWN:
                 if (cursor_min == cursor_max)
                     break;
                 cursor_y += 1;
                 while ((options[cursor_y].allowed == not_option || (options[cursor_y].allowed == boolean_val_n3ds && !is_n3ds)) && cursor_y < cursor_max && !less_mode)
                     cursor_y++;
                 break;
-            case BUTTON_LEFT:
+            case CTR_HID_LEFT:
                 if (cursor_min == cursor_max)
                     break;
                 cursor_y -= 5;
                 while ((options[cursor_y].allowed == not_option || (options[cursor_y].allowed == boolean_val_n3ds && !is_n3ds)) && cursor_y >= cursor_min && !less_mode)
                     cursor_y--;
                 break;
-            case BUTTON_RIGHT:
+            case CTR_HID_RIGHT:
                 if (cursor_min == cursor_max)
                     break;
                 cursor_y += 5;
                 while ((options[cursor_y].allowed == not_option || (options[cursor_y].allowed == boolean_val_n3ds && !is_n3ds)) && cursor_y < cursor_max && !less_mode)
                     cursor_y++;
                 break;
-            case BUTTON_A:
+            case CTR_HID_A:
                 if (less_mode)
                     break;
 
@@ -161,7 +161,7 @@ show_menu(struct options_s *options, uint8_t *toggles)
                     cursor_y = cursor_min;
                 }
                 break;
-            case BUTTON_X:
+            case CTR_HID_X:
                 if (options[cursor_y].allowed == ranged_val) {
                     if (toggles[options[cursor_y].index] == options[cursor_y].a)
                         toggles[options[cursor_y].index] = options[cursor_y].b;
@@ -169,12 +169,12 @@ show_menu(struct options_s *options, uint8_t *toggles)
                         toggles[options[cursor_y].index]--;
                 }
                 break;
-            case BUTTON_B:
+            case CTR_HID_B:
                 exit = 1;
                 clear_disp(TOP_SCREEN);
                 cursor_y = cursor_min;
                 break;
-            case BUTTON_SEL:
+            case CTR_HID_SELECT:
                 if (options[cursor_y].desc[0] != 0) {
                     show_help(options[cursor_y].desc);
                     clear_disp(TOP_SCREEN);
index 0fbdd26580a28acf797e791adabb2368dadc43c1..deb998b6c4e0b6c4463976c2b8d599373f115014 100644 (file)
@@ -5,41 +5,37 @@
 
 extern void waitcycles(uint32_t cycles);
 
+#define ARM9_APPROX_DELAY_MAX 134058675 / 95
+
 uint32_t
 wait_key(_UNUSED int sleep)
 {
-    // If your dpad has issues, please add this to the makefile.
-    if (sleep) {
-        #define ARM9_APPROX_DELAY_MAX 134058675 / 95
-        waitcycles(ARM9_APPROX_DELAY_MAX); // Approximately what a human can input - fine tuning needed (sorry, TASers!)
-    }
-
     uint32_t ret = 0, get = 0;
     while (ret == 0) {
-        get = HID_PAD;
+        get = ctr_hid_get_buttons();
 
-        if ((get & (BUTTON_L | BUTTON_R | BUTTON_STA)) == (BUTTON_L | BUTTON_R | BUTTON_STA)) {
+        if ((get & (CTR_HID_LT | CTR_HID_RT | CTR_HID_START)) == (CTR_HID_LT | CTR_HID_RT | CTR_HID_START)) {
             screenshot();
             waitcycles(ARM9_APPROX_DELAY_MAX); // Approximately what a human can input - fine tuning needed (sorry, TASers!)
-        } else if (get & BUTTON_UP)
-            ret = BUTTON_UP;
-        else if (get & BUTTON_DOWN)
-            ret = BUTTON_DOWN;
-        else if (get & BUTTON_RIGHT)
-            ret = BUTTON_RIGHT;
-        else if (get & BUTTON_LEFT)
-            ret = BUTTON_LEFT;
-        else if (get & BUTTON_A)
-            ret = BUTTON_A;
-        else if (get & BUTTON_B)
-            ret = BUTTON_B;
-        else if (get & BUTTON_X)
-            ret = BUTTON_X;
-        else if (get & BUTTON_SEL)
-            ret = BUTTON_SEL;
+        } else if (get & CTR_HID_UP)
+            ret = CTR_HID_UP;
+        else if (get & CTR_HID_DOWN)
+            ret = CTR_HID_DOWN;
+        else if (get & CTR_HID_RIGHT)
+            ret = CTR_HID_RIGHT;
+        else if (get & CTR_HID_LEFT)
+            ret = CTR_HID_LEFT;
+        else if (get & CTR_HID_A)
+            ret = CTR_HID_A;
+        else if (get & CTR_HID_B)
+            ret = CTR_HID_B;
+        else if (get & CTR_HID_X)
+            ret = CTR_HID_X;
+        else if (get & CTR_HID_SELECT)
+            ret = CTR_HID_SELECT;
 
     }
-    while (HID_PAD & ret);
+    while (ctr_hid_get_buttons());
 
     return ret;
 }
index 4051a83221ad703df00b1ddc7c4fabd920b04173..c09c2172219d3529d96408b07777c95f64ea301b 100644 (file)
@@ -1,24 +1,7 @@
 #ifndef __INPUT_H
 #define __INPUT_H
 
-#define BUTTON_A (1 << 0)
-#define BUTTON_B (1 << 1)
-#define BUTTON_SEL (1 << 2)
-#define BUTTON_STA (1 << 3)
-#define BUTTON_RIGHT (1 << 4)
-#define BUTTON_LEFT (1 << 5)
-#define BUTTON_UP (1 << 6)
-#define BUTTON_DOWN (1 << 7)
-#define BUTTON_R (1 << 8)
-#define BUTTON_L (1 << 9)
-#define BUTTON_X (1 << 10)
-#define BUTTON_Y (1 << 11)
-/* FIXME - I had ZR and ZL in, but they don't appear to
-           behave rationally without some initialization. */
-
-#define BUTTON_ANY 0xFFF
-
-#define HID_PAD ((*(volatile uint32_t *)0x10146000) ^ BUTTON_ANY)
+#include <ctr9/ctr_hid.h>
 
 uint32_t wait_key(_UNUSED int sleep);
 
index 2d52f4ecbc1a0b11c4a0f1de3816018aff9bb51f..63572fbe5eb9bcdfbcc7b217c3e367fd9bd147f0 100644 (file)
@@ -1,3 +1,5 @@
+#include <ctr9/ctr_hid.h>
+
 #include "common.h"
 #include "firm/firm.h"
 #include "input.h"
@@ -5,11 +7,10 @@
 #include "screeninit.h"
 #include "std/abort.h"
 
-int menu_handler();
-
 int is_n3ds = 0;
-
 int doing_autoboot = 0;
+
+int menu_handler();
 void shut_up();
 
 int
@@ -50,7 +51,7 @@ main(int argc, char** argv)
     }
 
     // Autoboot. Non-standard code path.
-    if (config.options[OPTION_AUTOBOOT] && !(HID_PAD & BUTTON_R)) {
+    if (config.options[OPTION_AUTOBOOT] && (ctr_hid_get_buttons() & CTR_HID_RT)) {
         if (config.options[OPTION_SILENCE])
             shut_up(); // This does exactly what it sounds like.
         doing_autoboot = 1;