1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2024-12-29 04:50:03 +01:00

* added ltc4150 shell command

* cosmetics in ltc4150 driver
This commit is contained in:
Oleg 2010-11-05 23:43:14 +01:00
parent 8f512fd6d4
commit ac6d4788eb
8 changed files with 37 additions and 30 deletions

View File

@ -8,7 +8,7 @@ void ltc4150_start();
void ltc4150_stop();
double ltc4150_get_current_mA();
double ltc4150_get_total_mA();
double ltc4150_get_total_mAh();
double ltc4150_get_avg_mA();
#endif /* __LTC4150_H */

View File

@ -62,7 +62,7 @@ double ltc4150_get_current_mA() {
return 1000000000/(ltc4150_get_last_int_duration_us()*(_GFH * _R_SENSE));
}
double ltc4150_get_total_mA() {
double ltc4150_get_total_mAh() {
return coulomb_to_mA(int_to_coulomb(int_count));
}

View File

@ -6,6 +6,6 @@
SubDir TOP projects default ;
Module default_project : main.c : shell posix_io uart0 shell_commands ps rtc sht11 auto_init ;
Module default_project : main.c : shell posix_io uart0 shell_commands ps rtc sht11 ltc4150 auto_init ;
UseModule default_project ;

View File

@ -6,6 +6,7 @@
#include <string.h>
#include <posix_io.h>
#include <ltc4150.h>
#include <shell.h>
#include <shell_commands.h>
#include <board_uart0.h>
@ -22,11 +23,12 @@ void shell_putchar(int c) {
int main(void) {
posix_open(uart0_handler_pid, 0);
ltc4150_start();
puts("Welcome to ukleos!");
shell_t shell;
shell_init(&shell, _shell_command_list, shell_readc, shell_putchar);
shell_init(&shell, NULL, shell_readc, shell_putchar);
shell_run(&shell);

View File

@ -28,7 +28,7 @@
SubDir TOP sys shell ;
Module shell : shell.c ;
Module shell_commands : shell_commands.c rtc.c sht11.c : shell ;
Module shell_commands : shell_commands.c rtc.c sht11.c ltc4150.c : shell ;
Module ps : ps.c ;

View File

@ -51,15 +51,16 @@ and the mailinglist (subscription via web site)
static void(*find_handler(const shell_command_t *command_list, char *command))(char*) {
const shell_command_t* entry = command_list;
while (entry->name != NULL) {
if ( strcmp(entry->name, command) == 0) {
return entry->handler;
} else {
entry++;
}
}
if (entry) {
while (entry->name != NULL) {
if ( strcmp(entry->name, command) == 0) {
return entry->handler;
} else {
entry++;
}
}
}
#ifdef MODULE_SHELL_COMMANDS
entry = _shell_command_list;
while (entry->name != NULL) {
@ -79,10 +80,12 @@ static void print_help(const shell_command_t *command_list) {
printf("%-20s %s\n", "Command", "Description");
puts("---------------------------------------");
while (entry->name != NULL) {
printf("%-20s %s\n", entry->name, entry->desc);
entry++;
}
if (entry) {
while (entry->name != NULL) {
printf("%-20s %s\n", entry->name, entry->desc);
entry++;
}
}
#ifdef MODULE_SHELL_COMMANDS
entry = _shell_command_list;

View File

@ -15,6 +15,11 @@ extern void _get_humidity_handler(char* unused);
extern void _get_weather_handler(char* unused);
#endif
#ifdef MODULE_LTC4150
extern void _get_current_handler(char* unused);
extern void _reset_current_handler(char* unused);
#endif
const shell_command_t _shell_command_list[] = {
#ifdef MODULE_PS
{"ps", "Prints information about running threads.", _ps_handler},
@ -23,9 +28,13 @@ const shell_command_t _shell_command_list[] = {
{"date", "Geets or gets current date and time.", _date_handler},
#endif
#ifdef MODULE_SHT11
{"gettemp", "Prints measured temperature.", _get_temperature_handler},
{"gethum", "Prints measured humidity.", _get_humidity_handler},
{"getweather", "Prints measured humidity and temperature.", _get_weather_handler},
{"temp", "Prints measured temperature.", _get_temperature_handler},
{"hum", "Prints measured humidity.", _get_humidity_handler},
{"weather", "Prints measured humidity and temperature.", _get_weather_handler},
#endif
#ifdef MODULE_LTC4150
{"cur", "Prints current and average power consumption.", _get_current_handler},
{"rstcur", "Resets coulomb counter.", _reset_current_handler},
#endif
{NULL, NULL, NULL}
};

View File

@ -10,19 +10,15 @@ class MyCmd(cmd.Cmd):
self.stdout.write(line + "\n")
def do_help(self, line):
self.stdout.write(line + "\n")
self.stdout.write("help\n")
def complete_date(self, text, line, begidx, endidx):
date = datetime.now().strftime("%Y-%M-%d %H:%m:%S")
return ["date %s\n" % date]
return ["%s\n" % date]
def do_exit(self, line):
sys.exit(0)
def sender(ser):
time.sleep(5)
ser.write("ps\n")
def reader(ser):
while (1):
c = ser.read(1)
@ -46,9 +42,6 @@ if __name__ == "__main__":
receiver_thread.setDaemon(1)
receiver_thread.start()
sender_thread = threading.Thread(target=sender, args=(ser,))
sender_thread.start()
myshell = MyCmd(stdout=ser)
myshell.prompt = ""