Use display to show serial message Only for test
Dependencies: EFM32_SegmentLCD IOFuncLib mbed
Revision 0:c0d5dcd1de43, committed 2015-07-16
- Comitter:
- MaxScorda
- Date:
- Thu Jul 16 21:06:45 2015 +0000
- Child:
- 1:08217ba7f63c
- Commit message:
- Alfa
Changed in this revision
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/EFM32_SegmentLCD.lib Thu Jul 16 21:06:45 2015 +0000 @@ -0,0 +1,1 @@ +https://developer.mbed.org/teams/SiliconLabs/code/EFM32_SegmentLCD/#114aa75da77b
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/Functions.h Thu Jul 16 21:06:45 2015 +0000
@@ -0,0 +1,70 @@
+#include <string>
+genFunctions fnz;
+
+
+/*
+ * Callback for 1 second timebase
+ */
+void tickerCallback(void)
+{
+ seconds++;
+ uint32_t clockValue = ((seconds / 60) % 60) * 100 + (seconds % 60);
+ segmentDisplay.Number(clockValue);
+ segmentDisplay.Symbol(LCD_SYMBOL_COL10, seconds & 0x1);
+}
+
+void blink(void)
+{
+ //sarebbe bene evitare questa funzione ma il notPin non funziona direttamente dentro blinker.attach(blink, TOGGLE_RATE);
+ led.notPin();
+}
+
+
+void serialCb(int events)
+{
+ /* Something triggered the callback, either buffer is full or 'S' is received */
+ unsigned char i;
+ string stringout;
+
+ if(events & SERIAL_EVENT_RX_CHARACTER_MATCH) {
+ //Received 'S', check for buffer length
+ for(i = 0; i < BUFF_LENGTH; i++) {
+ //Found the length!
+
+ stringout=stringout+fnz.char2string(rx_buf[i]);
+ if ((rx_buf[i] == '\n')||(i==BUFF_LENGTH-1)) {
+ segmentDisplay.Write((char *)rx_buf);
+ //oppure
+ // segmentDisplay.Write((char *) stringout.c_str());
+ break;
+ }
+ }
+
+ // Toggle blinking
+ if(blinking) {
+ blinker.detach();
+ blinking = false;
+ } else {
+ blinker.attach(blink, TOGGLE_RATE);
+ blinking = true;
+ }
+ } else if (events & SERIAL_EVENT_RX_COMPLETE) {
+ i = BUFF_LENGTH - 1;
+ } else {
+ rx_buf[0] = 'E';
+ rx_buf[1] = 'R';
+ rx_buf[2] = 'R';
+ rx_buf[3] = '!';
+ rx_buf[4] = 0;
+ i = 3;
+ }
+
+ // Echo string, no callback
+ test_connection.write(rx_buf, i+1, 0, 0);
+
+
+ // Reset serial reception
+ test_connection.read(rx_buf, BUFF_LENGTH, serialEventCb, SERIAL_EVENT_RX_ALL, 'S');
+}
+
+void tickerCallback(void);
\ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/IOFuncLib.lib Thu Jul 16 21:06:45 2015 +0000 @@ -0,0 +1,1 @@ +http://developer.mbed.org/users/MaxScorda/code/IOFuncLib/#b6c09ee246cc
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp Thu Jul 16 21:06:45 2015 +0000
@@ -0,0 +1,63 @@
+#include "mbed.h"
+#include "EFM32_SegmentLCD.h"
+#include "IOFuncLib.h"
+
+
+silabs::EFM32_SegmentLCD segmentDisplay;
+
+
+/*------------ Constant definitions --------------*/
+#define TX_PIN USBTX
+#define RX_PIN USBRX
+#define BRATE 115200
+#define LED_PIN LED1
+#define TOGGLE_RATE (0.5f)
+#define BUFF_LENGTH 5
+
+#define INIT_SECONDS 17600
+
+/*-------- Check if platform compatible ----------*/
+#if DEVICE_SERIAL_ASYNCH
+Serial test_connection(USBTX, USBRX);
+#else
+#error "Platform not compatible with Low Power APIs for Serial"
+#endif
+
+/*------------------ Variables -------------------*/
+LowPowerTicker blinker;
+bool blinking = false;
+event_callback_t serialEventCb;
+//DigitalOut LED(LED_PIN);
+uint8_t rx_buf[BUFF_LENGTH + 1];
+
+volatile uint32_t seconds = INIT_SECONDS;
+Flasher led(LED_PIN);
+
+/******************** Define Timers *****************************/
+// devo separare i timers. Non so il perche'
+LowPowerTicker refreshTicker;
+/*------------------ Callbacks -------------------*/
+
+
+//------------ Funzioni -------------
+#include "Functions.h"
+
+//-------------------------------------
+
+
+/*-------------------- Main ----------------------*/
+int main()
+{
+ /* Very Simple Main (tm) */
+ serialEventCb.attach(serialCb);
+
+ /* Setup serial connection */
+ test_connection.baud(BRATE);
+ test_connection.printf("Low Power API test\n\nSend 'S' to toggle blinking\n");
+ test_connection.read(rx_buf, BUFF_LENGTH, serialEventCb, SERIAL_EVENT_RX_ALL, 'S');
+
+ /* Let the callbacks take care of everything */
+ refreshTicker.attach(&tickerCallback, 1.0f);
+
+ while(1) sleep();
+}
\ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Thu Jul 16 21:06:45 2015 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed/builds/7cff1c4259d7 \ No newline at end of file