Adding num key parsing

Currently there is only support for an alphanumeric references that is
decoded into a pin number. The "num" keyword supports using the pin
number directly (integer). The JSON key field determines the parsing.

It matches the support for the "num" keyword for the gpio_defs.json
seen in skeleton/libobmc_intf. If added along with:

https://gerrit.openbmc.org/c/openbmc/skeleton/+/68883

then "num" could be used for systems that have numerically labeled GPIO
pins and have multiple GPIO banks.

Change-Id: Ibf3e432a36c60b650c7f245ee12e5af3a8359664
Signed-off-by: Jonico Eustaquio <jonico.eustaquio@fii-na.com>
diff --git a/README.md b/README.md
index 826492c..9ad2697 100644
--- a/README.md
+++ b/README.md
@@ -63,6 +63,9 @@
 2. An array consists of single or multiple gpio configs associated with the
    specific button interface.
 
+A gpio can be mapped using the "pin" or "num" keyword. The "pin" key uses
+alphanumerical references while the "num" key supports the integer pin number.
+
 ## example gpio def Json config
 
 ```json
diff --git a/src/main.cpp b/src/main.cpp
index cf38e1f..914d331 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -103,7 +103,16 @@
             for (const auto& config : groupGpio)
             {
                 GpioInfo gpioCfg;
-                gpioCfg.number = getGpioNum(config["pin"]);
+                if (gpioConfig.contains("pin"))
+                {
+                    // When "pin" key is used, parse as alphanumeric
+                    gpioCfg.number = getGpioNum(gpioConfig.at("pin"));
+                }
+                else
+                {
+                    // Without "pin", "num" is assumed and parsed as an integer
+                    gpioCfg.number = gpioConfig.at("num").get<uint32_t>();
+                }
                 gpioCfg.direction = config["direction"];
                 gpioCfg.name = config["name"];
                 gpioCfg.polarity = (config["polarity"] == "active_high")
@@ -115,7 +124,16 @@
         else
         {
             GpioInfo gpioCfg;
-            gpioCfg.number = getGpioNum(gpioConfig["pin"]);
+            if (gpioConfig.contains("pin"))
+            {
+                // When "pin" key is used, parse as alphanumeric
+                gpioCfg.number = getGpioNum(gpioConfig.at("pin"));
+            }
+            else
+            {
+                // Without "pin", "num" is assumed and parsed as an integer
+                gpioCfg.number = gpioConfig.at("num").get<uint32_t>();
+            }
             gpioCfg.direction = gpioConfig["direction"];
             buttonCfg.gpios.push_back(gpioCfg);
         }