r4261 - in trunk/src/target/OM-2007.2/panel-plugins/openmoko-panel-gps: data src
tick at sita.openmoko.org
tick at sita.openmoko.org
Thu Mar 27 18:48:04 CET 2008
Author: tick
Date: 2008-03-27 18:47:55 +0100 (Thu, 27 Mar 2008)
New Revision: 4261
Added:
trunk/src/target/OM-2007.2/panel-plugins/openmoko-panel-gps/data/GPS_Off.png
trunk/src/target/OM-2007.2/panel-plugins/openmoko-panel-gps/data/GPS_On.png
Modified:
trunk/src/target/OM-2007.2/panel-plugins/openmoko-panel-gps/data/Makefile.am
trunk/src/target/OM-2007.2/panel-plugins/openmoko-panel-gps/src/openmoko-panel-gps.c
Log:
implementation of GPS applet, for GTA02V05
Added: trunk/src/target/OM-2007.2/panel-plugins/openmoko-panel-gps/data/GPS_Off.png
===================================================================
(Binary files differ)
Property changes on: trunk/src/target/OM-2007.2/panel-plugins/openmoko-panel-gps/data/GPS_Off.png
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Added: trunk/src/target/OM-2007.2/panel-plugins/openmoko-panel-gps/data/GPS_On.png
===================================================================
(Binary files differ)
Property changes on: trunk/src/target/OM-2007.2/panel-plugins/openmoko-panel-gps/data/GPS_On.png
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Modified: trunk/src/target/OM-2007.2/panel-plugins/openmoko-panel-gps/data/Makefile.am
===================================================================
--- trunk/src/target/OM-2007.2/panel-plugins/openmoko-panel-gps/data/Makefile.am 2008-03-27 09:51:26 UTC (rev 4260)
+++ trunk/src/target/OM-2007.2/panel-plugins/openmoko-panel-gps/data/Makefile.am 2008-03-27 17:47:55 UTC (rev 4261)
@@ -5,4 +5,5 @@
#
resourcedir = $(pkgdatadir)
resource_DATA = \
- GPS.png
+ GPS_On.png \
+ GPS_Off.png
Modified: trunk/src/target/OM-2007.2/panel-plugins/openmoko-panel-gps/src/openmoko-panel-gps.c
===================================================================
--- trunk/src/target/OM-2007.2/panel-plugins/openmoko-panel-gps/src/openmoko-panel-gps.c 2008-03-27 09:51:26 UTC (rev 4260)
+++ trunk/src/target/OM-2007.2/panel-plugins/openmoko-panel-gps/src/openmoko-panel-gps.c 2008-03-27 17:47:55 UTC (rev 4261)
@@ -15,12 +15,17 @@
* Current Version: $Rev$ ($Date$) [$Author: mickey $]
*/
#include <libmokopanelui2/moko-panel-applet.h>
-
+#include <gtk/gtkbox.h>
+#include <gtk/gtk.h>
#include <gtk/gtkimage.h>
#include <time.h>
+#include <stdlib.h>
+#include <stdio.h>
+#define GPS_PWOERON_FILENAME "/sys/bus/platform/drivers/neo1973-pm-gps/neo1973-pm-gps.0/pwron"
typedef struct {
- int dummy;
+ MokoPanelApplet* mokoapplet;
+ int state;
} GpsApplet;
static void
@@ -29,6 +34,62 @@
g_slice_free (GpsApplet, applet);
}
+static int
+gps_applet_power_get()
+{
+ char buf[64];
+ FILE * f = fopen(GPS_PWOERON_FILENAME, "r");
+ int ret;
+ if (!f) {
+ printf("Open file %s failed!!\n",GPS_PWOERON_FILENAME);
+ return 0;
+ }
+ ret = fread(buf,sizeof(char),sizeof(buf)/sizeof(char),f);
+ fclose(f);
+ if (ret > 0 && buf[0]=='1') {
+ return 1;
+ }
+ return 0;
+}
+
+static int
+gps_applet_power_set(int on)
+{
+ char buf[64];
+ FILE * f = fopen(GPS_PWOERON_FILENAME, "w");
+ int ret;
+ if (!f) {
+ printf("Open file %s failed!!\n",GPS_PWOERON_FILENAME);
+ return 0;
+ }
+ sprintf(buf,"%d",on ==0 ? 0 : 1);
+ ret = fwrite(buf,sizeof(char),sizeof(buf)/sizeof(char),f);
+ fclose(f);
+ if (ret <= 0) {
+ printf("Write date into device failed!!\n");
+ return 0;
+ }
+ return on ==0 ? 0 : 1;
+}
+
+static void
+mb_panel_update (GpsApplet *applet, int state)
+{
+ moko_panel_applet_set_icon( applet->mokoapplet, state == 1 ? PKGDATADIR "/GPS_On.png" : PKGDATADIR "/GPS_Off.png");
+ applet->state = state;
+ printf("GPS State is %d\n", applet->state);
+}
+
+static void
+gps_applet_power_on (GtkWidget* menu, GpsApplet* applet) {
+ mb_panel_update(applet,gps_applet_power_set(1));
+}
+static void
+gps_applet_power_off (GtkWidget* menu, GpsApplet* applet) {
+ mb_panel_update(applet,gps_applet_power_set(0));
+}
+
+
G_MODULE_EXPORT GtkWidget*
mb_panel_applet_create(const char* id, GtkOrientation orientation)
{
@@ -39,8 +100,22 @@
struct tm *local_time;
applet = g_slice_new (GpsApplet);
+ applet->mokoapplet = mokoapplet;
+ applet->state=-100;
- moko_panel_applet_set_icon( mokoapplet, PKGDATADIR "/GPS.png" );
+ moko_panel_applet_set_icon(applet->mokoapplet,PKGDATADIR "/GPS_Off.png");
+ mb_panel_update(applet, gps_applet_power_get());
gtk_widget_show_all( GTK_WIDGET(mokoapplet) );
+
+ GtkMenu* menu = GTK_MENU(gtk_menu_new());
+ GtkWidget* item1 = gtk_menu_item_new_with_label("Power-Up GPS");
+ GtkWidget* item2 = gtk_menu_item_new_with_label("Power-Off GPS");
+ g_signal_connect(G_OBJECT(item1), "activate", G_CALLBACK(gps_applet_power_on), applet);
+ g_signal_connect(G_OBJECT(item2), "activate", G_CALLBACK(gps_applet_power_off), applet);
+ gtk_menu_shell_append(GTK_MENU_SHELL(menu), item1);
+ gtk_menu_shell_append(GTK_MENU_SHELL(menu), item2);
+ gtk_widget_show_all(GTK_WIDGET(menu));
+ moko_panel_applet_set_popup( mokoapplet, GTK_WIDGET(menu), MOKO_PANEL_APPLET_CLICK_POPUP);
+
return GTK_WIDGET(mokoapplet);
};
More information about the commitlog
mailing list