More callbacks, further GUI work
This commit is contained in:
parent
d1e0ca32db
commit
44f70f5275
9 changed files with 699 additions and 91 deletions
6
Makefile
6
Makefile
|
@ -4,7 +4,7 @@
|
|||
|
||||
# prefix for installation and search path (like icons)
|
||||
PREFIX = /usr/local/
|
||||
CFLAGS = -Wall -O2 $(CCFLAGS) `pkg-config --cflags glib-2.0` `pkg-config --cflags dbus-glib-1` `pkg-config --cflags dbus-1`
|
||||
CFLAGS = -Wall -g -DDEBUG -O2 $(CCFLAGS) `pkg-config --cflags glib-2.0` `pkg-config --cflags dbus-glib-1` `pkg-config --cflags dbus-1`
|
||||
#CFLAGS = -Wall -O2 $(CCFLAGS)
|
||||
|
||||
LDFLAGS = `pkg-config --libs glib-2.0` `pkg-config --libs dbus-glib-1` `pkg-config --libs dbus-1`
|
||||
|
@ -30,9 +30,9 @@ $(PRGNAME): $(OBJS)
|
|||
$(CC) -o $@ $^ $(LDFLAGS)
|
||||
|
||||
libmetawatch.a: metawatch.o crc16ccitt.o mw_utility.o bt_helper.o
|
||||
ar -cvq libmetawatch.a metawatch.o crc16ccitt.o mw_utility.o bt_helper.o
|
||||
rm -f libmetawatch.a; ar -cvq libmetawatch.a metawatch.o crc16ccitt.o mw_utility.o bt_helper.o
|
||||
|
||||
clean:
|
||||
rm -f *.o *.d $(PRGNAME)
|
||||
rm -f *.o *.d $(PRGNAME) libmetawatch.a
|
||||
|
||||
-include $(DEPS)
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
|
||||
# prefix for installation and search path (like icons)
|
||||
PREFIX = /usr/local/
|
||||
CFLAGS = -DDEBUG -Wall -O2 -Wl,--export-dynamic $(CCFLAGS) -I.. `pkg-config --cflags glib-2.0` `pkg-config --cflags dbus-glib-1` `pkg-config --cflags dbus-1` `pkg-config --cflags gtk+-2.0`
|
||||
CFLAGS = -DDEBUG -g -Wall -O2 -Wl,--export-dynamic $(CCFLAGS) -I.. `pkg-config --cflags glib-2.0` `pkg-config --cflags dbus-glib-1` `pkg-config --cflags dbus-1` `pkg-config --cflags gtk+-2.0`
|
||||
#CFLAGS = -Wall -O2 $(CCFLAGS)
|
||||
|
||||
LDFLAGS = `pkg-config --libs glib-2.0` `pkg-config --libs dbus-glib-1` `pkg-config --libs dbus-1` `pkg-config --libs gtk+-2.0` `pkg-config --libs gmodule-export-2.0` -L.. -lmetawatch
|
||||
|
|
|
@ -62,6 +62,38 @@ void mw_get_battery_voltage_response_cb(mwdevice_t *mwdevice, unsigned short *vo
|
|||
gtk_progress_bar_set_text(batbar, batstr);
|
||||
}
|
||||
|
||||
void on_notify_ok_clicked (GtkButton *button, gpointer user_data)
|
||||
{
|
||||
mwdata_t *mdata = (mwdata_t *)user_data;
|
||||
GtkWidget *notify_win;
|
||||
GtkTextView *tview;
|
||||
GtkTextBuffer *tbuf;
|
||||
GtkTextIter siter, eiter;
|
||||
gchar *text;
|
||||
|
||||
tview = GTK_TEXT_VIEW (gtk_builder_get_object (mdata->builder, "notify_textview"));
|
||||
tbuf = gtk_text_view_get_buffer(tview);
|
||||
gtk_text_buffer_get_start_iter(tbuf, &siter);
|
||||
gtk_text_buffer_get_end_iter(tbuf, &eiter);
|
||||
|
||||
text = gtk_text_buffer_get_text(tbuf, &siter, &eiter, FALSE);
|
||||
|
||||
mw_do_notification(&mdata->mwdevice, "Notification", text, 2);
|
||||
|
||||
notify_win = GTK_WIDGET (gtk_builder_get_object (mdata->builder, "notify_win"));
|
||||
gtk_widget_hide (notify_win);
|
||||
}
|
||||
|
||||
void on_notify_cancel_clicked (GtkButton *button, gpointer user_data)
|
||||
{
|
||||
mwdata_t *mdata = (mwdata_t *)user_data;
|
||||
GtkWidget *notify_win;
|
||||
|
||||
notify_win = GTK_WIDGET (gtk_builder_get_object (mdata->builder, "notify_win"));
|
||||
gtk_widget_hide (notify_win);
|
||||
}
|
||||
|
||||
|
||||
void on_rtc_button_clicked (GtkButton *button, gpointer user_data)
|
||||
{
|
||||
mwdata_t *mdata = (mwdata_t *)user_data;
|
||||
|
@ -72,7 +104,10 @@ void on_rtc_button_clicked (GtkButton *button, gpointer user_data)
|
|||
void on_notify_button_clicked (GtkButton *button, gpointer user_data)
|
||||
{
|
||||
mwdata_t *mdata = (mwdata_t *)user_data;
|
||||
GtkWidget *notify_win;
|
||||
|
||||
notify_win = GTK_WIDGET (gtk_builder_get_object (mdata->builder, "notify_win"));
|
||||
gtk_widget_show (notify_win);
|
||||
}
|
||||
|
||||
void bitmap_read(mwdevice_t *mwdevice, char *filename)
|
||||
|
@ -143,6 +178,28 @@ void bitmap_read(mwdevice_t *mwdevice, char *filename)
|
|||
free(bmapbuf);
|
||||
}
|
||||
|
||||
void on_vibrate_button_clicked (GtkButton *button, gpointer user_data)
|
||||
{
|
||||
mwdata_t *mdata = (mwdata_t *)user_data;
|
||||
}
|
||||
|
||||
void on_set_hands_clicked (GtkButton *button, gpointer user_data)
|
||||
{
|
||||
mwdata_t *mdata = (mwdata_t *)user_data;
|
||||
time_t mtime;
|
||||
struct tm mtm;
|
||||
unsigned short hour;
|
||||
|
||||
mtime = time(NULL);
|
||||
localtime_r(&mtime, &mtm);
|
||||
|
||||
hour = (unsigned char) mtm.tm_hour;
|
||||
if (hour > 12)
|
||||
hour -= 12;
|
||||
|
||||
mw_advance_watch_hands(&mdata->mwdevice, hour, (unsigned char) mtm.tm_min, (unsigned char) mtm.tm_sec);
|
||||
}
|
||||
|
||||
void on_bitmap_button_clicked (GtkButton *button, gpointer user_data)
|
||||
{
|
||||
mwdata_t *mdata = (mwdata_t *)user_data;
|
||||
|
@ -163,6 +220,31 @@ void on_bitmap_button_clicked (GtkButton *button, gpointer user_data)
|
|||
gtk_widget_destroy(dialog);
|
||||
}
|
||||
|
||||
void setup_watchtype_gui(mwdata_t *mdata)
|
||||
{
|
||||
GtkWidget *w;
|
||||
|
||||
if (mdata->mwdevice.devtype == MW_DEVICE_TYPE_DIGITAL || mdata->mwdevice.devtype == MW_DEVICE_TYPE_DEVB_DIGI) {
|
||||
w = GTK_WIDGET (gtk_builder_get_object (mdata->builder, "set_hands"));
|
||||
gtk_widget_hide(w);
|
||||
}
|
||||
if (mdata->mwdevice.devtype == MW_DEVICE_TYPE_ANA_DIGI || mdata->mwdevice.devtype == MW_DEVICE_TYPE_DEVB_ANA_DIGI) {
|
||||
w = GTK_WIDGET (gtk_builder_get_object (mdata->builder, "F_button_label"));
|
||||
gtk_widget_hide(w);
|
||||
w = GTK_WIDGET (gtk_builder_get_object (mdata->builder, "E_button_label"));
|
||||
gtk_widget_hide(w);
|
||||
w = GTK_WIDGET (gtk_builder_get_object (mdata->builder, "D_button_label"));
|
||||
gtk_widget_hide(w);
|
||||
}
|
||||
}
|
||||
|
||||
void mw_get_device_type_response_cb(mwdevice_t *mwdevice, unsigned char devtype, void *user_data)
|
||||
{
|
||||
mwdata_t *mdata = (mwdata_t *)user_data;
|
||||
|
||||
setup_watchtype_gui(mdata);
|
||||
}
|
||||
|
||||
void mw_get_real_time_clock_response_cb(mwdevice_t *mwdevice, struct tm *mw_tm, void *user_data)
|
||||
{
|
||||
mwdata_t *mdata = (mwdata_t *)user_data;
|
||||
|
@ -182,7 +264,7 @@ gboolean handle_mw_io(GIOChannel *mw_io, GIOCondition condition, gpointer udata)
|
|||
int rcvd;
|
||||
int processed;
|
||||
|
||||
rcvd = read(mdata->mwdevice.mw_fd, mdata->rcvbuf+mdata->rcvbuf_pos, 64);
|
||||
rcvd = read(mdata->mwdevice.mw_fd, mdata->rcvbuf/*+mdata->rcvbuf_pos*/, 64);
|
||||
#ifdef DEBUG
|
||||
fprintf(stderr, "read %d bytes:\n", rcvd);
|
||||
#endif
|
||||
|
@ -211,9 +293,7 @@ on_window_destroy (GtkObject *object, gpointer user_data)
|
|||
}
|
||||
|
||||
|
||||
|
||||
int
|
||||
main (int argc, char *argv[])
|
||||
int main (int argc, char *argv[])
|
||||
{
|
||||
GtkBuilder *builder;
|
||||
GtkWidget *window;
|
||||
|
@ -269,6 +349,7 @@ main (int argc, char *argv[])
|
|||
|
||||
mw_init(&mdata.mwdevice, mw_fd);
|
||||
|
||||
mw_set_get_device_type_response_cb(&mdata.mwdevice, mw_get_device_type_response_cb, &mdata);
|
||||
mw_set_get_real_time_clock_response_cb(&mdata.mwdevice, mw_get_real_time_clock_response_cb, &mdata);
|
||||
mw_set_get_battery_voltage_response_cb(&mdata.mwdevice, mw_get_battery_voltage_response_cb, &mdata);
|
||||
|
||||
|
@ -276,7 +357,9 @@ main (int argc, char *argv[])
|
|||
|
||||
mdata.bat_timeout_id = g_timeout_add_seconds(10, battery_level_get_timeout, &mdata);
|
||||
|
||||
// setup_watchtype_gui(&mdata);
|
||||
gtk_main ();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -194,7 +194,7 @@
|
|||
<object class="GtkTable" id="table1">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="n_rows">3</property>
|
||||
<property name="n_rows">2</property>
|
||||
<property name="n_columns">3</property>
|
||||
<child>
|
||||
<object class="GtkVButtonBox" id="vbuttonbox1">
|
||||
|
@ -296,52 +296,6 @@
|
|||
<property name="bottom_attach">2</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkButton" id="notify_button">
|
||||
<property name="label" translatable="yes">Notification</property>
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="receives_default">True</property>
|
||||
<property name="use_action_appearance">False</property>
|
||||
<signal name="clicked" handler="on_notify_button_clicked" swapped="no"/>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="top_attach">2</property>
|
||||
<property name="bottom_attach">3</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkButton" id="bitmap_button">
|
||||
<property name="label" translatable="yes">Bitmap</property>
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="receives_default">True</property>
|
||||
<property name="use_action_appearance">False</property>
|
||||
<signal name="clicked" handler="on_bitmap_button_clicked" swapped="no"/>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="left_attach">1</property>
|
||||
<property name="right_attach">2</property>
|
||||
<property name="top_attach">2</property>
|
||||
<property name="bottom_attach">3</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkButton" id="vibrate_button">
|
||||
<property name="label" translatable="yes">Vibration</property>
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="receives_default">True</property>
|
||||
<property name="use_action_appearance">False</property>
|
||||
<signal name="clicked" handler="on_vibrate_button_clicked" swapped="no"/>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="left_attach">2</property>
|
||||
<property name="right_attach">3</property>
|
||||
<property name="top_attach">2</property>
|
||||
<property name="bottom_attach">3</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkButton" id="rtc_button">
|
||||
<property name="label" translatable="yes">RTC</property>
|
||||
|
@ -354,11 +308,10 @@
|
|||
<packing>
|
||||
<property name="left_attach">1</property>
|
||||
<property name="right_attach">2</property>
|
||||
<property name="x_options"></property>
|
||||
<property name="y_options"></property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<placeholder/>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkVBox" id="vbox2">
|
||||
<property name="visible">True</property>
|
||||
|
@ -408,6 +361,21 @@
|
|||
<property name="bottom_attach">2</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkButton" id="info_button">
|
||||
<property name="label">gtk-about</property>
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="receives_default">True</property>
|
||||
<property name="use_action_appearance">False</property>
|
||||
<property name="use_stock">True</property>
|
||||
<signal name="clicked" handler="on_info_button_clicked" swapped="no"/>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="x_options"></property>
|
||||
<property name="y_options"></property>
|
||||
</packing>
|
||||
</child>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">True</property>
|
||||
|
@ -415,6 +383,77 @@
|
|||
<property name="position">1</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkHButtonBox" id="hbuttonbox2">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<child>
|
||||
<object class="GtkButton" id="notify_button">
|
||||
<property name="label" translatable="yes">Notification</property>
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="receives_default">True</property>
|
||||
<property name="use_action_appearance">False</property>
|
||||
<signal name="clicked" handler="on_notify_button_clicked" swapped="no"/>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
<property name="fill">False</property>
|
||||
<property name="position">0</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkButton" id="bitmap_button">
|
||||
<property name="label" translatable="yes">Bitmap</property>
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="receives_default">True</property>
|
||||
<property name="use_action_appearance">False</property>
|
||||
<signal name="clicked" handler="on_bitmap_button_clicked" swapped="no"/>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
<property name="fill">False</property>
|
||||
<property name="position">1</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkButton" id="vibrate_button">
|
||||
<property name="label" translatable="yes">Vibration</property>
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="receives_default">True</property>
|
||||
<property name="use_action_appearance">False</property>
|
||||
<signal name="clicked" handler="on_vibrate_button_clicked" swapped="no"/>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
<property name="fill">False</property>
|
||||
<property name="position">2</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkButton" id="set_hands">
|
||||
<property name="label" translatable="yes">Set Hands</property>
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="receives_default">True</property>
|
||||
<property name="use_action_appearance">False</property>
|
||||
<signal name="clicked" handler="on_set_hands_clicked" swapped="no"/>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
<property name="fill">False</property>
|
||||
<property name="position">3</property>
|
||||
</packing>
|
||||
</child>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">True</property>
|
||||
<property name="fill">True</property>
|
||||
<property name="position">2</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkStatusbar" id="statusbar1">
|
||||
<property name="visible">True</property>
|
||||
|
@ -424,6 +463,353 @@
|
|||
<packing>
|
||||
<property name="expand">False</property>
|
||||
<property name="fill">True</property>
|
||||
<property name="position">3</property>
|
||||
</packing>
|
||||
</child>
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
<object class="GtkWindow" id="notify_win">
|
||||
<property name="can_focus">False</property>
|
||||
<property name="modal">True</property>
|
||||
<property name="window_position">center-on-parent</property>
|
||||
<child>
|
||||
<object class="GtkVBox" id="vbox3">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<child>
|
||||
<object class="GtkLabel" id="label1">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="ypad">1</property>
|
||||
<property name="label" translatable="yes"><b>Notification text</b></property>
|
||||
<property name="use_markup">True</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">True</property>
|
||||
<property name="fill">True</property>
|
||||
<property name="position">0</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkScrolledWindow" id="scrolledwindow1">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="hscrollbar_policy">automatic</property>
|
||||
<property name="vscrollbar_policy">automatic</property>
|
||||
<child>
|
||||
<object class="GtkTextView" id="notify_textview">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">True</property>
|
||||
<property name="fill">True</property>
|
||||
<property name="position">1</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkHButtonBox" id="hbuttonbox1">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<child>
|
||||
<object class="GtkButton" id="notify_cancel">
|
||||
<property name="label">gtk-cancel</property>
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="receives_default">True</property>
|
||||
<property name="use_action_appearance">False</property>
|
||||
<property name="use_stock">True</property>
|
||||
<signal name="clicked" handler="on_notify_cancel_clicked" swapped="no"/>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
<property name="fill">False</property>
|
||||
<property name="position">0</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkButton" id="notify_ok">
|
||||
<property name="label">gtk-apply</property>
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="receives_default">True</property>
|
||||
<property name="use_action_appearance">False</property>
|
||||
<property name="use_stock">True</property>
|
||||
<signal name="clicked" handler="on_notify_ok_clicked" swapped="no"/>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
<property name="fill">False</property>
|
||||
<property name="position">1</property>
|
||||
</packing>
|
||||
</child>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">True</property>
|
||||
<property name="fill">True</property>
|
||||
<property name="position">2</property>
|
||||
</packing>
|
||||
</child>
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
<object class="GtkWindow" id="window1">
|
||||
<property name="can_focus">False</property>
|
||||
<child>
|
||||
<object class="GtkVBox" id="vbox4">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<child>
|
||||
<object class="GtkLabel" id="label2">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="label" translatable="yes"><b>RTC</b></property>
|
||||
<property name="use_markup">True</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">True</property>
|
||||
<property name="fill">True</property>
|
||||
<property name="padding">5</property>
|
||||
<property name="position">0</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkTable" id="table3">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="n_rows">2</property>
|
||||
<property name="n_columns">4</property>
|
||||
<child>
|
||||
<object class="GtkLabel" id="label3">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="label" translatable="yes">Date</property>
|
||||
</object>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkLabel" id="label6">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="label" translatable="yes">Time</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="left_attach">2</property>
|
||||
<property name="right_attach">3</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkRadioButton" id="h12_radio">
|
||||
<property name="label" translatable="yes">12h</property>
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="receives_default">False</property>
|
||||
<property name="use_action_appearance">False</property>
|
||||
<property name="active">True</property>
|
||||
<property name="draw_indicator">True</property>
|
||||
<property name="group">h24_radio</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="left_attach">2</property>
|
||||
<property name="right_attach">3</property>
|
||||
<property name="top_attach">1</property>
|
||||
<property name="bottom_attach">2</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkRadioButton" id="h24_radio">
|
||||
<property name="label" translatable="yes">24h</property>
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="receives_default">False</property>
|
||||
<property name="use_action_appearance">False</property>
|
||||
<property name="active">True</property>
|
||||
<property name="draw_indicator">True</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="left_attach">3</property>
|
||||
<property name="right_attach">4</property>
|
||||
<property name="top_attach">1</property>
|
||||
<property name="bottom_attach">2</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkVBox" id="vbox6">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<child>
|
||||
<object class="GtkCalendar" id="calendar1">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="year">2011</property>
|
||||
<property name="month">7</property>
|
||||
<property name="day">21</property>
|
||||
<property name="show_week_numbers">True</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">True</property>
|
||||
<property name="fill">True</property>
|
||||
<property name="position">0</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkHBox" id="hbox1">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<child>
|
||||
<object class="GtkLabel" id="label4">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="label" translatable="yes">Format</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">True</property>
|
||||
<property name="fill">True</property>
|
||||
<property name="position">0</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkRadioButton" id="mmdd_radio">
|
||||
<property name="label" translatable="yes">MM/DD</property>
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="receives_default">False</property>
|
||||
<property name="use_action_appearance">False</property>
|
||||
<property name="active">True</property>
|
||||
<property name="draw_indicator">True</property>
|
||||
<property name="group">ddmm_radio</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">True</property>
|
||||
<property name="fill">True</property>
|
||||
<property name="position">1</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkRadioButton" id="ddmm_radio">
|
||||
<property name="label" translatable="yes">DD.MM</property>
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="receives_default">False</property>
|
||||
<property name="use_action_appearance">False</property>
|
||||
<property name="active">True</property>
|
||||
<property name="draw_indicator">True</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">True</property>
|
||||
<property name="fill">True</property>
|
||||
<property name="position">2</property>
|
||||
</packing>
|
||||
</child>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">True</property>
|
||||
<property name="fill">True</property>
|
||||
<property name="position">1</property>
|
||||
</packing>
|
||||
</child>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="left_attach">1</property>
|
||||
<property name="right_attach">2</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<placeholder/>
|
||||
</child>
|
||||
<child>
|
||||
<placeholder/>
|
||||
</child>
|
||||
<child>
|
||||
<placeholder/>
|
||||
</child>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">True</property>
|
||||
<property name="fill">True</property>
|
||||
<property name="position">1</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkHButtonBox" id="hbuttonbox3">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<child>
|
||||
<object class="GtkVBox" id="vbox5">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<child>
|
||||
<object class="GtkButton" id="get_watch_rtc_button">
|
||||
<property name="label" translatable="yes">Get RTC from
|
||||
watch</property>
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="receives_default">True</property>
|
||||
<property name="use_action_appearance">False</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
<property name="fill">False</property>
|
||||
<property name="position">0</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkButton" id="get_sys_rtc_button">
|
||||
<property name="label" translatable="yes">Get RTC from
|
||||
System</property>
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="receives_default">True</property>
|
||||
<property name="use_action_appearance">False</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">True</property>
|
||||
<property name="fill">True</property>
|
||||
<property name="position">1</property>
|
||||
</packing>
|
||||
</child>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
<property name="fill">False</property>
|
||||
<property name="position">0</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkButton" id="set_rtc_button">
|
||||
<property name="label" translatable="yes">Set RTC</property>
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="receives_default">True</property>
|
||||
<property name="use_action_appearance">False</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
<property name="fill">False</property>
|
||||
<property name="position">1</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkButton" id="rtc_ok_button">
|
||||
<property name="label">gtk-apply</property>
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="receives_default">True</property>
|
||||
<property name="use_action_appearance">False</property>
|
||||
<property name="use_stock">True</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
<property name="fill">False</property>
|
||||
<property name="position">2</property>
|
||||
</packing>
|
||||
</child>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">True</property>
|
||||
<property name="fill">True</property>
|
||||
<property name="position">2</property>
|
||||
</packing>
|
||||
</child>
|
||||
|
|
91
metawatch.c
91
metawatch.c
|
@ -222,6 +222,7 @@ int mw_write_oled_buffer(mwdevice_t *mwdevice,
|
|||
if (mwdevice->devtype != MW_DEVICE_TYPE_ANA_DIGI && mwdevice->devtype != MW_DEVICE_TYPE_DEVB_ANA_DIGI)
|
||||
return -1;
|
||||
|
||||
fprintf(stderr, "write oled buf len = %d\n", buflen);
|
||||
/* lower row first since display wil be updated after completion of upper row */
|
||||
if (buflen > 80) {
|
||||
for (i=80; i<buflen; i+=20) {
|
||||
|
@ -235,6 +236,7 @@ int mw_write_oled_buffer(mwdevice_t *mwdevice,
|
|||
memcpy((mdata+1), (buffer+i), 20);
|
||||
mw_send_frame(mwdevice, MW_WRITE_OLED_IDLE_DISPLAY_MSG, 1 | (oled ? 2 : 0), mdata, 21);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -272,11 +274,69 @@ int mw_disable_button(mwdevice_t *mwdevice,
|
|||
return mw_send_frame(mwdevice, MW_ENABLE_BUTTON, 0, mdata, 3);
|
||||
}
|
||||
|
||||
int mw_advance_watch_hands(mwdevice_t *mwdevice, unsigned char hours, unsigned char minutes, unsigned char seconds)
|
||||
{
|
||||
unsigned char mdata[4];
|
||||
|
||||
if (hours > 12)
|
||||
return -1;
|
||||
if (minutes > 60)
|
||||
return -1;
|
||||
if (seconds > 60)
|
||||
return -1;
|
||||
|
||||
mdata[0] = hours;
|
||||
mdata[1] = minutes;
|
||||
mdata[2] = seconds;
|
||||
|
||||
return mw_send_frame(mwdevice, MW_ADVANCE_WATCH_HANDS, 0, mdata, 3);
|
||||
}
|
||||
|
||||
/* ----------------------------------------------------------------------
|
||||
* Watch responses, events or notifications
|
||||
* ---------------------------------------------------------------------- */
|
||||
|
||||
|
||||
int mw_get_device_type_response(mwdevice_t *mwdevice, unsigned char devtype)
|
||||
{
|
||||
#ifdef DEBUG
|
||||
fprintf(stderr, "Got device type ");
|
||||
switch(devtype) {
|
||||
case 0:
|
||||
fprintf(stderr, "Reserved\n");
|
||||
break;
|
||||
case 1:
|
||||
fprintf(stderr, "Ana-Digi\n");
|
||||
break;
|
||||
case 2:
|
||||
fprintf(stderr, "Digital\n");
|
||||
break;
|
||||
case 3:
|
||||
fprintf(stderr, "Development Board Digital\n");
|
||||
break;
|
||||
case 4:
|
||||
fprintf(stderr, "Development Board Ana-Digi\n");
|
||||
break;
|
||||
default:
|
||||
fprintf(stderr, "unknown %d\n", devtype);
|
||||
break;
|
||||
};
|
||||
#endif
|
||||
mwdevice->devtype = devtype;
|
||||
if (mwdevice->mw_get_device_type_response_cb != NULL)
|
||||
mwdevice->mw_get_device_type_response_cb(mwdevice, devtype, mwdevice->mw_gdtypersp_data);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void mw_set_get_device_type_response_cb(mwdevice_t *mwdevice, void (*mw_get_device_type_response_cb) (mwdevice_t *mwdevice, unsigned char devtype, void *user_data), void *user_data)
|
||||
{
|
||||
if (mw_get_device_type_response_cb != NULL)
|
||||
mwdevice->mw_get_device_type_response_cb = mw_get_device_type_response_cb;
|
||||
if (user_data != NULL)
|
||||
mwdevice->mw_gdtypersp_data = user_data;
|
||||
}
|
||||
|
||||
|
||||
int mw_get_real_time_clock_response(mwdevice_t *mwdevice, unsigned char *rtcrsp, int len)
|
||||
{
|
||||
struct tm mtm;
|
||||
|
@ -435,18 +495,10 @@ int decode_frame(mwdevice_t *mwdevice, unsigned char *buf, int len)
|
|||
fprintf(stderr, "decode frame CRC error\n");
|
||||
return -1;
|
||||
}
|
||||
#ifdef DEBUG
|
||||
else
|
||||
fprintf(stderr, "decode frame CRC OK\n");
|
||||
#endif
|
||||
if (buf[0] != MW_SOF) {
|
||||
fprintf(stderr, "decode frame SOF not found\n");
|
||||
return -1;
|
||||
}
|
||||
#ifdef DEBUG
|
||||
else
|
||||
fprintf(stderr, "decode frame found SOF\n");
|
||||
#endif
|
||||
|
||||
msglen = buf[1];
|
||||
msgtype = buf[2];
|
||||
|
@ -456,28 +508,7 @@ int decode_frame(mwdevice_t *mwdevice, unsigned char *buf, int len)
|
|||
|
||||
switch (msgtype) {
|
||||
case MW_GET_DEVICE_TYPE_RSP:
|
||||
fprintf(stderr, "Got device type ");
|
||||
switch(msgdata[0]) {
|
||||
case 0:
|
||||
fprintf(stderr, "Reserved\n");
|
||||
break;
|
||||
case 1:
|
||||
fprintf(stderr, "Ana-Digi\n");
|
||||
break;
|
||||
case 2:
|
||||
fprintf(stderr, "Digital\n");
|
||||
break;
|
||||
case 3:
|
||||
fprintf(stderr, "Development Board Digital\n");
|
||||
break;
|
||||
case 4:
|
||||
fprintf(stderr, "Development Board Ana-Digi\n");
|
||||
break;
|
||||
default:
|
||||
fprintf(stderr, "unknown %d\n", msgdata[0]);
|
||||
break;
|
||||
};
|
||||
mwdevice->devtype = msgdata[0];
|
||||
mw_get_device_type_response(mwdevice, msgdata[0]);
|
||||
break;
|
||||
case MW_GET_INFORMATION_STRING_RSP:
|
||||
msgdata[len-2] = 0;
|
||||
|
|
|
@ -13,6 +13,9 @@
|
|||
typedef struct _mwdevice_t {
|
||||
int mw_fd; /* file decriptor for MW connection */
|
||||
unsigned char devtype; /* the device type of the connected device */
|
||||
/* watch message callbacks */
|
||||
void (*mw_get_device_type_response_cb) (struct _mwdevice_t *mwdevice, unsigned char devtype, void *user_data);
|
||||
void *mw_gdtypersp_data;
|
||||
void (*mw_get_real_time_clock_response_cb) (struct _mwdevice_t *mwdevice, struct tm *mw_tm, void *user_data);
|
||||
void *mw_grtcrsp_data;
|
||||
void (*mw_get_battery_voltage_response_cb) (struct _mwdevice_t *mwdevice, unsigned short *voltage, unsigned char *pgood, unsigned char *charging, void *user_data);
|
||||
|
@ -53,6 +56,9 @@ int mw_write_oled_buffer(mwdevice_t *mwdevice,
|
|||
unsigned char col_index, /* starting index */
|
||||
unsigned char *buffer, int buflen);
|
||||
|
||||
int mw_get_device_type_response(mwdevice_t *mwdevice, unsigned char devtype);
|
||||
void mw_set_get_device_type_response_cb(mwdevice_t *mwdevice, void (*mw_get_device_type_response_cb) (mwdevice_t *mwdevice, unsigned char devtype, void *user_data), void *user_data);
|
||||
|
||||
int mw_get_real_time_clock_response(mwdevice_t *mwdevice, unsigned char *rtcrsp, int len);
|
||||
void mw_set_get_real_time_clock_response_cb(mwdevice_t *mwdevice, void (*mw_get_real_time_clock_response_cb) (mwdevice_t *mwdevice, struct tm *mw_tm, void *user_data), void *user_data);
|
||||
|
||||
|
@ -71,6 +77,8 @@ int mw_enable_button(mwdevice_t *mwdevice, unsigned char mode, unsigned char but
|
|||
|
||||
int mw_disable_button(mwdevice_t *mwdevice, unsigned char mode, unsigned char button_index, unsigned char press_type);
|
||||
|
||||
int mw_advance_watch_hands(mwdevice_t *mwdevice, unsigned char hours, unsigned char minutes, unsigned char seconds);
|
||||
|
||||
int decode_frame(mwdevice_t *mwdevice, unsigned char *buf, int len);
|
||||
|
||||
int mw_init(mwdevice_t *mwdevice, int mw_fd);
|
||||
|
|
|
@ -343,7 +343,7 @@ void process_cmd(char *cmdline, int clinep, mwdata_t *mwdata)
|
|||
}
|
||||
if (strncmp(cmdline, "srtc", 4) == 0) {
|
||||
fprintf(stderr, "Setting RTC from system time...");
|
||||
mw_set_rtc(&mwdata->mwdevice, MW_RTC_CLOCK_24HR, MW_RTC_DATE_DDMM);
|
||||
mw_set_rtc(&mwdata->mwdevice, MW_RTC_CLOCK_12HR, MW_RTC_DATE_MMDD);
|
||||
fprintf(stderr, "OK\n");
|
||||
}
|
||||
if (strncmp(cmdline, "grtc", 4) == 0) {
|
||||
|
@ -399,7 +399,8 @@ void process_cmd(char *cmdline, int clinep, mwdata_t *mwdata)
|
|||
bitmap_read(&mwdata->mwdevice);
|
||||
}
|
||||
if (strncmp(cmdline, "tnote", 5) == 0) {
|
||||
test_notification(&mwdata->mwdevice);
|
||||
// test_notification(&mwdata->mwdevice);
|
||||
mw_do_notification(&mwdata->mwdevice, "TestNotification", "This is a pretty long text that needs to be broken and torn", 1);
|
||||
}
|
||||
if (strncmp(cmdline, "tapp", 4) == 0) {
|
||||
test_application(&mwdata->mwdevice);
|
||||
|
@ -598,6 +599,8 @@ int main(int argc, char **argv)
|
|||
memset(mdata.cmdline, 0, 128);
|
||||
mdata.cmdline_pos = 0;
|
||||
|
||||
mw_init(&mdata.mwdevice, mw_fd);
|
||||
|
||||
g_main_loop_run (mdata.mloop);
|
||||
|
||||
fsync(mw_fd);
|
||||
|
|
96
mw_utility.c
96
mw_utility.c
|
@ -21,11 +21,15 @@
|
|||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "mw_utility.h"
|
||||
#include "metawatch.h"
|
||||
#include "mw_utility.h"
|
||||
|
||||
#include "fonts.h"
|
||||
|
||||
/* ----------------------------------------------------------------------
|
||||
* Generic drawing functions
|
||||
* ---------------------------------------------------------------------- */
|
||||
|
||||
/*
|
||||
* The pixmap buffer has at least one byte per pixel, even for monochrome (bpp=1)
|
||||
* bitmaps
|
||||
|
@ -252,3 +256,93 @@ void mw_buf_draw_line_bresenham(mw_buffer *mwbuf, unsigned int xstart, unsigned
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
/* ----------------------------------------------------------------------
|
||||
* Complex combined functions, for user convenience
|
||||
* ---------------------------------------------------------------------- */
|
||||
|
||||
/*
|
||||
* send a text notification, automatically take care of device type (ana/digi)
|
||||
* char *title is displayed inverse in top line
|
||||
* char *text is the notification text
|
||||
* vibrate is the number of 300ms vibrations, 0 for none
|
||||
*/
|
||||
void mw_do_notification(mwdevice_t *mwdevice, char *title, char *text, unsigned char vibrate)
|
||||
{
|
||||
mw_buffer *mwbuf;
|
||||
unsigned char *bbuf;
|
||||
int len,i,c,r;
|
||||
char sstr[32];
|
||||
|
||||
// fprintf(stderr, "do_notify devtype=%d, title='%s', text='%s', vibrate=%d\n", mwdevice->devtype, title, text, vibrate);
|
||||
if (mwdevice->devtype == MW_DEVICE_TYPE_DIGITAL || mwdevice->devtype == MW_DEVICE_TYPE_DEVB_DIGI) {
|
||||
mwbuf = mw_alloc_pbuffer(96, 96, 1);
|
||||
mw_buf_clear(mwbuf, MW_BLACK);
|
||||
|
||||
mw_buf_print(mwbuf, 0, 0, title, 0, MW_BLACK, MW_WHITE);
|
||||
|
||||
i=0;
|
||||
c=0; r=1;
|
||||
memset(sstr,0,32);
|
||||
while (i<strlen(text)) {
|
||||
sstr[c++] = text[i++];
|
||||
if (c>=16 || i>=strlen(text)) {
|
||||
mw_buf_print(mwbuf, 0, r*9, sstr, 0, MW_WHITE, MW_BLACK);
|
||||
memset(sstr,0,32);
|
||||
c=0; r++;
|
||||
if (r>10)
|
||||
break;
|
||||
};
|
||||
};
|
||||
|
||||
bbuf = mw_make_mw_buffer(mwbuf, &len);
|
||||
mw_send_bitmap(mwdevice, MW_SCREEN_MODE_NOTIFICATION, 96, 96, 0, bbuf, len);
|
||||
mw_update_display(mwdevice, MW_SCREEN_MODE_NOTIFICATION, 1);
|
||||
mw_free_pbuffer(mwbuf);
|
||||
} else if (mwdevice->devtype == MW_DEVICE_TYPE_ANA_DIGI || mwdevice->devtype == MW_DEVICE_TYPE_DEVB_ANA_DIGI) {
|
||||
fprintf(stderr, "do notify OLED\n");
|
||||
mwbuf = mw_alloc_pbuffer(80, 16, 1);
|
||||
mw_buf_clear(mwbuf, MW_BLACK);
|
||||
|
||||
mw_buf_print(mwbuf, 0, 0, title, 0, MW_BLACK, MW_WHITE);
|
||||
|
||||
i=0;
|
||||
c=0; r=1;
|
||||
memset(sstr,0,32);
|
||||
while (i<strlen(text) && r<2) {
|
||||
sstr[c++] = text[i++];
|
||||
if (c>=13 || i>=strlen(text)) {
|
||||
mw_buf_print(mwbuf, 0, r*9, sstr, 0, MW_WHITE, MW_BLACK);
|
||||
memset(sstr,0,32);
|
||||
c=0; r++;
|
||||
};
|
||||
};
|
||||
|
||||
bbuf = mw_make_mw_oled_buffer(mwbuf, &len);
|
||||
mw_write_oled_buffer(mwdevice, 0, MW_OLED_UPPER, 80, 0, bbuf, len);
|
||||
|
||||
mw_buf_clear(mwbuf, MW_BLACK);
|
||||
c=0; r=0;
|
||||
memset(sstr,0,32);
|
||||
while (i<strlen(text) && r<2) {
|
||||
sstr[c++] = text[i++];
|
||||
if (c>=13 || i>=strlen(text)) {
|
||||
mw_buf_print(mwbuf, 0, r*9, sstr, 0, MW_WHITE, MW_BLACK);
|
||||
memset(sstr,0,32);
|
||||
c=0; r++;
|
||||
if (r>2)
|
||||
break;
|
||||
};
|
||||
};
|
||||
|
||||
bbuf = mw_make_mw_oled_buffer(mwbuf, &len);
|
||||
mw_write_oled_buffer(mwdevice, 0, MW_OLED_LOWER, 80, 0, bbuf, len);
|
||||
|
||||
mw_free_pbuffer(mwbuf);
|
||||
} else
|
||||
fprintf(stderr, "Watch type not set - forgot to call mw_init()?\n");
|
||||
|
||||
if (vibrate)
|
||||
mw_set_vibrate_mode(mwdevice, 1, 300, 300, vibrate);
|
||||
}
|
||||
|
||||
|
|
|
@ -54,5 +54,8 @@ void mw_buf_print(mw_buffer *mwbuf, unsigned int x, unsigned int y, char *text,
|
|||
|
||||
void mw_buf_draw_line_bresenham(mw_buffer *mwbuf, unsigned int xstart, unsigned int ystart, unsigned int xend, unsigned int yend, mw_color clr);
|
||||
|
||||
|
||||
void mw_do_notification(mwdevice_t *mwdevice, char *title, char *text, unsigned char vibrate);
|
||||
|
||||
#endif
|
||||
|
||||
|
|
Loading…
Reference in a new issue