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/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);
         }