Simple sample that demonstrates reading the FXOS8700CQ accelerometer, convert the data to JSON and send to an Azure IoT Hub.

Dependencies:   azure_umqtt_c iothub_mqtt_transport mbed-rtos mbed wolfSSL Socket lwip-eth lwip-sys lwip

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers tickcounter_mbed.cpp Source File

tickcounter_mbed.cpp

00001 // Copyright (c) Microsoft. All rights reserved.
00002 // Licensed under the MIT license. See LICENSE file in the project root for full license information.
00003 
00004 #include <cstdlib>
00005 
00006 #ifdef _CRTDBG_MAP_ALLOC
00007 #include <crtdbg.h>
00008 #endif
00009 
00010 #include <cstdio>
00011 #include <cctype>
00012 #include "mbed.h"
00013 #include "azure_c_shared_utility/tickcounter.h"
00014 
00015 class TICK_COUNTER_INSTANCE_TAG
00016 {
00017 public:
00018     clock_t last_clock_value;
00019     uint64_t current_ms;
00020 };
00021 
00022 TICK_COUNTER_HANDLE tickcounter_create(void)
00023 {
00024     TICK_COUNTER_INSTANCE_TAG* result;
00025     result = new TICK_COUNTER_INSTANCE_TAG();
00026     result->last_clock_value = clock();
00027     result->current_ms = result->last_clock_value * 1000 / CLOCKS_PER_SEC;
00028     return result;
00029 }
00030 
00031 void tickcounter_destroy(TICK_COUNTER_HANDLE tick_counter)
00032 {
00033     if (tick_counter != NULL)
00034     {
00035         delete tick_counter;
00036     }
00037 }
00038 
00039 int tickcounter_get_current_ms(TICK_COUNTER_HANDLE tick_counter, uint64_t* current_ms)
00040 {
00041     int result;
00042     if (tick_counter == NULL || current_ms == NULL)
00043     {
00044         result = __LINE__;
00045     }
00046     else
00047     {
00048         TICK_COUNTER_INSTANCE_TAG* tick_counter_instance = (TICK_COUNTER_INSTANCE_TAG*)tick_counter;
00049 
00050         clock_t clock_value = clock();
00051 
00052         tick_counter_instance->current_ms += (clock_value - tick_counter_instance->last_clock_value) * 1000 / CLOCKS_PER_SEC;
00053         tick_counter_instance->last_clock_value = clock_value;
00054         *current_ms = tick_counter_instance->current_ms;
00055 
00056         result = 0;
00057     }
00058     return result;
00059 }