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:
- 14:2e17a27f56b2
- Parent:
- 13:9f581a090e53
- Child:
- 16:f4277e9b8612
--- a/main.cpp Sat Apr 27 09:30:38 2019 +0000 +++ b/main.cpp Sat Jun 08 09:16:21 2019 +0000 @@ -4,7 +4,11 @@ #include "eeprom_cust.h" //#include "digitLCD.h" #include "SB1602E.h" +#include "eventflags.h" +EventFlags button_event_flags; +EventFlags LCD_update_flags; +extern void main_menu(); extern void analyzePayload(); #if 1 #ifdef STM32F207xx @@ -50,7 +54,10 @@ EEPROM ep(SDA,SCL,EEPROM_ADDR,EEPROM::T24C256); extern void eeprom_test(void); -int init_id = 0x12340000; // first 8 bit is the address +int device_address = DEVICE_DEFAULT_ADDRESS; // first 11 bytes +int init_id = 0x00300000; // first 11 bit is the address +int init_filter_handle, broadcast_filter_handle; +int broadcast_id = 0x1ffC0000; uint8_t can_tx_data[8]; uint8_t can_rx_data[8]; @@ -64,6 +71,7 @@ Thread can_receivethread; Thread can_handlethread; +Thread mainmenu_thread; CANMessage msg; MemoryPool<CANMessage, 16> can_mpool; @@ -100,6 +108,16 @@ if (button_status == 0) { printf("button0 down\r\n"); + scaleCalibration(); + button_status = button0.read(); + if (button_status == 0) + { + printf("button0 hold\r\n"); + } + else + { + printf("button0 press hold and release\r\n"); + } } else printf("button0 released\r\n"); @@ -124,9 +142,13 @@ if (button_status == 0) { printf("button1 down\r\n"); + button_event_flags.set(BUTTON1_HOLD_EVENT); } else + { printf("button1 released\r\n"); + button_event_flags.set(BUTTON1_PRESSED_EVENT); + } button1_enabled = true; } @@ -148,9 +170,13 @@ if (button_status == 0) { printf("button2 down\r\n"); + button_event_flags.set(BUTTON2_HOLD_EVENT); } else + { printf("button2 released\r\n"); + button_event_flags.set(BUTTON2_PRESSED_EVENT); + } button2_enabled = true; } @@ -172,9 +198,13 @@ if (button_status == 0) { printf("button3 down\r\n"); + button_event_flags.set(BUTTON3_HOLD_EVENT); } else + { printf("button3 released\r\n"); + button_event_flags.set(BUTTON3_PRESSED_EVENT); + } button3_enabled = true; } @@ -196,9 +226,13 @@ if (button_status == 0) { printf("button4 down\r\n"); + button_event_flags.set(BUTTON4_HOLD_EVENT); } else + { printf("button4 released\r\n"); + button_event_flags.set(BUTTON4_PRESSED_EVENT); + } button4_enabled = true; } @@ -231,7 +265,8 @@ { printf("data[%d]=%d\r\n", loop, can_rx_data[loop]); } - if(msg.id == 1337) { +// if(msg.id == 1337) + { //only queue the message belongs to you CANMessage *can_message = can_mpool.alloc(); memcpy((void *)can_message, (void *)&msg, sizeof(msg)); @@ -253,9 +288,13 @@ { int loop = 0; int8_t ival; - printf("\n\n*** RTOS basic example ***\r\n"); + printf("\n\n*** RTOS starts ***\r\n"); // wait(1); + ep.read((uint32_t)EEPROM_DEVICE_ADDRESS_ADDRESS,device_address); + printf("EEPROM: read device address:%d 0x%08x\r\n", device_address, device_address); + if ((device_address == 0) || (device_address == 0xFFFFFFFF)) + device_address = DEVICE_DEFAULT_ADDRESS; #ifdef LCD_1621 lcd.clear(); // clears display lcd.allsegson(); @@ -279,7 +318,9 @@ // can1.reset(); // can2.reset(); can1.frequency(100000); - can1.filter(init_id, 0xFFFC0000, CANExtended); // 0xFFFC0000 to filter the last 18bits 0-17 + can1.filter((device_address<<18), 0x1FFC0000, CANExtended, init_filter_handle); // 0x1FFC0000 to filter the last 18bits 0-17 +//only support one filter +// can1.filter(broadcast_id, 0x1FFC0000, CANExtended, broadcast_filter_handle); // the broadcast id // can2.frequency(100000); //button0.mode(PullUp); // Activate pull-up can_receivethread.start(can_rxthread); @@ -301,7 +342,14 @@ // scaleCalibration(); init_scale(); scale_thread.start(scale_reading); + mainmenu_thread.start(main_menu); + #endif + while(1) { + wait(1); + } + +#if 0 int idx = 0; // Just for printf below can_tx_data[0] = 0; while(1) { @@ -327,17 +375,6 @@ can_tx_data[0]++; } } +#endif -#if 0 - while(1) { - // can1.write(CANMessage(1337, reinterpret_cast<char*>(&a), sizeof(a))); -#if - can1.write(CANMessage(1337, reinterpret_cast<char*>(&a), 1)); -#endif - printf("loop a=%d\n", a); - led1 = !led1; - a++; - wait(0.2); - } -#endif }