Permalink
Browse files

[wiki,grifo] temperature display

Grifo ADC added channel to read temperature in centi-celcius

Wiki conditionally compiled code to display temperature on search screen
when the search string is empty.

set TEMPERATURE_DISPLAY=YES when compiling wiki

If compiled in, then a small 5 pixel high/wide 'T' shows up in the top
right to let you know something is there to press. when you press it it
cycles between C, F, and then back to the T icon.

Signed-off-by: Christopher Hall <hsw@openmoko.com>
  • Loading branch information...
1 parent 5a8e466 commit 26d2c2bdf4777b00feeb7d6a336f39ba96379d39 Robin Humble committed with hxw Jan 10, 2011
Showing with 153 additions and 6 deletions.
  1. +3 −2 Makefile
  2. +3 −0 samo-lib/grifo/src/analog.c
  3. +1 −0 samo-lib/grifo/src/analog.h
  4. +15 −0 wiki/Makefile
  5. +112 −4 wiki/keyboard.c
  6. +7 −0 wiki/keyboard.h
  7. +12 −0 wiki/wikilib.c
View
5 Makefile
@@ -52,7 +52,7 @@
#
# PROGRESS_BAR Enable progress bar when compiling mahatma.elf [NO]
#
-# TEMPERATURE_DISPLAY Enable temperature display when compiling mahatma.elf [NO]
+# TEMPERATURE_DISPLAY Enable temperature display when compiling mahatma.elf/wiki.app [NO]
#
# GRIFO_EXAMPLES Compile / install grifo examples [NO]
#
@@ -248,6 +248,7 @@ clear-history: validate-destdir
${RM} "${DESTDIR_PATH}"/[wW][iI][kK][iI].[iI][nN][fF]
dd if=/dev/zero of="${DESTDIR_PATH}/wiki.hst" bs=67584 count=1
dd if=/dev/zero of="${DESTDIR_PATH}/wiki.pas" bs=40 count=1
+ dd if=/dev/zero of="${DESTDIR_PATH}/wiki.tem" bs=10 count=1
${STRIP_HASH_OR_BLANK_LINES} "${LICENSE_DIR}"/wiki.inf > "${DESTDIR_PATH}"/wiki.inf
id=$$(grep -n -m 1 '${WIKI_LANGUAGE}${WIKI_DIR_SUFFIX}' "${DESTDIR_PATH}/wiki.inf"); \
id=$${id%%:*}; \
@@ -828,7 +829,7 @@ grifo-simulate: validate-destdir
# wiki application using grifo
# ============================
-$(call STD_RULE, wiki, wiki, gcc mini-libc grifo, INSTALL, PROGRESS_BAR="${PROGRESS_BAR}" INSTALL_GRIFO_SIMULATION="${INSTALL_GRIFO_SIMULATION}")
+$(call STD_RULE, wiki, wiki, gcc mini-libc grifo, INSTALL, PROGRESS_BAR="${PROGRESS_BAR}" TEMPERATURE_DISPLAY="${TEMPERATURE_DISPLAY}" INSTALL_GRIFO_SIMULATION="${INSTALL_GRIFO_SIMULATION}")
.PHONY: wiki-simulate
View
3 samo-lib/grifo/src/analog.c
@@ -125,6 +125,9 @@ long Analog_read(Analog_ChannelType channel)
case ANALOG_TEMPERATURE_CELCIUS:
return (adc[1] * THERMISTOR_K1 + THERMISTOR_K0) / THERMISTOR_DIVISOR;
+ case ANALOG_TEMPERATURE_CENTI_CELCIUS:
+ return (adc[1] * THERMISTOR_K1 + THERMISTOR_K0) / ( THERMISTOR_DIVISOR / 100 );
+
default:
return 0;
}
View
1 samo-lib/grifo/src/analog.h
@@ -27,6 +27,7 @@ typedef enum {
ANALOG_BATTERY_MILLIVOLTS,
ANALOG_LCD_MILLIVOLTS,
ANALOG_TEMPERATURE_CELCIUS,
+ ANALOG_TEMPERATURE_CENTI_CELCIUS,
//-MakeSystemCalls: channels
} Analog_ChannelType;
View
15 wiki/Makefile
@@ -59,6 +59,21 @@ ENABLE_PROGRESS ?= 0
# optional items for compiler
CFLAGS += -DENABLE_PROGRESS="${ENABLE_PROGRESS}"
+# enable the temperature display by adding:
+# TEMPERATURE_DISPLAY=yes to make command line
+ifeq (YES,$(strip ${TEMPERATURE_DISPLAY}))
+ENABLE_TEMPERATURE := 1
+endif
+ifeq (yes,$(strip ${TEMPERATURE_DISPLAY}))
+ENABLE_TEMPERATURE := 1
+endif
+
+# default values are disabled
+ENABLE_TEMPERATURE ?= 0
+
+# optional items for compiler
+CFLAGS += -DENABLE_TEMPERATURE="${ENABLE_TEMPERATURE}"
+
# list of sources and headers
SOURCES += ${PROGRAM}.c
SOURCES += Alloc.c
View
116 wiki/keyboard.c
@@ -18,6 +18,7 @@
*/
#include <ctype.h>
+#include <stdio.h>
#include <grifo.h>
@@ -51,6 +52,8 @@ int bKoreanSpecialKeyEnabled = 0;
extern int display_mode;
extern unsigned int touch_down_on_keyboard;
extern int b_type_a_word_cleared;
+int temperature_mode_default = 0; // 0 = None, 1 = Celcius, 2 = Farenheight
+int temperature_mode = 0;
/* qwerty keyboard by columns */
#define KEY(l_x, l_y, r_x, r_y, l_x_i, l_y_i, r_x_i, r_y_i, keycode) \
@@ -102,6 +105,7 @@ static struct keyboard_key qwerty_char[] = {
KEY(216, 181, 239, 207, 218, 183, 236, 205, WL_KEY_SWITCH_KEYBOARD_STR),
KEY(198, 84, 233, 119, 198, 84, 233, 119, WL_KEY_NLS_STR),
+ KEY(180, 10, 239, 27, 180, 10, 239, 27, WL_KEY_TEMPERATURE_STR),
};
static struct keyboard_key qwerty_full_char[] = {
KEY( 0, 126, 23, 152, 3, 128, 21, 150, ""),
@@ -144,6 +148,7 @@ static struct keyboard_key qwerty_full_char[] = {
KEY(216, 181, 239, 207, 218, 183, 236, 205, WL_KEY_SWITCH_KEYBOARD_STR),
KEY(198, 84, 233, 119, 198, 84, 233, 119, WL_KEY_NLS_STR),
+ KEY(180, 10, 239, 27, 180, 10, 239, 27, WL_KEY_TEMPERATURE_STR),
};
static struct keyboard_key qwerty_char_da[] = {
KEY( 0, 126, 20, 152, 1, 128, 19, 150, ""),
@@ -190,6 +195,7 @@ static struct keyboard_key qwerty_char_da[] = {
KEY(219, 181, 239, 207, 220, 183, 238, 205, WL_KEY_BACKSPACE_STR),
KEY(198, 84, 233, 119, 198, 84, 233, 119, WL_KEY_NLS_STR),
+ KEY(180, 10, 239, 27, 180, 10, 239, 27, WL_KEY_TEMPERATURE_STR),
};
static struct keyboard_key qwerty_num[] = {
KEY( 0, 126, 23, 152, 3, 128, 21, 150, "1"),
@@ -232,6 +238,7 @@ static struct keyboard_key qwerty_num[] = {
KEY(216, 181, 239, 207, 218, 183, 236, 205, WL_KEY_SWITCH_KEYBOARD_STR),
KEY(198, 84, 233, 119, 198, 84, 233, 119, WL_KEY_NLS_STR),
+ KEY(180, 10, 239, 27, 180, 10, 239, 27, WL_KEY_TEMPERATURE_STR),
};
static struct keyboard_key phone_jp[] = {
KEY( 0, 127, 45, 146, 2, 128, 43, 145, WL_KEY_NO_WAIT_STR),
@@ -258,6 +265,7 @@ static struct keyboard_key phone_jp[] = {
KEY(144, 187, 193, 207, 146, 189, 191, 205, "、。?!"),
KEY(198, 84, 233, 119, 198, 84, 233, 119, WL_KEY_NLS_STR),
+ KEY(180, 10, 239, 27, 180, 10, 239, 27, WL_KEY_TEMPERATURE_STR),
};
static struct keyboard_key phone_tw[] = {
@@ -285,6 +293,7 @@ static struct keyboard_key phone_tw[] = {
KEY(144, 187, 193, 207, 146, 189, 191, 205, ",‧?!"),
KEY(198, 84, 233, 119, 198, 84, 233, 119, WL_KEY_NLS_STR),
+ KEY(180, 10, 239, 27, 180, 10, 239, 27, WL_KEY_TEMPERATURE_STR),
};
static struct keyboard_key phone_abc[] = {
@@ -312,6 +321,7 @@ static struct keyboard_key phone_abc[] = {
KEY(144, 187, 193, 207, 146, 189, 191, 205, ",‧?!"),
KEY(198, 84, 233, 119, 198, 84, 233, 119, WL_KEY_NLS_STR),
+ KEY(180, 10, 239, 27, 180, 10, 239, 27, WL_KEY_TEMPERATURE_STR),
};
static struct keyboard_key phone_123[] = {
KEY( 0, 127, 45, 146, 2, 128, 43, 145, WL_KEY_NO_WAIT_STR),
@@ -338,6 +348,7 @@ static struct keyboard_key phone_123[] = {
KEY(144, 187, 193, 207, 146, 189, 191, 205, ",‧?!"),
KEY(198, 84, 233, 119, 198, 84, 233, 119, WL_KEY_NLS_STR),
+ KEY(180, 10, 239, 27, 180, 10, 239, 27, WL_KEY_TEMPERATURE_STR),
};
static struct keyboard_key phone_tw_abc[] = {
KEY( 0, 127, 45, 146, 2, 128, 43, 145, WL_KEY_NO_WAIT_STR),
@@ -364,6 +375,7 @@ static struct keyboard_key phone_tw_abc[] = {
KEY(144, 187, 193, 207, 146, 189, 191, 205, ",‧?!"),
KEY(198, 84, 233, 119, 198, 84, 233, 119, WL_KEY_NLS_STR),
+ KEY(180, 10, 239, 27, 180, 10, 239, 27, WL_KEY_TEMPERATURE_STR),
};
static struct keyboard_key phone_tw_123[] = {
KEY( 0, 127, 45, 146, 2, 128, 43, 145, WL_KEY_NO_WAIT_STR),
@@ -390,6 +402,7 @@ static struct keyboard_key phone_tw_123[] = {
KEY(144, 187, 193, 207, 146, 189, 191, 205, ",‧?!"),
KEY(198, 84, 233, 119, 198, 84, 233, 119, WL_KEY_NLS_STR),
+ KEY(180, 10, 239, 27, 180, 10, 239, 27, WL_KEY_TEMPERATURE_STR),
};
static struct keyboard_key password_char[] = {
KEY(175, 81, 228, 105, 177, 83, 226, 103, "Y"),
@@ -583,6 +596,98 @@ int nls_button_enabled()
kb_mode != KEYBOARD_PASSWORD_CHAR && kb_mode != KEYBOARD_PASSWORD_NUM);
}
+#if ENABLE_TEMPERATURE
+int temperature_button_enabled() {
+ return (get_search_string_len() == 0 &&
+ kb_mode != KEYBOARD_PASSWORD_CHAR && kb_mode != KEYBOARD_PASSWORD_NUM);
+}
+#else
+int temperature_button_enabled() {return 0;}
+#endif
+
+unsigned char *temperature_string()
+{
+ static char tMsg[16];
+ long t;
+ //char degree = 0x00B0;
+
+ if (temperature_mode == 0 || temperature_mode > 2)
+ return NULL;
+
+ t = analog_input(ANALOG_TEMPERATURE_CENTI_CELCIUS);
+
+ if (temperature_mode == 2) {// Fahrenheit
+ t = (t*9/5)+3200;
+ }
+ int negative = (t<0?1:0);
+ if (negative) {
+ t = -t;
+ }
+ t += 5; // do proper rounding on the last decimal place
+ int tMajor = t/100;
+ int tMinor = (t - tMajor*100)/10;
+ sprintf(tMsg, "%s%d.%d°%c", (negative?"-":""), tMajor, tMinor, ((temperature_mode==1)?'C':'F'));
+
+ return (unsigned char *)tMsg;
+}
+
+void draw_temperature()
+{
+ const unsigned char *tMsg;
+ int i;
+
+ tMsg = temperature_string();
+ guilib_clear_area(180, 10, 239, 27);
+ if (tMsg != NULL)
+ render_string(SUBTITLE_FONT_IDX, 180, 10, tMsg, 1, 0);
+ else
+ {
+ // tiny 'T'
+ int tSize = 5;
+ for (i = 0; i < tSize; i++ )
+ {
+ lcd_set_pixel(230+i-tSize/2, 15, LCD_BLACK);
+ lcd_set_pixel(230, 15+i, LCD_BLACK);
+ }
+ }
+}
+
+void get_temperature_mode()
+{
+ int fd;
+ char sWikiTem[10];
+ int m;
+ fd = file_open("wiki.tem", FILE_OPEN_READ);
+ if (fd < 0)
+ {
+ temperature_mode = temperature_mode_default;
+ return;
+ }
+ file_read(fd, sWikiTem, 10);
+ file_close(fd);
+ sWikiTem[9] = '\0';
+ m = atoi(sWikiTem);
+ if (m < 0 || m > 2)
+ temperature_mode = temperature_mode_default;
+ else
+ temperature_mode = m;
+}
+
+void set_temperature_mode()
+{
+ int fd;
+ char sWikiTem[10];
+
+ fd = file_open("wiki.tem", FILE_OPEN_WRITE);
+ if (fd < 0)
+ fd = file_create("wiki.tem", FILE_OPEN_WRITE);
+ if (fd >= 0)
+ {
+ sprintf(sWikiTem, "%d\n", temperature_mode);
+ file_write(fd, sWikiTem, strlen(sWikiTem));
+ file_close(fd);
+ }
+}
void keyboard_paint()
{
@@ -627,6 +732,8 @@ void keyboard_paint()
guilib_blit_image(image_data, 0, guilib_framebuffer_height() - image_data->height);
if (nls_button_enabled())
guilib_blit_image(&nls_image, 200, guilib_framebuffer_height() - image_data->height - 40);
+ if (temperature_button_enabled())
+ draw_temperature();
guilib_fb_unlock();
}
@@ -754,7 +861,8 @@ struct keyboard_key * keyboard_get_data(int x, int y)
for (i = 0; i < keyboard_entries; ++i) {
if (keyboard_key[i].left_x <= x && keyboard_key[i].right_x >= x
&& keyboard_key[i].left_y <= y && keyboard_key[i].right_y >= y
- && (nls_button_enabled() || *keyboard_key[i].key != WL_KEY_NLS)) {
+ && (nls_button_enabled() || *keyboard_key[i].key != WL_KEY_NLS)
+ && (temperature_button_enabled() || *keyboard_key[i].key != WL_KEY_TEMPERATURE)) {
return &keyboard_key[i];
}
}
@@ -957,7 +1065,7 @@ void keyboard_process_key_invert(struct keyboard_key *key, bool bResetDelay)
guilib_invert_area(end_x,start_y,end_x,start_y);
guilib_invert_area(end_x,end_y,end_x,end_y);
}
- else if (*key->key == ' ' || *key->key == WL_KEY_BACKSPACE || isupper(*key->key))
+ else if (*key->key == ' ' || *key->key == WL_KEY_BACKSPACE || isupper(*key->key) || *key->key == WL_KEY_TEMPERATURE)
{
guilib_invert_area(start_x,start_y,end_x,end_y);
guilib_invert_area(start_x,start_y,start_x,start_y);
@@ -1066,9 +1174,9 @@ int keyboard_key_reset_invert(int bFlag, unsigned long ev_time)
guilib_fb_lock();
if (*pre_key->key == ' ' || *pre_key->key == WL_KEY_BACKSPACE || isupper(*pre_key->key) ||
kb_mode > KEYBOARD_PHONE_STYLE ||
- (*pre_key->key == WL_KEY_NLS && display_mode != DISPLAY_MODE_WIKI_SELECTION))
+ ((*pre_key->key == WL_KEY_NLS || *pre_key->key == WL_KEY_TEMPERATURE ) && display_mode != DISPLAY_MODE_WIKI_SELECTION))
keyboard_process_key_invert(pre_key, true);
- else if (*pre_key->key != WL_KEY_NLS)
+ else if (*pre_key->key != WL_KEY_NLS && *pre_key->key != WL_KEY_TEMPERATURE)
restore_key_bubble();
bIsKoreanSpecialKey = 0;
View
7 wiki/keyboard.h
@@ -30,6 +30,7 @@
#define MIDDLE_JAMO_COUNT 21
#define FINAL_JAMO_COUNT 28
+#define WL_KEY_TEMPERATURE 0X0B
#define WL_KEY_CLEAR 0X0A
#define WL_KEY_BACKWARD 0X09
#define WL_KEY_BACKSPACE 0x08
@@ -41,6 +42,7 @@
#define WL_KEY_SONANT 0X02
#define WL_KEY_NO_WAIT 0X01
+#define WL_KEY_TEMPERATURE_STR "\x0B\x00"
#define WL_KEY_CLEAR_STR "\x0A\x00"
#define WL_KEY_BACKWARD_STR "\x09\x00"
#define WL_KEY_BACKSPACE_STR "\x08\x00"
@@ -106,4 +108,9 @@ void flash_keyboard_key_invert();
int multi_selection_key(struct keyboard_key *key);
int keyboard_korean_special_key(void);
int is_korean_special_key_enabled(void);
+int temperature_button_enabled(void);
+unsigned char *temperature_string(void);
+void draw_temperature(void);
+void get_temperature_mode(void);
+void set_temperature_mode(void);
#endif
View
12 wiki/wikilib.c
@@ -97,6 +97,7 @@ long finger_move_speed = 0;
extern int over_scroll_lines;
#endif
int finger_touched = 0;
+extern int temperature_mode;
void repaint_search(void)
{
@@ -236,6 +237,16 @@ void handle_search_key(struct keyboard_key *key, unsigned long ev_time)
keyboard_set_mode(KEYBOARD_NONE);
wiki_selection();
return;
+ }
+ else if (keycode == WL_KEY_TEMPERATURE) {
+ delay_us(100000);
+ temperature_mode ++;
+ temperature_mode %= 3;
+ set_temperature_mode();
+ guilib_fb_lock();
+ keyboard_paint();
+ guilib_fb_unlock();
+ return;
} else if (keycode == WL_KEY_BACKSPACE) {
rc = search_remove_char(0, ev_time);
} else if (keycode == WL_KEY_SWITCH_KEYBOARD ||
@@ -1256,6 +1267,7 @@ int wikilib_run(void)
article_buf_pointer = NULL;
search_init();
history_list_init();
+ get_temperature_mode();
print_intro();
pMsg = get_nls_text("type_a_word");
render_string(SUBTITLE_FONT_IDX, -1, 55, pMsg, ustrlen(pMsg), 0);

0 comments on commit 26d2c2b

Please sign in to comment.