added interrupt handler
diff --git a/objects/button_power_obj.c b/objects/button_power_obj.c
index 33cd466..b535d50 100644
--- a/objects/button_power_obj.c
+++ b/objects/button_power_obj.c
@@ -1,3 +1,4 @@
+#include <stdio.h>
#include "interfaces/openbmc_intf.h"
#include "gpio.h"
#include "openbmc.h"
@@ -9,7 +10,7 @@
static GDBusObjectManagerServer *manager = NULL;
//This object will use these GPIOs
-GPIO button = (GPIO){ "POWER_BUTTON" };
+GPIO gpio_button = (GPIO){ "POWER_BUTTON" };
static gboolean
on_is_on (Button *btn,
@@ -31,6 +32,15 @@
button_complete_sim_button_press(btn,invocation);
return TRUE;
}
+static gboolean
+on_button_interrupt( GIOChannel *channel,
+ GIOCondition condition,
+ gpointer user_data )
+{
+ Button* button = object_get_button((Object*)user_data);
+ printf("Power Button pressed\n");
+ button_emit_button_pressed(button);
+}
static void
on_bus_acquired (GDBusConnection *connection,
@@ -47,36 +57,46 @@
}
manager = g_dbus_object_manager_server_new (dbus_object_path);
int i=0;
- for (i=1;i<cmd->argc;i++)
- {
- gchar *s;
- s = g_strdup_printf ("%s/%s",dbus_object_path,cmd->argv[i]);
- object = object_skeleton_new (s);
- g_free (s);
+ gchar *s;
+ s = g_strdup_printf ("%s/%s",dbus_object_path,cmd->argv[1]);
+ object = object_skeleton_new (s);
+ g_free (s);
- Button* button = button_skeleton_new ();
- object_skeleton_set_button (object, button);
- g_object_unref (button);
+ Button* button = button_skeleton_new ();
+ object_skeleton_set_button (object, button);
+ g_object_unref (button);
- //define method callbacks
- g_signal_connect (button,
- "handle-is-on",
- G_CALLBACK (on_is_on),
- NULL); /* user_data */
- g_signal_connect (button,
+ //define method callbacks
+ g_signal_connect (button,
+ "handle-is-on",
+ G_CALLBACK (on_is_on),
+ NULL); /* user_data */
+ g_signal_connect (button,
"handle-sim-button-press",
G_CALLBACK (on_button_press),
NULL); /* user_data */
+ /* Export the object (@manager takes its own reference to @object) */
+ g_dbus_object_manager_server_export (manager, G_DBUS_OBJECT_SKELETON (object));
+ g_object_unref (object);
- /* Export the object (@manager takes its own reference to @object) */
- g_dbus_object_manager_server_export (manager, G_DBUS_OBJECT_SKELETON (object));
- g_object_unref (object);
-
- }
/* Export all objects */
g_dbus_object_manager_server_set_connection (manager, connection);
+
+ // get gpio device paths
+ int rc = GPIO_OK;
+ do {
+ rc = gpio_init(connection,&gpio_button);
+ if (rc != GPIO_OK) { break; }
+ rc = gpio_open_interrupt(&gpio_button,on_button_interrupt,object);
+ if (rc != GPIO_OK) { break; }
+ } while(0);
+ if (rc != GPIO_OK)
+ {
+ printf("ERROR PowerButton: GPIO setup (rc=%d)\n",rc);
+ }
+
}
static void
@@ -84,7 +104,6 @@
const gchar *name,
gpointer user_data)
{
-// g_print ("Acquired the name %s\n", name);
}
static void
@@ -92,7 +111,6 @@
const gchar *name,
gpointer user_data)
{
- // g_print ("Lost the name %s\n", name);
}