From f388bbc7c47c9442463b7512e2380dbc508bbb54 Mon Sep 17 00:00:00 2001
From: Bhuvanchandra <bhuvanchandra.dv@gmail.com>
Date: Mon, 18 Jul 2016 23:14:23 +0000
Subject: [PATCH] examples: ds3231: Add simple example for ds3231

Simple example for reading out the time and temperature
from ds3231 RTC every second.

Signed-off-by: Bhuvanchandra DV <bhuvanchandra.dv@gmail.com>
---
 examples/ds3231_test/Makefile      |  3 +++
 examples/ds3231_test/ds3231_test.c | 41 ++++++++++++++++++++++++++++++
 2 files changed, 44 insertions(+)
 create mode 100644 examples/ds3231_test/Makefile
 create mode 100644 examples/ds3231_test/ds3231_test.c

diff --git a/examples/ds3231_test/Makefile b/examples/ds3231_test/Makefile
new file mode 100644
index 0000000..3df6d8d
--- /dev/null
+++ b/examples/ds3231_test/Makefile
@@ -0,0 +1,3 @@
+PROGRAM=ds3231_test
+EXTRA_COMPONENTS = extras/ds3231 extras/i2c
+include ../../common.mk
diff --git a/examples/ds3231_test/ds3231_test.c b/examples/ds3231_test/ds3231_test.c
new file mode 100644
index 0000000..77fc167
--- /dev/null
+++ b/examples/ds3231_test/ds3231_test.c
@@ -0,0 +1,41 @@
+/* Test code for DS3231 high precision RTC module 
+ *
+ * Part of esp-open-rtos
+ * Copyright (C) 2016 Bhuvanchandra DV <bhuvanchandra.dv@gmail.com>
+ * MIT Licensed as described in the file LICENSE
+ */
+#include "espressif/esp_common.h"
+#include "esp/uart.h"
+#include "FreeRTOS.h"
+#include "task.h"
+#include "i2c/i2c.h"
+
+#include "ds3231/ds3231.h"
+
+void task1(void *pvParameters)
+{
+    struct tm time;
+    float tempFloat;
+
+    while(1) {
+        vTaskDelay(100);
+        ds3231_getTime(&time);
+	ds3231_getTempFloat(&tempFloat);
+        printf("TIME:%d:%d:%d, TEMPERATURE:%.2f DegC\r\n", time.tm_hour, time.tm_min, time.tm_sec, tempFloat);
+    }
+}
+
+void user_init(void)
+{
+    const int scl = 5, sda = 4;
+
+    uart_set_baud(0, 115200);
+
+    printf("\n");
+    printf("SDK version : %s\n", sdk_system_get_sdk_version());
+    printf("GIT version : %s\n", GITSHORTREV);
+
+    ds3231_Init(scl, sda);
+
+    xTaskCreate(task1, (signed char *)"tsk1", 256, NULL, 2, NULL);
+}