Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed mbed-rtos 4DGL-uLCD-SE RPCInterface
Diff: main.cpp
- Revision:
- 12:f1856a0b8ced
- Parent:
- 11:0309bef74ba8
- Child:
- 13:f1649dc31b04
diff -r 0309bef74ba8 -r f1856a0b8ced main.cpp
--- a/main.cpp Wed Feb 15 14:04:02 2017 -0600
+++ b/main.cpp Tue Nov 12 19:21:49 2019 +0000
@@ -1,22 +1,128 @@
#include "mbed.h"
#include "rtos.h"
+
+#include "mbed_rpc.h"
+#include "uLCD_4DGL.h"
+
+uLCD_4DGL uLCD(p9,p10,p11); // serial tx, serial rx, reset pin;
+Serial bluetooth(p13,p14);
+Serial pc(USBTX, USBRX);
+
+Mutex stdio_mutex;
+Mutex lcd_mutex;
+
+Thread bluetooth_thread;
+Thread time_thread;
+
+void writeLCD(Arguments *in, Reply *out);
+void setTime (Arguments *in, Reply *out);
+
+//rpc function prototypes
+RPCFunction rpcWriteLCD(&writeLCD, "writeLCD");
+RPCFunction rpcSetTime(&setTime, "setTime");
+
+
+void time_thread_func() {
-DigitalOut led1(LED1);
-DigitalOut led2(LED2);
-Thread thread;
+ while (true) {
+ time_t seconds = time(NULL);
+
+ stdio_mutex.lock();
+ lcd_mutex.lock();
+
+ uLCD.locate(0,0);
+ uLCD.printf("%s", ctime(&seconds)); //Time as a basic string
+
+ stdio_mutex.unlock();
+ lcd_mutex.unlock();
+
+ //printf("Time as seconds since January 1, 1970 = %d\n", seconds);
-void led2_thread() {
- while (true) {
- led2 = !led2;
- Thread::wait(1000);
+ //char buffer[32];
+ //strftime(buffer, 32, "%I:%M %p\n", localtime(&seconds));
+ //printf("Time as a custom formatted string = %s", buffer);
+
+ Thread::wait(1000); //only update every second
+ }
+
+}
+
+
+void bluetooth_thread_func() {
+
+ //The mbed RPC classes are now wrapped to create an RPC enabled version - see RpcClasses.h so don't add to base class
+ // receive commands, and send back the responses
+ char buf[256], outbuf[256];
+ uint16_t buf_pos = 0;
+
+ while(true) {
+ //Thread::wait(20);
+
+ if (pc.readable() == true) {
+ //if (bluetooth.readable() == true) {
+
+ stdio_mutex.lock();
+
+ buf[buf_pos] = pc.getc();
+ //buf[buf_pos] = bluetooth.getc();
+
+ stdio_mutex.unlock();
+
+ if (buf[buf_pos] == '\n') { //the end of the RPC command has been received
+ buf[buf_pos] = '\0';
+ buf_pos = 0;
+ RPC::call(buf, outbuf); //make an RPC call
+
+ stdio_mutex.lock();
+ pc.printf("%s\n", outbuf); //send the response
+ stdio_mutex.unlock();
+ }
+ else {
+ buf_pos++;
+ }
+
+ } else {
+ Thread::yield();
+ }
+
}
}
-
+
int main() {
- thread.start(led2_thread);
+
+ bluetooth_thread.start(bluetooth_thread_func);
+ time_thread.start(time_thread_func);
+
+}
+
+
+// Make sure the method takes in Arguments and Reply objects.
+void setTime (Arguments *in, Reply *out) {
+ static const char * unix_time_str;
+ uint32_t unix_time;
+
+ //set_time(1256729737); // Set RTC time to Wed, 28 Oct 2009 11:35:37
+ unix_time_str = in->getArg<const char*>(); //get a pointer to the location where the argument string is stored
+ unix_time = atoll(unix_time_str);
+
+ set_time(unix_time); // Set RTC time to Wed, 28 Oct 2009 11:35:37
- while (true) {
- led1 = !led1;
- Thread::wait(500);
- }
}
+
+
+// Make sure the method takes in Arguments and Reply objects.
+void writeLCD (Arguments *in, Reply *out) {
+ static const char * msg_str;
+
+ msg_str = in->getArg<const char*>(); //get a pointer to the location where the argument string is stored
+
+ stdio_mutex.lock();
+ lcd_mutex.lock();
+
+ uLCD.locate(0,2);
+ uLCD.printf("%s\r\n",msg_str);
+
+ stdio_mutex.unlock();
+ lcd_mutex.unlock();
+
+}