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.
Diff: main.cpp
- Revision:
- 1:fc72e0bdb693
- Parent:
- 0:96794c9fc5a3
diff -r 96794c9fc5a3 -r fc72e0bdb693 main.cpp
--- a/main.cpp Wed Mar 02 20:46:57 2011 +0000
+++ b/main.cpp Thu Apr 07 19:54:09 2011 +0000
@@ -2,141 +2,63 @@
#include "TextLCD.h"
-TextLCD lcd(p30, p29, p28, p27, p26, p25, TextLCD::LCD16x2); // rs, e, d0-d3
-
#include "eth_comfort.h"
#include "rfm.h"
#include "rfm12b.h"
-rfm12b rfm12b_spi(p11, p12, p13, p14, p18); // mosi, miso, sclk, cs, rxdata
+/*!
+ * \file main.cpp
+ * \brief Show the messages from ETH-Radio-Shutters on serial port and lcd
+ * \author Karl Zweimüller
+ */
+TextLCD lcd(p30, p29, p28, p27, p26, p25, TextLCD::LCD16x2); // rs, e, d0-d3
+
+eth_comfort eth_comf(p11, p12, p13, p14, p18, LED4); // mosi, miso, sclk, cs, rxdata, rxled
Serial pc(USBTX, USBRX); // tx, rx
// mbed LEDs
+/*
DigitalOut led1(LED1);
DigitalOut led2(LED2);
DigitalOut led3(LED3);
DigitalOut led4(LED4);
-
-
-
-//---------------------------------------------------------------------
-
-void init(void)
-{
-
-
- rbyte=0;
- bit_cnt=0;
- buffer_cnt=0;
-
- decode=0;
-
- pack_ok=0; // this will be set by ISR, when byte was received
-
-
- // init the eth_receiver
- eth_init();
-
- // Interrupt on every bit-change
- rfm12b_spi.attachISR(&ISR);
-
- // Init the RFM12B
- rfm12b_spi.RFM_init();
-
-}
+*/
//---------------------------------------------------------------------
//
//---------------------------------------------------------------------
-int main()
-{
-uint8_t blocklength=0;
-unsigned int i,j=0,k;
-unsigned long timeout=0;
-unsigned long tick=0;
-uint16_t crc, swapped;
-bool crc_ok = false;
+int main() {
+
+ eth_message message;
- pc.baud(115200);
-
- pc.printf("\n\rConnected to mbed\n\r");
- lcd.printf("Hello!\n");
+ pc.baud(115200);
- init();
-
- // state =start
- startbit=0;
- do{
+ pc.printf("\n\rConnected to mbed\n\r");
+ lcd.printf("Hello!\n");
- if (pack_ok==1){
- timeout=0;
- pack_ok=0;
- j=0;
- };
- if(timeout<10000){
- timeout++;
- }
- else if(timeout==10000){
- if(buffer_cnt>8){
- if (buf[2]==0x10) blocklength=10;
- else if(buf[2]==0x20) blocklength=9;
- else blocklength=99;
- j=0;
- crc_ok = false;
- for(i=0;i<=buffer_cnt;i++){
- pc.printf("%02X ",buf[i]);
- j++;
- if(j==blocklength){
- //check crc
- if(blocklength==9){
- crc=0xbdb7;
- for(k=0;k<7;k++){ // crc over first 7 byte
- crc=calcCRC16r(buf[k],crc,0x8408);
- }
- //swap the two crc-bytes
- swapped = ((crc >> 8) & 0xff) | ((crc << 8) & 0xff00);
- pc.printf("CRC: %04X ",swapped);
- if (((buf[7]<<8) | buf[8]) == swapped) crc_ok = true;
- else crc_ok = false;
- pc.printf("%s", (crc_ok==true) ? "OK" : "Not OK");
- if (crc_ok) {
- pc.printf("\n\rCounter: %02X\n\r",buf[1]);
- pc.printf( " Dev-ID: %02X %02X %02X\n\r",buf[3],buf[4],buf[5]);
- //pc.printf( "Battery: %s\n\r", (buf[6]&0x80 != 0x00) ? "WEAK" : "GOOD");
- pc.printf( "Window : %s\n\r\n\r", (buf[6]&0x01 != 0x00) ? "OPEN" : "CLOSE");
- lcd.cls();
- lcd.printf("#:%02X ID: %02X%02X%02X\n",buf[1],buf[3],buf[4],buf[5]);
- lcd.printf("Window : %s\n", (buf[6]&0x01 != 0x00) ? "OPEN" : "CLOSE");
- }
- }
- pc.printf("\n\r");
- }
- }
-
-
- //start receive from beginning
- buffer_cnt=0;
- bit_cnt=0;
- timeout++;
- startbit=0;
- state=0;
+ do {
+ // anything new?
+ if (eth_comf.readable()) {
+ // read the new message and display
+ message = eth_comf.getMessage();
+ pc.printf("\n\rCounter: %02X\n\r",message.cnt);
+ pc.printf( " Dev-ID: %06X\n\r",message.adr);
+ pc.printf( " cmd: %0X\n\r",message.cmd);
+ //pc.printf( "cmd&0x80: %0X\n\r",message.cmd&0x80);
+ // why doesn't work the following??????????????
+ //pc.printf( "Battery: ");
+ //if (message.cmd&0x80 == 0x00) pc.printf("GOOD\n\r"); else pc.printf("WEAK\n\r");
- pc.printf("\n\r-----------------------------\n\r");
- for(i=0;i<1023;i++)buf[i]=0;
- };
- timeout = 0;
- };
- tick++;
- //delay_ms(100);
- if(tick>=2000000){
- tick=0;
- led1= !led1;
- led3=0; // reset receive-led
- };
-}while(1==1);
+ pc.printf( "Window : %s\n\r\n\r", (message.cmd&0x01 != 0x00) ? "OPEN" : "CLOSE");
+ lcd.cls();
+ lcd.printf("#:%02X ID: %06X\n",message.cnt,message.adr);
+ lcd.printf("Window : %s\n", (message.cmd&0x01 != 0x00) ? "OPEN" : "CLOSE");
+ pc.printf("\n\r");
+ }
+ } while (1==1);
}