Feng Hong / Mbed OS Nucleo_rtos_basic
Committer:
hi1000
Date:
Sat Jun 29 09:53:19 2019 +0000
Revision:
16:f4277e9b8612
Parent:
14:2e17a27f56b2
Child:
17:faa4d4976d22
add device_type and command struct

Who changed what in which revision?

UserRevisionLine numberNew contents of line
hi1000 0:765cf978c3e5 1 #include "mbed.h"
hi1000 1:eb499e2a1b9b 2 #include <HX711.h>
hi1000 2:61a0169765bf 3 #include <eeprom.h>
hi1000 7:e0c7e624c5fa 4 #include "eeprom_cust.h"
hi1000 5:4585215afd11 5 //#include "digitLCD.h"
hi1000 5:4585215afd11 6 #include "SB1602E.h"
hi1000 14:2e17a27f56b2 7 #include "eventflags.h"
hi1000 9:486f65124378 8
hi1000 14:2e17a27f56b2 9 EventFlags button_event_flags;
hi1000 14:2e17a27f56b2 10 EventFlags LCD_update_flags;
hi1000 14:2e17a27f56b2 11 extern void main_menu();
hi1000 7:e0c7e624c5fa 12 extern void analyzePayload();
hi1000 11:8702316d7fc8 13 #if 1
hi1000 11:8702316d7fc8 14 #ifdef STM32F207xx
hi1000 11:8702316d7fc8 15 HX711 hx711(PB_11, PB_10);// data, clk
hi1000 11:8702316d7fc8 16 #endif
hi1000 11:8702316d7fc8 17
hi1000 11:8702316d7fc8 18 #ifdef STM32F303xE
hi1000 11:8702316d7fc8 19 //HX711 hx711(D8, D9);// data, clk
hi1000 11:8702316d7fc8 20 HX711 hx711(PA_14, PA_15);
hi1000 11:8702316d7fc8 21 #endif
hi1000 7:e0c7e624c5fa 22 extern void scaleCalibration();
hi1000 11:8702316d7fc8 23 extern void init_scale();
hi1000 11:8702316d7fc8 24 Thread scale_thread;
hi1000 11:8702316d7fc8 25 extern void scale_reading();
hi1000 9:486f65124378 26 #endif
hi1000 8:6105ffbaf237 27 unsigned char rx_buffer[8], tx_buffer[8];
hi1000 7:e0c7e624c5fa 28 unsigned char rx_length, tx_length;
hi1000 0:765cf978c3e5 29
hi1000 5:4585215afd11 30 #define LCD_1602
hi1000 9:486f65124378 31 #ifdef STM32F207xx
hi1000 5:4585215afd11 32 SB1602E lcd( PB_9, PB_8 ); // SDA, SCL
hi1000 0:765cf978c3e5 33 CAN can1(PD_0, PD_1);
hi1000 0:765cf978c3e5 34 CAN can2(PB_5, PB_6);
hi1000 1:eb499e2a1b9b 35 DigitalOut led1(LED1);
hi1000 1:eb499e2a1b9b 36 DigitalOut led2(LED2);
hi1000 1:eb499e2a1b9b 37 //FlashIAP flashIAP;
hi1000 1:eb499e2a1b9b 38
hi1000 5:4585215afd11 39 //#define LCD_1621
hi1000 5:4585215afd11 40 //digitLCD lcd(PA_5,PA_4,PB_5); // WO, CS, DATA
hi1000 9:486f65124378 41 #endif
hi1000 9:486f65124378 42 #ifdef STM32F303xE
hi1000 9:486f65124378 43 SB1602E lcd(D14, D15 ); // SDA, SCL
hi1000 9:486f65124378 44 CAN can1(PA_11, PA_12); // RD, TD
hi1000 9:486f65124378 45 DigitalOut led1(LED1); // only one LED PA_5
hi1000 9:486f65124378 46 DigitalOut led2(LED2); // only one LED PA_5
hi1000 9:486f65124378 47 #endif
hi1000 7:e0c7e624c5fa 48
hi1000 12:5cb359f981f3 49 DigitalOut output1(PC_3);
hi1000 12:5cb359f981f3 50 DigitalOut output2(PC_2);
hi1000 12:5cb359f981f3 51 DigitalOut output3(PB_7);
hi1000 12:5cb359f981f3 52 DigitalIn input1(PC_6);
hi1000 12:5cb359f981f3 53 DigitalIn input2(PC_8);
hi1000 2:61a0169765bf 54
hi1000 10:d1104e320de7 55 EEPROM ep(SDA,SCL,EEPROM_ADDR,EEPROM::T24C256);
hi1000 9:486f65124378 56 extern void eeprom_test(void);
hi1000 16:f4277e9b8612 57 int device_address = DEVICE_DEFAULT_ADDRESS; // address 11 bits: last 8 bits is device_address
hi1000 16:f4277e9b8612 58 int device_type; //address 11 bits: first 3 bits is device_type
hi1000 14:2e17a27f56b2 59 int init_id = 0x00300000; // first 11 bit is the address
hi1000 14:2e17a27f56b2 60 int init_filter_handle, broadcast_filter_handle;
hi1000 14:2e17a27f56b2 61 int broadcast_id = 0x1ffC0000;
hi1000 1:eb499e2a1b9b 62
hi1000 9:486f65124378 63 uint8_t can_tx_data[8];
hi1000 9:486f65124378 64 uint8_t can_rx_data[8];
hi1000 0:765cf978c3e5 65
hi1000 0:765cf978c3e5 66 void print_char(char c = '*')
hi1000 0:765cf978c3e5 67 {
hi1000 0:765cf978c3e5 68 printf("%c\r\n", c);
hi1000 0:765cf978c3e5 69 fflush(stdout);
hi1000 0:765cf978c3e5 70 }
hi1000 0:765cf978c3e5 71
hi1000 11:8702316d7fc8 72
hi1000 8:6105ffbaf237 73 Thread can_receivethread;
hi1000 8:6105ffbaf237 74 Thread can_handlethread;
hi1000 14:2e17a27f56b2 75 Thread mainmenu_thread;
hi1000 1:eb499e2a1b9b 76
hi1000 0:765cf978c3e5 77 CANMessage msg;
hi1000 8:6105ffbaf237 78 MemoryPool<CANMessage, 16> can_mpool;
hi1000 8:6105ffbaf237 79 Queue<CANMessage, 16> can_queue;
hi1000 0:765cf978c3e5 80
hi1000 12:5cb359f981f3 81 InterruptIn button0(USER_BUTTON);
hi1000 12:5cb359f981f3 82 volatile bool button0_pressed = false; // Used in the main loop
hi1000 12:5cb359f981f3 83 volatile bool button0_enabled = true; // Used for debouncing
hi1000 12:5cb359f981f3 84 Timeout button0_timeout; // Used for debouncing
hi1000 12:5cb359f981f3 85 InterruptIn button1(PB_4);
hi1000 0:765cf978c3e5 86 volatile bool button1_pressed = false; // Used in the main loop
hi1000 0:765cf978c3e5 87 volatile bool button1_enabled = true; // Used for debouncing
hi1000 0:765cf978c3e5 88 Timeout button1_timeout; // Used for debouncing
hi1000 12:5cb359f981f3 89 InterruptIn button2(PC_1);
hi1000 12:5cb359f981f3 90 volatile bool button2_pressed = false; // Used in the main loop
hi1000 12:5cb359f981f3 91 volatile bool button2_enabled = true; // Used for debouncing
hi1000 12:5cb359f981f3 92 Timeout button2_timeout; // Used for debouncing
hi1000 12:5cb359f981f3 93 InterruptIn button3(PC_7);
hi1000 12:5cb359f981f3 94 volatile bool button3_pressed = false; // Used in the main loop
hi1000 12:5cb359f981f3 95 volatile bool button3_enabled = true; // Used for debouncing
hi1000 12:5cb359f981f3 96 Timeout button3_timeout; // Used for debouncing
hi1000 12:5cb359f981f3 97 InterruptIn button4(PA_9);
hi1000 12:5cb359f981f3 98 volatile bool button4_pressed = false; // Used in the main loop
hi1000 12:5cb359f981f3 99 volatile bool button4_enabled = true; // Used for debouncing
hi1000 12:5cb359f981f3 100 Timeout button4_timeout; // Used for debouncing
hi1000 12:5cb359f981f3 101
hi1000 0:765cf978c3e5 102
hi1000 0:765cf978c3e5 103 // Enables button when bouncing is over
hi1000 12:5cb359f981f3 104 //button0
hi1000 12:5cb359f981f3 105 void button0_enabled_cb(void)
hi1000 12:5cb359f981f3 106 {
hi1000 12:5cb359f981f3 107 int button_status;
hi1000 12:5cb359f981f3 108 button_status = button0.read();
hi1000 12:5cb359f981f3 109 if (button_status == 0)
hi1000 12:5cb359f981f3 110 {
hi1000 12:5cb359f981f3 111 printf("button0 down\r\n");
hi1000 14:2e17a27f56b2 112 scaleCalibration();
hi1000 14:2e17a27f56b2 113 button_status = button0.read();
hi1000 14:2e17a27f56b2 114 if (button_status == 0)
hi1000 14:2e17a27f56b2 115 {
hi1000 14:2e17a27f56b2 116 printf("button0 hold\r\n");
hi1000 14:2e17a27f56b2 117 }
hi1000 14:2e17a27f56b2 118 else
hi1000 14:2e17a27f56b2 119 {
hi1000 14:2e17a27f56b2 120 printf("button0 press hold and release\r\n");
hi1000 14:2e17a27f56b2 121 }
hi1000 12:5cb359f981f3 122 }
hi1000 12:5cb359f981f3 123 else
hi1000 12:5cb359f981f3 124 printf("button0 released\r\n");
hi1000 12:5cb359f981f3 125 button0_enabled = true;
hi1000 12:5cb359f981f3 126 }
hi1000 12:5cb359f981f3 127
hi1000 12:5cb359f981f3 128 // ISR handling button pressed event
hi1000 12:5cb359f981f3 129 void button0_onpressed_cb(void)
hi1000 12:5cb359f981f3 130 {
hi1000 12:5cb359f981f3 131 if (button0_enabled) { // Disabled while the button is bouncing
hi1000 12:5cb359f981f3 132 button0_enabled = false;
hi1000 12:5cb359f981f3 133 button0_pressed = true; // To be read by the main loop
hi1000 12:5cb359f981f3 134 button0_timeout.attach(callback(button0_enabled_cb), 0.3); // Debounce time 300 ms
hi1000 12:5cb359f981f3 135 }
hi1000 12:5cb359f981f3 136 }
hi1000 12:5cb359f981f3 137 //button0--
hi1000 12:5cb359f981f3 138 //button1
hi1000 0:765cf978c3e5 139 void button1_enabled_cb(void)
hi1000 0:765cf978c3e5 140 {
hi1000 12:5cb359f981f3 141 int button_status;
hi1000 12:5cb359f981f3 142 button_status = button1.read();
hi1000 12:5cb359f981f3 143 if (button_status == 0)
hi1000 12:5cb359f981f3 144 {
hi1000 12:5cb359f981f3 145 printf("button1 down\r\n");
hi1000 14:2e17a27f56b2 146 button_event_flags.set(BUTTON1_HOLD_EVENT);
hi1000 12:5cb359f981f3 147 }
hi1000 12:5cb359f981f3 148 else
hi1000 14:2e17a27f56b2 149 {
hi1000 12:5cb359f981f3 150 printf("button1 released\r\n");
hi1000 14:2e17a27f56b2 151 button_event_flags.set(BUTTON1_PRESSED_EVENT);
hi1000 14:2e17a27f56b2 152 }
hi1000 0:765cf978c3e5 153 button1_enabled = true;
hi1000 0:765cf978c3e5 154 }
hi1000 0:765cf978c3e5 155
hi1000 0:765cf978c3e5 156 // ISR handling button pressed event
hi1000 0:765cf978c3e5 157 void button1_onpressed_cb(void)
hi1000 0:765cf978c3e5 158 {
hi1000 0:765cf978c3e5 159 if (button1_enabled) { // Disabled while the button is bouncing
hi1000 0:765cf978c3e5 160 button1_enabled = false;
hi1000 0:765cf978c3e5 161 button1_pressed = true; // To be read by the main loop
hi1000 0:765cf978c3e5 162 button1_timeout.attach(callback(button1_enabled_cb), 0.3); // Debounce time 300 ms
hi1000 0:765cf978c3e5 163 }
hi1000 0:765cf978c3e5 164 }
hi1000 12:5cb359f981f3 165 //button1--
hi1000 12:5cb359f981f3 166 //button2
hi1000 12:5cb359f981f3 167 void button2_enabled_cb(void)
hi1000 12:5cb359f981f3 168 {
hi1000 12:5cb359f981f3 169 int button_status;
hi1000 12:5cb359f981f3 170 button_status = button2.read();
hi1000 12:5cb359f981f3 171 if (button_status == 0)
hi1000 12:5cb359f981f3 172 {
hi1000 12:5cb359f981f3 173 printf("button2 down\r\n");
hi1000 14:2e17a27f56b2 174 button_event_flags.set(BUTTON2_HOLD_EVENT);
hi1000 12:5cb359f981f3 175 }
hi1000 12:5cb359f981f3 176 else
hi1000 14:2e17a27f56b2 177 {
hi1000 12:5cb359f981f3 178 printf("button2 released\r\n");
hi1000 14:2e17a27f56b2 179 button_event_flags.set(BUTTON2_PRESSED_EVENT);
hi1000 14:2e17a27f56b2 180 }
hi1000 12:5cb359f981f3 181 button2_enabled = true;
hi1000 12:5cb359f981f3 182 }
hi1000 0:765cf978c3e5 183
hi1000 12:5cb359f981f3 184 // ISR handling button pressed event
hi1000 12:5cb359f981f3 185 void button2_onpressed_cb(void)
hi1000 12:5cb359f981f3 186 {
hi1000 12:5cb359f981f3 187 if (button2_enabled) { // Disabled while the button is bouncing
hi1000 12:5cb359f981f3 188 button2_enabled = false;
hi1000 12:5cb359f981f3 189 button2_pressed = true; // To be read by the main loop
hi1000 12:5cb359f981f3 190 button2_timeout.attach(callback(button2_enabled_cb), 0.3); // Debounce time 300 ms
hi1000 12:5cb359f981f3 191 }
hi1000 12:5cb359f981f3 192 }
hi1000 12:5cb359f981f3 193 //button2--
hi1000 12:5cb359f981f3 194 //button3
hi1000 12:5cb359f981f3 195 void button3_enabled_cb(void)
hi1000 12:5cb359f981f3 196 {
hi1000 12:5cb359f981f3 197 int button_status;
hi1000 12:5cb359f981f3 198 button_status = button3.read();
hi1000 12:5cb359f981f3 199 if (button_status == 0)
hi1000 12:5cb359f981f3 200 {
hi1000 12:5cb359f981f3 201 printf("button3 down\r\n");
hi1000 14:2e17a27f56b2 202 button_event_flags.set(BUTTON3_HOLD_EVENT);
hi1000 12:5cb359f981f3 203 }
hi1000 12:5cb359f981f3 204 else
hi1000 14:2e17a27f56b2 205 {
hi1000 12:5cb359f981f3 206 printf("button3 released\r\n");
hi1000 14:2e17a27f56b2 207 button_event_flags.set(BUTTON3_PRESSED_EVENT);
hi1000 14:2e17a27f56b2 208 }
hi1000 12:5cb359f981f3 209 button3_enabled = true;
hi1000 12:5cb359f981f3 210 }
hi1000 12:5cb359f981f3 211
hi1000 12:5cb359f981f3 212 // ISR handling button pressed event
hi1000 12:5cb359f981f3 213 void button3_onpressed_cb(void)
hi1000 12:5cb359f981f3 214 {
hi1000 12:5cb359f981f3 215 if (button3_enabled) { // Disabled while the button is bouncing
hi1000 12:5cb359f981f3 216 button3_enabled = false;
hi1000 12:5cb359f981f3 217 button3_pressed = true; // To be read by the main loop
hi1000 12:5cb359f981f3 218 button3_timeout.attach(callback(button3_enabled_cb), 0.3); // Debounce time 300 ms
hi1000 12:5cb359f981f3 219 }
hi1000 12:5cb359f981f3 220 }
hi1000 12:5cb359f981f3 221 //button3--
hi1000 12:5cb359f981f3 222 //button4
hi1000 12:5cb359f981f3 223 void button4_enabled_cb(void)
hi1000 12:5cb359f981f3 224 {
hi1000 12:5cb359f981f3 225 int button_status;
hi1000 12:5cb359f981f3 226 button_status = button4.read();
hi1000 12:5cb359f981f3 227 if (button_status == 0)
hi1000 12:5cb359f981f3 228 {
hi1000 12:5cb359f981f3 229 printf("button4 down\r\n");
hi1000 14:2e17a27f56b2 230 button_event_flags.set(BUTTON4_HOLD_EVENT);
hi1000 12:5cb359f981f3 231 }
hi1000 12:5cb359f981f3 232 else
hi1000 14:2e17a27f56b2 233 {
hi1000 12:5cb359f981f3 234 printf("button4 released\r\n");
hi1000 14:2e17a27f56b2 235 button_event_flags.set(BUTTON4_PRESSED_EVENT);
hi1000 14:2e17a27f56b2 236 }
hi1000 12:5cb359f981f3 237 button4_enabled = true;
hi1000 12:5cb359f981f3 238 }
hi1000 12:5cb359f981f3 239
hi1000 12:5cb359f981f3 240 // ISR handling button pressed event
hi1000 12:5cb359f981f3 241 void button4_onpressed_cb(void)
hi1000 12:5cb359f981f3 242 {
hi1000 12:5cb359f981f3 243 if (button4_enabled) { // Disabled while the button is bouncing
hi1000 12:5cb359f981f3 244 button4_enabled = false;
hi1000 12:5cb359f981f3 245 button4_pressed = true; // To be read by the main loop
hi1000 12:5cb359f981f3 246 button4_timeout.attach(callback(button4_enabled_cb), 0.3); // Debounce time 300 ms
hi1000 12:5cb359f981f3 247 }
hi1000 12:5cb359f981f3 248 }
hi1000 12:5cb359f981f3 249 //button4--
hi1000 8:6105ffbaf237 250 void can_rxthread()
hi1000 0:765cf978c3e5 251 {
hi1000 9:486f65124378 252 int loop;
hi1000 0:765cf978c3e5 253 while (true) {
hi1000 9:486f65124378 254 #if 1
hi1000 0:765cf978c3e5 255 if(can1.read(msg)) {
hi1000 0:765cf978c3e5 256 print_char();
hi1000 0:765cf978c3e5 257 printf("got message id=%d 0x%08x\r\n", msg.id, msg.id);
hi1000 0:765cf978c3e5 258 // b = *reinterpret_cast<int*>(msg.data);
hi1000 9:486f65124378 259 for (loop = 0; loop < msg.len; loop++)
hi1000 8:6105ffbaf237 260 {
hi1000 9:486f65124378 261 can_rx_data[loop] = msg.data[loop];
hi1000 8:6105ffbaf237 262 }
hi1000 8:6105ffbaf237 263
hi1000 9:486f65124378 264 printf("got data: length:%d\r\n", msg.len);
hi1000 9:486f65124378 265 for (loop = 0; loop < msg.len; loop++)
hi1000 9:486f65124378 266 {
hi1000 9:486f65124378 267 printf("data[%d]=%d\r\n", loop, can_rx_data[loop]);
hi1000 9:486f65124378 268 }
hi1000 14:2e17a27f56b2 269 // if(msg.id == 1337)
hi1000 14:2e17a27f56b2 270 {
hi1000 9:486f65124378 271 //only queue the message belongs to you
hi1000 9:486f65124378 272 CANMessage *can_message = can_mpool.alloc();
hi1000 9:486f65124378 273 memcpy((void *)can_message, (void *)&msg, sizeof(msg));
hi1000 9:486f65124378 274 if (!can_queue.full())
hi1000 9:486f65124378 275 can_queue.put(can_message);
hi1000 9:486f65124378 276 else
hi1000 9:486f65124378 277 {
hi1000 9:486f65124378 278 printf("message queue is full. \r\n");
hi1000 9:486f65124378 279 }
hi1000 0:765cf978c3e5 280 led2 = !led2;
hi1000 0:765cf978c3e5 281 }
hi1000 0:765cf978c3e5 282 }
hi1000 9:486f65124378 283 #endif
hi1000 0:765cf978c3e5 284 // wait(0.2);
hi1000 0:765cf978c3e5 285 }
hi1000 0:765cf978c3e5 286 }
hi1000 0:765cf978c3e5 287
hi1000 0:765cf978c3e5 288 int main()
hi1000 0:765cf978c3e5 289 {
hi1000 9:486f65124378 290 int loop = 0;
hi1000 9:486f65124378 291 int8_t ival;
hi1000 14:2e17a27f56b2 292 printf("\n\n*** RTOS starts ***\r\n");
hi1000 9:486f65124378 293
hi1000 9:486f65124378 294 // wait(1);
hi1000 14:2e17a27f56b2 295 ep.read((uint32_t)EEPROM_DEVICE_ADDRESS_ADDRESS,device_address);
hi1000 14:2e17a27f56b2 296 printf("EEPROM: read device address:%d 0x%08x\r\n", device_address, device_address);
hi1000 14:2e17a27f56b2 297 if ((device_address == 0) || (device_address == 0xFFFFFFFF))
hi1000 14:2e17a27f56b2 298 device_address = DEVICE_DEFAULT_ADDRESS;
hi1000 16:f4277e9b8612 299 device_type = (device_address & 0x00000700) >> 8;
hi1000 16:f4277e9b8612 300
hi1000 8:6105ffbaf237 301 #ifdef LCD_1621
hi1000 4:40bb33497de4 302 lcd.clear(); // clears display
hi1000 4:40bb33497de4 303 lcd.allsegson();
hi1000 5:4585215afd11 304
hi1000 4:40bb33497de4 305 // lcd.printf("ABCDEFGHI"); // Standard printf function, All ASCII characters will display
hi1000 5:4585215afd11 306 #endif
hi1000 9:486f65124378 307
hi1000 5:4585215afd11 308 #ifdef LCD_1602
hi1000 16:f4277e9b8612 309 // lcd.printf( 0, "Hello world!" ); // line# (0 or 1), string
hi1000 16:f4277e9b8612 310 // lcd.printf( 1, "pi = %.6f", 3.14159265 );
hi1000 16:f4277e9b8612 311 // lcd.putcxy(0x55, 5, 1);
hi1000 16:f4277e9b8612 312 // lcd.printf(5, 0, "UUU");
hi1000 16:f4277e9b8612 313 // lcd.printf(0, 0, "pressed!" );
hi1000 9:486f65124378 314 #endif
hi1000 11:8702316d7fc8 315
hi1000 12:5cb359f981f3 316 input1.mode(PullUp);
hi1000 12:5cb359f981f3 317 input2.mode(PullUp);
hi1000 13:9f581a090e53 318
hi1000 1:eb499e2a1b9b 319 // flashIAP.init();
hi1000 1:eb499e2a1b9b 320 // printf("Flash start address: 0x%08x Flash Size: %d\r\n", flashIAP.get_flash_start(), flashIAP.get_flash_size());
hi1000 0:765cf978c3e5 321 // can1.reset();
hi1000 0:765cf978c3e5 322 // can2.reset();
hi1000 16:f4277e9b8612 323 printf("device_address =0x%08x \r\n", (device_address<<18));
hi1000 2:61a0169765bf 324 can1.frequency(100000);
hi1000 14:2e17a27f56b2 325 can1.filter((device_address<<18), 0x1FFC0000, CANExtended, init_filter_handle); // 0x1FFC0000 to filter the last 18bits 0-17
hi1000 16:f4277e9b8612 326 device_address = (device_address & 0x000000FF);
hi1000 14:2e17a27f56b2 327 //only support one filter
hi1000 14:2e17a27f56b2 328 // can1.filter(broadcast_id, 0x1FFC0000, CANExtended, broadcast_filter_handle); // the broadcast id
hi1000 0:765cf978c3e5 329 // can2.frequency(100000);
hi1000 12:5cb359f981f3 330 //button0.mode(PullUp); // Activate pull-up
hi1000 13:9f581a090e53 331 can_receivethread.start(can_rxthread);
hi1000 13:9f581a090e53 332 can_handlethread.start(analyzePayload);
hi1000 9:486f65124378 333
hi1000 12:5cb359f981f3 334 button0.fall(callback(button0_onpressed_cb)); // Attach ISR to handle button press event
hi1000 12:5cb359f981f3 335 button0.rise(callback(button0_onpressed_cb)); // Attach ISR to handle button press event
hi1000 2:61a0169765bf 336 button1.fall(callback(button1_onpressed_cb)); // Attach ISR to handle button press event
hi1000 12:5cb359f981f3 337 button1.rise(callback(button1_onpressed_cb)); // Attach ISR to handle button press event
hi1000 12:5cb359f981f3 338 button2.fall(callback(button2_onpressed_cb)); // Attach ISR to handle button press event
hi1000 12:5cb359f981f3 339 button2.rise(callback(button2_onpressed_cb)); // Attach ISR to handle button press event
hi1000 12:5cb359f981f3 340 button3.fall(callback(button3_onpressed_cb)); // Attach ISR to handle button press event
hi1000 12:5cb359f981f3 341 button3.rise(callback(button3_onpressed_cb)); // Attach ISR to handle button press event
hi1000 12:5cb359f981f3 342 button4.fall(callback(button4_onpressed_cb)); // Attach ISR to handle button press event
hi1000 12:5cb359f981f3 343 button4.rise(callback(button4_onpressed_cb)); // Attach ISR to handle button press event
hi1000 11:8702316d7fc8 344 // eeprom_test();
hi1000 0:765cf978c3e5 345
hi1000 11:8702316d7fc8 346 #if 1
hi1000 11:8702316d7fc8 347 // scaleCalibration();
hi1000 11:8702316d7fc8 348 init_scale();
hi1000 11:8702316d7fc8 349 scale_thread.start(scale_reading);
hi1000 14:2e17a27f56b2 350 mainmenu_thread.start(main_menu);
hi1000 14:2e17a27f56b2 351
hi1000 11:8702316d7fc8 352 #endif
hi1000 14:2e17a27f56b2 353 while(1) {
hi1000 14:2e17a27f56b2 354 wait(1);
hi1000 14:2e17a27f56b2 355 }
hi1000 14:2e17a27f56b2 356
hi1000 14:2e17a27f56b2 357 #if 0
hi1000 0:765cf978c3e5 358 int idx = 0; // Just for printf below
hi1000 9:486f65124378 359 can_tx_data[0] = 0;
hi1000 0:765cf978c3e5 360 while(1) {
hi1000 12:5cb359f981f3 361 if (button0_pressed) { // Set when button is pressed
hi1000 9:486f65124378 362 #if 0
hi1000 1:eb499e2a1b9b 363 printf("scale value %f. \r\n", hx711.getGram());
hi1000 9:486f65124378 364 #endif
hi1000 9:486f65124378 365 can_tx_data[1] = can_tx_data[0]+1;
hi1000 9:486f65124378 366 can_tx_data[2] = can_tx_data[1]+1;
hi1000 9:486f65124378 367 can_tx_data[3] = can_tx_data[2]+1;
hi1000 9:486f65124378 368 can_tx_data[4] = can_tx_data[3]+1;
hi1000 9:486f65124378 369 can_tx_data[5] = can_tx_data[4]+1;
hi1000 9:486f65124378 370 can_tx_data[6] = can_tx_data[5]+1;
hi1000 9:486f65124378 371 can_tx_data[7] = can_tx_data[6]+1;
hi1000 12:5cb359f981f3 372 button0_pressed = false;
hi1000 2:61a0169765bf 373 printf("Button pressed %d\r\n", idx++);
hi1000 9:486f65124378 374 printf("ID=%d data[0]=%d. \r\n", init_id + idx%10, can_tx_data[0]);
hi1000 9:486f65124378 375 #ifdef LCD_1602
hi1000 9:486f65124378 376 lcd.printf(0, 0, "%d ", idx ); // line# (0 or 1), string
hi1000 9:486f65124378 377 #endif
hi1000 9:486f65124378 378 can1.write(CANMessage((init_id + idx%10), reinterpret_cast<char*>(can_tx_data), 8));
hi1000 0:765cf978c3e5 379 led1 = !led1;
hi1000 9:486f65124378 380 can_tx_data[0]++;
hi1000 0:765cf978c3e5 381 }
hi1000 0:765cf978c3e5 382 }
hi1000 14:2e17a27f56b2 383 #endif
hi1000 9:486f65124378 384
hi1000 0:765cf978c3e5 385 }