X-Git-Url: https://git.karo-electronics.de/?p=oswald.git;a=blobdiff_plain;f=ui%2Foswald-ui.c;h=74d567623639739196deec588bf1c99278a9126d;hp=ff88ff927396839d972d035ec1cbb60be32ea998;hb=HEAD;hpb=a03500b5bbf376bb275002887ec566872efb40c4 diff --git a/ui/oswald-ui.c b/ui/oswald-ui.c index ff88ff9..74d5676 100644 --- a/ui/oswald-ui.c +++ b/ui/oswald-ui.c @@ -12,7 +12,7 @@ #include -#include "Fonts.h" // the MetaWatch fonts +//#include "Fonts.h" // the MetaWatch fonts #include "oswald.h" #include "oswald_main.h" @@ -23,28 +23,28 @@ static oswald_ui *ui_g; -void lcd_set_pixel(gint x, gint y, gboolean state) +void hal_lcd_set_pixel(gint x, gint y, uint8_t state) { gint ix, iy; ix = x*2; iy = y*2; + // we double all pixel to get a bigger picture gdk_draw_point(GDK_DRAWABLE(ui_g->pixmap), state ? ui_g->darea->style->black_gc : ui_g->darea->style->white_gc, ix, iy); gdk_draw_point(GDK_DRAWABLE(ui_g->pixmap), state ? ui_g->darea->style->black_gc : ui_g->darea->style->white_gc, ix+1, iy); gdk_draw_point(GDK_DRAWABLE(ui_g->pixmap), state ? ui_g->darea->style->black_gc : ui_g->darea->style->white_gc, ix, iy+1); gdk_draw_point(GDK_DRAWABLE(ui_g->pixmap), state ? ui_g->darea->style->black_gc : ui_g->darea->style->white_gc, ix+1, iy+1); -// gtk_widget_queue_draw(ui_g->darea); } /* updates the actual LCD so that drawing becomes visible */ -void lcd_update_display(void) +void hal_lcd_update_display(void) { gtk_widget_queue_draw(ui_g->darea); } -void lcd_clear_display(void) +void hal_lcd_clear_display(void) { gdk_draw_rectangle (ui_g->pixmap, ui_g->darea->style->white_gc, @@ -56,6 +56,77 @@ void lcd_clear_display(void) gtk_widget_queue_draw(ui_g->darea); } +static bluetooth_state bt_state = BLUETOOTH_OFF; +static boolean bt_visible = FALSE; + +bluetooth_state hal_bluetooth_set_state(bluetooth_state state) +{ + bt_state = state; + if (bt_state == BLUETOOTH_OFF) + bt_visible = FALSE; + + return bt_state; +} + +bluetooth_state hal_bluetooth_get_state(void) +{ + return bt_state; +} + +uint8_t *hal_bluetooth_get_local_bdaddr(void) +{ + static uint8_t local_bdaddr[6] = {0x00, 0x11, 0x22, 0x33, 0x44, 0x55}; + + return local_bdaddr; +} + +void hal_bluetooth_set_visible(boolean visible) +{ + bt_visible = visible; +} + +boolean hal_bluetooth_get_visible(void) +{ + return bt_visible; +} + +void hal_bluetooth_send_data(const void *mdat, uint16_t mlen) +{ + g_printerr("write comm %d\n", mlen); +} + +const char *hal_get_version_string(void) +{ + return "GTK v0.3"; +} + +const char *hal_get_buildno_string(void) +{ + return BUILDNO; +} + +const char *hal_get_radio_version_string(void) +{ + return "BlueZ"; +} + +void hal_accelerometer_enable(void) +{ + g_printerr("accel enable\n"); + gtk_widget_set_sensitive(ui_g->x_sc, TRUE); + gtk_widget_set_sensitive(ui_g->y_sc, TRUE); + gtk_widget_set_sensitive(ui_g->z_sc, TRUE); +} + +void hal_accelerometer_disable(void) +{ + g_printerr("accel disable\n"); + gtk_widget_set_sensitive(ui_g->x_sc, FALSE); + gtk_widget_set_sensitive(ui_g->y_sc, FALSE); + gtk_widget_set_sensitive(ui_g->z_sc, FALSE); +} + + static gint configure_event (GtkWidget *widget, GdkEventConfigure *event, gpointer user_data) { @@ -167,7 +238,7 @@ void ambientlight_value_changed (GtkRange *range, gpointer user_data) double val; val = gtk_range_get_value(range); - oswald_handle_ambientlight_event((u8t) val); + oswald_handle_ambientlight_event((uint8_t) val); } void accelX_value_changed (GtkRange *range, gpointer user_data) @@ -176,7 +247,7 @@ void accelX_value_changed (GtkRange *range, gpointer user_data) double val; val = gtk_range_get_value(range); - ui->accel_x = (u8t)val; + ui->accel_x = (uint8_t)val; oswald_handle_accel_event(ui->accel_x, ui->accel_y, ui->accel_z); } @@ -186,7 +257,7 @@ void accelY_value_changed (GtkRange *range, gpointer user_data) double val; val = gtk_range_get_value(range); - ui->accel_y = (u8t)val; + ui->accel_y = (uint8_t)val; oswald_handle_accel_event(ui->accel_x, ui->accel_y, ui->accel_z); } @@ -196,7 +267,7 @@ void accelZ_value_changed (GtkRange *range, gpointer user_data) double val; val = gtk_range_get_value(range); - ui->accel_z = (u8t)val; + ui->accel_z = (uint8_t)val; oswald_handle_accel_event(ui->accel_x, ui->accel_y, ui->accel_z); } @@ -219,19 +290,19 @@ static void create_mainwin(oswald_ui *ui) vb = gtk_vbox_new(FALSE, 5); gtk_box_pack_start (GTK_BOX(hb), vb, FALSE, FALSE, 5); - btn = gtk_button_new_with_label(" D "); + btn = gtk_button_new_with_label(" F "); gtk_box_pack_start (GTK_BOX(vb), btn, FALSE, FALSE, 10); - g_signal_connect(G_OBJECT(btn), "clicked", G_CALLBACK(button_D_clicked), ui); + g_signal_connect(G_OBJECT(btn), "clicked", G_CALLBACK(button_F_clicked), ui); + g_signal_connect(G_OBJECT(btn), "button-press-event", G_CALLBACK(button_F_pr), ui); + g_signal_connect(G_OBJECT(btn), "button-release-event", G_CALLBACK(button_F_pr), ui); btn = gtk_button_new_with_label(" E "); gtk_box_pack_start (GTK_BOX(vb), btn, FALSE, FALSE, 10); g_signal_connect(G_OBJECT(btn), "clicked", G_CALLBACK(button_E_clicked), ui); - btn = gtk_button_new_with_label(" F "); + btn = gtk_button_new_with_label(" D "); gtk_box_pack_start (GTK_BOX(vb), btn, FALSE, FALSE, 10); - g_signal_connect(G_OBJECT(btn), "clicked", G_CALLBACK(button_F_clicked), ui); - g_signal_connect(G_OBJECT(btn), "button-press-event", G_CALLBACK(button_F_pr), ui); - g_signal_connect(G_OBJECT(btn), "button-release-event", G_CALLBACK(button_F_pr), ui); + g_signal_connect(G_OBJECT(btn), "clicked", G_CALLBACK(button_D_clicked), ui); ui->darea = gtk_drawing_area_new (); gtk_box_pack_start (GTK_BOX(hb), GTK_WIDGET(ui->darea), FALSE, FALSE, 5); @@ -273,21 +344,27 @@ static void create_mainwin(oswald_ui *ui) l = gtk_label_new("X:"); gtk_box_pack_start (GTK_BOX(hb), l, FALSE, FALSE, 5); - sc = gtk_hscale_new_with_range (0, 255, 1); + sc = gtk_hscale_new_with_range (-128, 127, 1); gtk_box_pack_start (GTK_BOX(hb), sc, TRUE, TRUE, 5); g_signal_connect(G_OBJECT(sc), "value-changed", G_CALLBACK(accelX_value_changed), ui); + ui->x_sc = sc; + gtk_widget_set_sensitive(ui->x_sc, FALSE); l = gtk_label_new("Y:"); gtk_box_pack_start (GTK_BOX(hb), l, FALSE, FALSE, 5); - sc = gtk_hscale_new_with_range (0, 255, 1); + sc = gtk_hscale_new_with_range (-128, 127, 1); gtk_box_pack_start (GTK_BOX(hb), sc, TRUE, TRUE, 5); g_signal_connect(G_OBJECT(sc), "value-changed", G_CALLBACK(accelY_value_changed), ui); + ui->y_sc = sc; + gtk_widget_set_sensitive(ui->y_sc, FALSE); l = gtk_label_new("Z:"); gtk_box_pack_start (GTK_BOX(hb), l, FALSE, FALSE, 5); - sc = gtk_hscale_new_with_range (0, 255, 1); + sc = gtk_hscale_new_with_range (-128, 127, 1); gtk_box_pack_start (GTK_BOX(hb), sc, TRUE, TRUE, 5); g_signal_connect(G_OBJECT(sc), "value-changed", G_CALLBACK(accelZ_value_changed), ui); + ui->z_sc = sc; + gtk_widget_set_sensitive(ui->z_sc, FALSE); gtk_widget_show_all(ui->mainwin); } @@ -323,13 +400,13 @@ static gboolean centisecond_tmo_handler (gpointer userdata) return TRUE; } -void enable_centisecond_timer(void) +void hal_enable_centisecond_timer(void) { ui_g->centisecond_active = TRUE; g_timeout_add(10, centisecond_tmo_handler, ui_g); } -void disable_centisecond_timer(void) +void hal_disable_centisecond_timer(void) { ui_g->centisecond_active = FALSE; } @@ -346,17 +423,81 @@ static gboolean halfsecond_tmo_handler (gpointer userdata) return TRUE; } -void enable_halfsecond_timer(void) +void hal_enable_halfsecond_timer(void) { ui_g->halfsecond_active = TRUE; g_timeout_add(500, halfsecond_tmo_handler, ui_g); } -void disable_halfsecond_timer(void) +void hal_disable_halfsecond_timer(void) { ui_g->halfsecond_active = FALSE; } +void hal_get_rtc(clock_state *rtc) +{ + time_t mt; + struct tm mtime; + + mt = time(NULL); + localtime_r(&mt, &mtime); + + rtc->hour = mtime.tm_hour; + rtc->minute = mtime.tm_min; + rtc->second = mtime.tm_sec; + rtc->day = mtime.tm_mday; + rtc->wday = mtime.tm_wday; + rtc->month = (mtime.tm_mon + 1); + rtc->year = (mtime.tm_year + 1900); + +} + +void hal_set_rtc(const clock_state *rtc, boolean set_set) +{ +} + +void hal_get_power_state(power_state *pwr) +{ + pwr->source = POWER_SOURCE_EXTERNAL; + pwr->charge_state = POWER_CHARGER_CHARGING; + pwr->percent = 50; + pwr->level = 3242; // mV +} + +static boolean BacklightState = FALSE; + +/* sets the backlight on/off, on=TRUE, off=FALSE */ +void hal_lcd_set_backlight(boolean state) +{ + g_print("turn LCD backlight %s\n", state ? "on" : "off"); + BacklightState = state; +} + +boolean hal_lcd_get_backlight(void) +{ + return BacklightState; +} + +static boolean VibrationState = FALSE; + +/* sets the vibration motor on/off, on=TRUE, off=FALSE */ +void hal_vibration_set_state(boolean state) +{ + g_print("turn vibration %s\n", state ? "on" : "off"); + VibrationState = state; +} + +boolean hal_vibration_get_state(void) +{ + return VibrationState; +} + +uint16_t hal_amblight_get_val(void) +{ + return 42; +} + + int main(int argc , char ** argv) { oswald_ui ui;