Feng Hong / Mbed OS Nucleo_rtos_basic
Committer:
hi1000
Date:
Sat Jun 08 09:16:21 2019 +0000
Revision:
14:2e17a27f56b2
Parent:
13:9f581a090e53
Child:
16:f4277e9b8612
Add some tare and device ID menu

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