[Pkg-running-devel] [openambit] 08/131: Updated example
Christian Perrier
bubulle at moszumanska.debian.org
Thu Jul 17 20:19:06 UTC 2014
This is an automated email from the git hooks/post-receive script.
bubulle pushed a commit to branch master
in repository openambit.
commit d044a3c10f5b3417c04fa5427d9b68e6c0061d35
Author: Emil Ljungdahl <emil at kratern.se>
Date: Wed Dec 11 23:17:00 2013 +0100
Updated example
---
src/example/CMakeLists.txt | 2 +-
src/example/ambitconsole.c | 76 +++++++++++++++++++++++++++++++---------------
2 files changed, 52 insertions(+), 26 deletions(-)
diff --git a/src/example/CMakeLists.txt b/src/example/CMakeLists.txt
index 1de3352..f639da0 100644
--- a/src/example/CMakeLists.txt
+++ b/src/example/CMakeLists.txt
@@ -11,5 +11,5 @@ add_executable(
)
target_link_libraries(
- ambitconsole libambit
+ ambitconsole ambit
)
diff --git a/src/example/ambitconsole.c b/src/example/ambitconsole.c
index e805358..4fb6bd0 100644
--- a/src/example/ambitconsole.c
+++ b/src/example/ambitconsole.c
@@ -2,6 +2,9 @@
#include <stdio.h>
#include <libambit.h>
+static int log_skip_cb(void *ambit_object, ambit_log_header_t *log_header);
+static void log_data_cb(void *object, ambit_log_entry_t *log_entry);
+
int main(int argc, char *argv[])
{
ambit_object_t *ambit_object;
@@ -12,38 +15,38 @@ int main(int argc, char *argv[])
struct tm *local_time;
if ((ambit_object = libambit_detect()) != NULL) {
- printf("Found clock!!!\n");
+ libambit_device_info_get(ambit_object, &info);
- if (libambit_device_info_get(ambit_object, &info) == 0) {
- printf("Model: %s, serial: %s, FW version: %d.%d.%d\n", info.model, info.serial, info.fw_version[0], info.fw_version[1], info.fw_version[2]);
- }
- else {
- printf("Failed to read info\n");
- }
+ if (libambit_device_supported(ambit_object)) {
+ printf("Device: %s, serial: %s, FW version: %d.%d.%d\n", info.name, info.serial, info.fw_version[0], info.fw_version[1], info.fw_version[2]);
- if (libambit_device_status_get(ambit_object, &status) == 0) {
- printf("Current charge: %d%%\n", status.charge);
- }
- else {
- printf("Failed to read status\n");
- }
+ if (libambit_device_status_get(ambit_object, &status) == 0) {
+ printf("Current charge: %d%%\n", status.charge);
+ }
+ else {
+ printf("Failed to read status\n");
+ }
+
+ if (libambit_personal_settings_get(ambit_object, &settings) == 0) {
+ }
+ else {
+ printf("Failed to read status\n");
+ }
+
+ current_time = time(NULL);
+ local_time = localtime(¤t_time);
+ //if (libambit_date_time_set(ambit_object, local_time) == 0) {
+ //}
+ //else {
+ // printf("Failed to set date and time\n");
+ //}
- if (libambit_personal_settings_get(ambit_object, &settings) == 0) {
+ libambit_log_read(ambit_object, log_skip_cb, log_data_cb, NULL, ambit_object);
}
else {
- printf("Failed to read status\n");
+ printf("Device: %s (fw_version: %d.%d.%d) is not supported yet!\n", info.name, info.fw_version[0], info.fw_version[1], info.fw_version[2]);
}
- current_time = time(NULL);
- local_time = localtime(¤t_time);
- //if (libambit_date_time_set(ambit_object, local_time) == 0) {
- //}
- //else {
- // printf("Failed to set date and time\n");
- //}
-
- libambit_log_read_get_next(ambit_object);
-
libambit_close(ambit_object);
}
else {
@@ -52,3 +55,26 @@ int main(int argc, char *argv[])
return 0;
}
+
+static int log_skip_cb(void *ambit_object, ambit_log_header_t *log_header)
+{
+ static int log_count = 0;
+
+ printf("Got log header \"%s\" %d-%02d-%02d %02d:%02d:%02d\n", log_header->activity_name, log_header->date_time.year, log_header->date_time.month, log_header->date_time.day, log_header->date_time.hour, log_header->date_time.minute, log_header->date_time.msec/1000);
+
+ if (log_count++ > 1) {
+ return 0;
+ }
+
+ return 1;
+}
+
+static void log_data_cb(void *object, ambit_log_entry_t *log_entry)
+{
+ printf("Got log entry \"%s\" %d-%02d-%02d %02d:%02d:%02d\n", log_entry->header.activity_name, log_entry->header.date_time.year, log_entry->header.date_time.month, log_entry->header.date_time.day, log_entry->header.date_time.hour, log_entry->header.date_time.minute, log_entry->header.date_time.msec/1000);
+
+ int i;
+ for (i=0; i<log_entry->header.samples_count; i++) {
+ printf("Sample #%d, type: %d, time: %04u-%02u-%02u %02u:%02u:%2.3f\n", i, log_entry->samples[i].type, log_entry->samples[i].utc_time.year, log_entry->samples[i].utc_time.month, log_entry->samples[i].utc_time.day, log_entry->samples[i].utc_time.hour, log_entry->samples[i].utc_time.minute, (1.0*log_entry->samples[i].utc_time.msec)/1000);
+ }
+}
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-running/openambit.git
More information about the Pkg-running-devel
mailing list