Permalink
Browse files

[mahatma,drivers] Add a temperature display

Show temperature on search screen when the search string is empty

This option is conditionally compiled in if:
  TEMPERATURE_DISPLAY=YES
is on the make command line when compiling mahatma

Signed-off-by: Christopher Hall <hsw@openmoko.com>
  • Loading branch information...
1 parent e54d04f commit 370c120578bc5bf285fd7f3850876b8d39fb3229 Robin Humble committed with hxw Oct 18, 2010
View
5 Makefile
@@ -50,6 +50,8 @@
#
# PROGRESS_BAR Enable progress bar when compiling mahatma.elf [NO]
#
+# TEMPERATURE_DISPLAY Enable temperature display when compiling mahatma.elf [NO]
+#
# EXTRACT_VERSION_FROM a link to XML file name that has an embedded date
# which will be used to set WIKI_VERSION
#
@@ -245,7 +247,8 @@ validate-destdir:
# default: progress bar = off
PROGRESS_BAR ?= NO
-$(call STD_RULE, mahatma, ${SAMO_LIB}/mahatma, mini-libc fatfs drivers, INSTALL, PROGRESS_BAR="${PROGRESS_BAR}")
+TEMPERATURE_DISPLAY ?= NO
+$(call STD_RULE, mahatma, ${SAMO_LIB}/mahatma, mini-libc fatfs drivers, INSTALL, PROGRESS_BAR="${PROGRESS_BAR}" TEMPERATURE_DISPLAY="${TEMPERATURE_DISPLAY}")
# Libraries
View
3 samo-lib/drivers/include/analog.h
@@ -31,9 +31,10 @@ void Analog_initialise(void);
void Analog_scan(void);
// routines to convert the current filtered value
-// to enfineering units
+// to engineering units
int Analog_BatteryMilliVolts(void);
int Analog_TemperatureCelcius(void);
+int Analog_TemperatureCentiCelcius(void);
int Analog_ContrastMilliVolts(void);
#endif
View
1 samo-lib/drivers/include/temperature.h
@@ -29,4 +29,5 @@ void Temperature_initialise(void);
// call this periodically
void Temperature_control(void);
+char *Temperature_string(int celcius);
#endif
View
7 samo-lib/drivers/src/analog.c
@@ -113,7 +113,12 @@ int Analog_BatteryMilliVolts(void)
int Analog_TemperatureCelcius(void)
{
- return (adc[1] * THERMISTOR_K1 + THERMISTOR_K0) / THERMISTOR_DIVISOR;
+ return (Analog_TemperatureCentiCelcius() / 100);
+}
+
+int Analog_TemperatureCentiCelcius(void)
+{
+ return (adc[1] * THERMISTOR_K1 + THERMISTOR_K0) / (THERMISTOR_DIVISOR / 100);
}
int Analog_ContrastMilliVolts(void)
View
26 samo-lib/drivers/src/temperature.c
@@ -22,6 +22,7 @@
#include <stdlib.h>
#include <stdbool.h>
#include <regs.h>
+#include <stdio.h>
#include "analog.h"
#include "contrast.h"
@@ -52,6 +53,31 @@ void Temperature_initialise(void)
}
}
+
+char *Temperature_string(int celcius)
+{
+ static char tMsg[16];
+ //char degree = 0x00B0;
+
+ Analog_scan();
+ int t = Analog_TemperatureCentiCelcius();
+
+ if (!celcius) {// 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, (celcius?'C':'F'));
+
+ return tMsg;
+}
+
+
void Temperature_control(void)
{
unsigned long ticks = Tick_get();
View
21 samo-lib/mahatma/Makefile
@@ -51,8 +51,19 @@ endif
ifeq (yes,$(strip ${PROGRESS_BAR}))
ENABLE_PROGRESS := 1
endif
-# default value is disabled
+
+# enable the temperature display by adding:
+# TEMPERATURE_DISPLAY=yes to make command line
+ifeq (YES,$(strip ${TEMPERATURE_DISPLAY}))
+ENABLE_ := 1
+endif
+ifeq (yes,$(strip ${TEMPERATURE_DISPLAY}))
+ENABLE_TEMPERATURE := 1
+endif
+
+# default values are disabled
ENABLE_PROGRESS ?= 0
+ENABLE_TEMPERATURE ?= 0
INCLUDES += -I${MINI_LIBC_INCLUDE}
INCLUDES += -I${DRIVERS_INCLUDE}
@@ -107,11 +118,13 @@ LZMA_COBJS += LzFind.o
# convert the image files
IMAGES = keyboard_abc keyboard_abc2 keyboard_abc_ko keyboard_abc_da keyboard_123 nls
-IMAGES += keyboard_phone_jp keyboard_phone_abc keyboard_phone_123
+IMAGES += keyboard_phone_jp keyboard_phone_abc keyboard_phone_123
IMAGES += keyboard_phone_tw keyboard_phone_tw_abc keyboard_phone_tw_123
-CFLAGS+=-DINCLUDED_FROM_KERNEL ${PROFILER_ON} -DENABLE_PROGRESS=${ENABLE_PROGRESS}
-LDFLAGS=-static --strip-all -s --no-gc-sections -N -L${MINI_LIBC}
+CFLAGS += -DINCLUDED_FROM_KERNEL ${PROFILER_ON}
+CFLAGS += -DENABLE_PROGRESS=${ENABLE_PROGRESS}
+CFLAGS += -DENABLE_TEMPERATURE=${ENABLE_TEMPERATURE}
+LDFLAGS = -static --strip-all -s --no-gc-sections -N -L${MINI_LIBC}
OBJECTS = mahatma.o
View
12 wiki-app/search.c
@@ -49,6 +49,7 @@
#include "time.h"
#else
#include <tick.h>
+#include <temperature.h>
#endif
#define DBG_SEARCH 0
@@ -1183,6 +1184,12 @@ void search_reload(int flag)
pMsg = get_nls_text("type_a_word");
render_string_and_clear(SUBTITLE_FONT_IDX, -1, 55, pMsg, strlen(pMsg), 0,
0, 35, 239, LCD_HEIGHT_LINES - KEYBOARD_HEIGHT - 1);
+
+#if defined(INCLUDED_FROM_KERNEL) && ENABLE_TEMPERATURE
+ char *tMsg = Temperature_string(1);
+ render_string_and_clear(SUBTITLE_FONT_IDX, 180, 10, tMsg, strlen(tMsg), 1,
+ 0, 0, 239, 40 );
+#endif
keyboard_paint();
goto out;
}
@@ -1305,6 +1312,11 @@ void search_result_display()
pMsg = get_nls_text("type_a_word");
render_string_and_clear(SUBTITLE_FONT_IDX, -1, 55, pMsg, strlen(pMsg), 0,
0, 35, 239, LCD_HEIGHT_LINES - KEYBOARD_HEIGHT - 1);
+#if defined(INCLUDED_FROM_KERNEL) && ENABLE_TEMPERATURE
+ char *tMsg = Temperature_string(1);
+ render_string_and_clear(SUBTITLE_FONT_IDX, 180, 10, tMsg, strlen(tMsg), 1,
+ 0, 0, 239, 40 );
+#endif
keyboard_paint();
goto out;
}
View
8 wiki-app/wikilib.c
@@ -47,7 +47,8 @@
#ifndef INCLUDED_FROM_KERNEL
#include "time.h"
#else
-#include "samo.h"
+#include <samo.h>
+#include <temperature.h>
#endif
//#include <t_services.h>
//#include <kernel.h>
@@ -1417,6 +1418,11 @@ int wikilib_run(void)
#endif
pMsg = get_nls_text("type_a_word");
render_string(SUBTITLE_FONT_IDX, -1, 55, pMsg, strlen(pMsg), 0);
+#if defined(INCLUDED_FROM_KERNEL) && ENABLE_TEMPERATURE
+ char *tMsg = Temperature_string(1);
+ render_string_and_clear(SUBTITLE_FONT_IDX, 180, 10, tMsg, strlen(tMsg), 1,
+ 0, 0, 239, 40 );
+#endif
for (;;) {
if (more_events)

0 comments on commit 370c120

Please sign in to comment.