Feng Hong / Mbed OS Nucleo_yoda2_v2
Committer:
hi1000
Date:
Sat Feb 22 05:10:09 2020 +0000
Revision:
21:acd050bf2f28
Parent:
20:ec9d4f6a16ac
old

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 18:e6ed582f7022 7 #include "yoda2.h"
hi1000 19:0356e54240cc 8 #include "TextLCD.h"
hi1000 20:ec9d4f6a16ac 9 #include "DS3231.h"
hi1000 20:ec9d4f6a16ac 10
hi1000 20:ec9d4f6a16ac 11
hi1000 20:ec9d4f6a16ac 12 DigitalOut relay4(RELAY_4);
hi1000 20:ec9d4f6a16ac 13 DigitalOut relay3(RELAY_3);
hi1000 20:ec9d4f6a16ac 14 DigitalOut relay2(RELAY_2);
hi1000 20:ec9d4f6a16ac 15 DigitalOut relay1(RELAY_1);
hi1000 20:ec9d4f6a16ac 16 DigitalIn din1(DIN1);
hi1000 20:ec9d4f6a16ac 17 DigitalIn din2(DIN2);
hi1000 20:ec9d4f6a16ac 18 DigitalIn din3(DIN3);
hi1000 20:ec9d4f6a16ac 19 DigitalIn din4(DIN4);
hi1000 20:ec9d4f6a16ac 20 DigitalIn din5(DIN5);
hi1000 20:ec9d4f6a16ac 21 DigitalIn din6(DIN6);
hi1000 20:ec9d4f6a16ac 22 DigitalIn din7(DIN7);
hi1000 20:ec9d4f6a16ac 23 DigitalIn din8(DIN8);
hi1000 20:ec9d4f6a16ac 24
hi1000 20:ec9d4f6a16ac 25 extern int moveMotor(int motornumber, int distance_mm, bool direction, bool freemove, bool gobackhome);
hi1000 20:ec9d4f6a16ac 26 extern int moveMotor1(int distance_mm, bool direction, bool freemove, bool gobackhome);
hi1000 20:ec9d4f6a16ac 27 extern int moveMotor2(int distance_mm, bool direction, bool freemove, bool gobackhome);
hi1000 20:ec9d4f6a16ac 28 extern int moveMotor3(int distance_mm, bool direction, bool freemove, bool gobackhome);
hi1000 20:ec9d4f6a16ac 29 extern int moveMotor3Until(bool direction, DigitalIn sensorpin);
hi1000 20:ec9d4f6a16ac 30 extern DigitalOut motor3_pul;
hi1000 20:ec9d4f6a16ac 31 extern DigitalOut motor3_en;
hi1000 20:ec9d4f6a16ac 32 extern DigitalOut motor3_dir;
hi1000 9:486f65124378 33
hi1000 14:2e17a27f56b2 34 EventFlags button_event_flags;
hi1000 19:0356e54240cc 35 EEPROM ep(SDA,SCL,EEPROM_ADDR,EEPROM::T24C32);
hi1000 19:0356e54240cc 36 extern void eeprom_test(void);
hi1000 19:0356e54240cc 37 #ifdef YODA2
hi1000 21:acd050bf2f28 38 Serial uart1(PC_4, PC_5); // tx, rx
hi1000 19:0356e54240cc 39 // I2C Communication
hi1000 20:ec9d4f6a16ac 40 I2C i2c_lcd(LCD_SDA, LCD_SCL); // SDA, SCL
hi1000 19:0356e54240cc 41 TextLCD_I2C_N lcd(&i2c_lcd, ST7032_SA, TextLCD::LCD16x2, NC, TextLCD::ST7032_3V3);
hi1000 19:0356e54240cc 42 #endif
hi1000 19:0356e54240cc 43 #if 1
hi1000 19:0356e54240cc 44 int current_weight;
hi1000 19:0356e54240cc 45 //EEPROM ep(SDA,SCL,EEPROM_ADDR,EEPROM::T24C256);
hi1000 19:0356e54240cc 46 int device_address = DEVICE_DEFAULT_ADDRESS; // address 11 bits: last 8 bits is device_address
hi1000 19:0356e54240cc 47 int device_type; //address 11 bits: first 3 bits is device_type
hi1000 19:0356e54240cc 48 int init_id = 0x00300000; // first 11 bit is the address
hi1000 19:0356e54240cc 49 int init_filter_handle, broadcast_filter_handle;
hi1000 19:0356e54240cc 50 int broadcast_id = 0x1ffC0000;
hi1000 19:0356e54240cc 51 #endif
hi1000 19:0356e54240cc 52
hi1000 19:0356e54240cc 53
hi1000 19:0356e54240cc 54 #if 1
hi1000 19:0356e54240cc 55
hi1000 14:2e17a27f56b2 56 EventFlags LCD_update_flags;
hi1000 14:2e17a27f56b2 57 extern void main_menu();
hi1000 7:e0c7e624c5fa 58 extern void analyzePayload();
hi1000 19:0356e54240cc 59 extern Device_Type_d device_type_v;
hi1000 19:0356e54240cc 60 extern data_field_d can_txdata_frame;
hi1000 19:0356e54240cc 61 extern CANMessage tx_message;
hi1000 11:8702316d7fc8 62 #if 1
hi1000 11:8702316d7fc8 63 #ifdef STM32F207xx
hi1000 11:8702316d7fc8 64 HX711 hx711(PB_11, PB_10);// data, clk
hi1000 11:8702316d7fc8 65 #endif
hi1000 11:8702316d7fc8 66
hi1000 11:8702316d7fc8 67 #ifdef STM32F303xE
hi1000 11:8702316d7fc8 68 //HX711 hx711(D8, D9);// data, clk
hi1000 19:0356e54240cc 69 #ifdef OWN_SOLDER_BOARD
hi1000 11:8702316d7fc8 70 HX711 hx711(PA_14, PA_15);
hi1000 11:8702316d7fc8 71 #endif
hi1000 19:0356e54240cc 72 #ifdef YODA2
hi1000 20:ec9d4f6a16ac 73 HX711 hx711(SCALE_SDA, SCALE_SCL);
hi1000 19:0356e54240cc 74 #endif
hi1000 19:0356e54240cc 75 #endif
hi1000 18:e6ed582f7022 76 extern void scaleCalibration(bool release_led);
hi1000 11:8702316d7fc8 77 extern void init_scale();
hi1000 11:8702316d7fc8 78 Thread scale_thread;
hi1000 11:8702316d7fc8 79 extern void scale_reading();
hi1000 9:486f65124378 80 #endif
hi1000 8:6105ffbaf237 81 unsigned char rx_buffer[8], tx_buffer[8];
hi1000 7:e0c7e624c5fa 82 unsigned char rx_length, tx_length;
hi1000 0:765cf978c3e5 83
hi1000 19:0356e54240cc 84 //#define LCD_1602
hi1000 9:486f65124378 85 #ifdef STM32F207xx
hi1000 5:4585215afd11 86 SB1602E lcd( PB_9, PB_8 ); // SDA, SCL
hi1000 0:765cf978c3e5 87 CAN can1(PD_0, PD_1);
hi1000 0:765cf978c3e5 88 CAN can2(PB_5, PB_6);
hi1000 1:eb499e2a1b9b 89 DigitalOut led1(LED1);
hi1000 1:eb499e2a1b9b 90 DigitalOut led2(LED2);
hi1000 1:eb499e2a1b9b 91 //FlashIAP flashIAP;
hi1000 1:eb499e2a1b9b 92
hi1000 5:4585215afd11 93 //#define LCD_1621
hi1000 5:4585215afd11 94 //digitLCD lcd(PA_5,PA_4,PB_5); // WO, CS, DATA
hi1000 9:486f65124378 95 #endif
hi1000 9:486f65124378 96 #ifdef STM32F303xE
hi1000 19:0356e54240cc 97
hi1000 19:0356e54240cc 98 #ifdef LCD_1602
hi1000 9:486f65124378 99 SB1602E lcd(D14, D15 ); // SDA, SCL
hi1000 19:0356e54240cc 100 #endif
hi1000 20:ec9d4f6a16ac 101 CAN can1(CAN_RD, CAN_TD); // RD, TD
hi1000 9:486f65124378 102 DigitalOut led1(LED1); // only one LED PA_5
hi1000 9:486f65124378 103 DigitalOut led2(LED2); // only one LED PA_5
hi1000 9:486f65124378 104 #endif
hi1000 7:e0c7e624c5fa 105
hi1000 19:0356e54240cc 106 #if 0
hi1000 12:5cb359f981f3 107 DigitalOut output1(PC_3);
hi1000 12:5cb359f981f3 108 DigitalOut output2(PC_2);
hi1000 12:5cb359f981f3 109 DigitalOut output3(PB_7);
hi1000 12:5cb359f981f3 110 DigitalIn input1(PC_6);
hi1000 12:5cb359f981f3 111 DigitalIn input2(PC_8);
hi1000 19:0356e54240cc 112 #endif
hi1000 19:0356e54240cc 113
hi1000 1:eb499e2a1b9b 114
hi1000 9:486f65124378 115 uint8_t can_tx_data[8];
hi1000 9:486f65124378 116 uint8_t can_rx_data[8];
hi1000 19:0356e54240cc 117 #endif
hi1000 0:765cf978c3e5 118 void print_char(char c = '*')
hi1000 0:765cf978c3e5 119 {
hi1000 0:765cf978c3e5 120 printf("%c\r\n", c);
hi1000 0:765cf978c3e5 121 fflush(stdout);
hi1000 0:765cf978c3e5 122 }
hi1000 0:765cf978c3e5 123
hi1000 19:0356e54240cc 124 #if 1
hi1000 8:6105ffbaf237 125 Thread can_receivethread;
hi1000 8:6105ffbaf237 126 Thread can_handlethread;
hi1000 14:2e17a27f56b2 127 Thread mainmenu_thread;
hi1000 19:0356e54240cc 128 bool can_register_success = false;
hi1000 0:765cf978c3e5 129 CANMessage msg;
hi1000 8:6105ffbaf237 130 MemoryPool<CANMessage, 16> can_mpool;
hi1000 8:6105ffbaf237 131 Queue<CANMessage, 16> can_queue;
hi1000 19:0356e54240cc 132 #endif
hi1000 12:5cb359f981f3 133 InterruptIn button0(USER_BUTTON);
hi1000 12:5cb359f981f3 134 volatile bool button0_pressed = false; // Used in the main loop
hi1000 12:5cb359f981f3 135 volatile bool button0_enabled = true; // Used for debouncing
hi1000 12:5cb359f981f3 136 Timeout button0_timeout; // Used for debouncing
hi1000 19:0356e54240cc 137 InterruptIn button1(BUTTON1);
hi1000 0:765cf978c3e5 138 volatile bool button1_pressed = false; // Used in the main loop
hi1000 0:765cf978c3e5 139 volatile bool button1_enabled = true; // Used for debouncing
hi1000 0:765cf978c3e5 140 Timeout button1_timeout; // Used for debouncing
hi1000 19:0356e54240cc 141 InterruptIn button2(BUTTON2);
hi1000 12:5cb359f981f3 142 volatile bool button2_pressed = false; // Used in the main loop
hi1000 12:5cb359f981f3 143 volatile bool button2_enabled = true; // Used for debouncing
hi1000 12:5cb359f981f3 144 Timeout button2_timeout; // Used for debouncing
hi1000 19:0356e54240cc 145 InterruptIn button3(BUTTON3);
hi1000 12:5cb359f981f3 146 volatile bool button3_pressed = false; // Used in the main loop
hi1000 12:5cb359f981f3 147 volatile bool button3_enabled = true; // Used for debouncing
hi1000 12:5cb359f981f3 148 Timeout button3_timeout; // Used for debouncing
hi1000 19:0356e54240cc 149 InterruptIn button4(BUTTON4);
hi1000 12:5cb359f981f3 150 volatile bool button4_pressed = false; // Used in the main loop
hi1000 12:5cb359f981f3 151 volatile bool button4_enabled = true; // Used for debouncing
hi1000 12:5cb359f981f3 152 Timeout button4_timeout; // Used for debouncing
hi1000 12:5cb359f981f3 153
hi1000 0:765cf978c3e5 154
hi1000 0:765cf978c3e5 155 // Enables button when bouncing is over
hi1000 12:5cb359f981f3 156 //button0
hi1000 12:5cb359f981f3 157 void button0_enabled_cb(void)
hi1000 12:5cb359f981f3 158 {
hi1000 12:5cb359f981f3 159 int button_status;
hi1000 12:5cb359f981f3 160 button_status = button0.read();
hi1000 12:5cb359f981f3 161 if (button_status == 0)
hi1000 12:5cb359f981f3 162 {
hi1000 12:5cb359f981f3 163 printf("button0 down\r\n");
hi1000 20:ec9d4f6a16ac 164 // scaleCalibration(true);
hi1000 20:ec9d4f6a16ac 165 moveMotor3(100, true, true, false);
hi1000 14:2e17a27f56b2 166 button_status = button0.read();
hi1000 14:2e17a27f56b2 167 if (button_status == 0)
hi1000 14:2e17a27f56b2 168 {
hi1000 14:2e17a27f56b2 169 printf("button0 hold\r\n");
hi1000 14:2e17a27f56b2 170 }
hi1000 14:2e17a27f56b2 171 else
hi1000 14:2e17a27f56b2 172 {
hi1000 14:2e17a27f56b2 173 printf("button0 press hold and release\r\n");
hi1000 14:2e17a27f56b2 174 }
hi1000 12:5cb359f981f3 175 }
hi1000 12:5cb359f981f3 176 else
hi1000 12:5cb359f981f3 177 printf("button0 released\r\n");
hi1000 12:5cb359f981f3 178 button0_enabled = true;
hi1000 12:5cb359f981f3 179 }
hi1000 12:5cb359f981f3 180
hi1000 12:5cb359f981f3 181 // ISR handling button pressed event
hi1000 12:5cb359f981f3 182 void button0_onpressed_cb(void)
hi1000 12:5cb359f981f3 183 {
hi1000 12:5cb359f981f3 184 if (button0_enabled) { // Disabled while the button is bouncing
hi1000 12:5cb359f981f3 185 button0_enabled = false;
hi1000 12:5cb359f981f3 186 button0_pressed = true; // To be read by the main loop
hi1000 12:5cb359f981f3 187 button0_timeout.attach(callback(button0_enabled_cb), 0.3); // Debounce time 300 ms
hi1000 12:5cb359f981f3 188 }
hi1000 12:5cb359f981f3 189 }
hi1000 12:5cb359f981f3 190 //button0--
hi1000 12:5cb359f981f3 191 //button1
hi1000 0:765cf978c3e5 192 void button1_enabled_cb(void)
hi1000 0:765cf978c3e5 193 {
hi1000 12:5cb359f981f3 194 int button_status;
hi1000 12:5cb359f981f3 195 button_status = button1.read();
hi1000 12:5cb359f981f3 196 if (button_status == 0)
hi1000 12:5cb359f981f3 197 {
hi1000 12:5cb359f981f3 198 printf("button1 down\r\n");
hi1000 14:2e17a27f56b2 199 button_event_flags.set(BUTTON1_HOLD_EVENT);
hi1000 12:5cb359f981f3 200 }
hi1000 12:5cb359f981f3 201 else
hi1000 14:2e17a27f56b2 202 {
hi1000 12:5cb359f981f3 203 printf("button1 released\r\n");
hi1000 14:2e17a27f56b2 204 button_event_flags.set(BUTTON1_PRESSED_EVENT);
hi1000 14:2e17a27f56b2 205 }
hi1000 0:765cf978c3e5 206 button1_enabled = true;
hi1000 0:765cf978c3e5 207 }
hi1000 0:765cf978c3e5 208
hi1000 0:765cf978c3e5 209 // ISR handling button pressed event
hi1000 0:765cf978c3e5 210 void button1_onpressed_cb(void)
hi1000 0:765cf978c3e5 211 {
hi1000 0:765cf978c3e5 212 if (button1_enabled) { // Disabled while the button is bouncing
hi1000 0:765cf978c3e5 213 button1_enabled = false;
hi1000 0:765cf978c3e5 214 button1_pressed = true; // To be read by the main loop
hi1000 0:765cf978c3e5 215 button1_timeout.attach(callback(button1_enabled_cb), 0.3); // Debounce time 300 ms
hi1000 0:765cf978c3e5 216 }
hi1000 0:765cf978c3e5 217 }
hi1000 12:5cb359f981f3 218 //button1--
hi1000 12:5cb359f981f3 219 //button2
hi1000 12:5cb359f981f3 220 void button2_enabled_cb(void)
hi1000 12:5cb359f981f3 221 {
hi1000 12:5cb359f981f3 222 int button_status;
hi1000 12:5cb359f981f3 223 button_status = button2.read();
hi1000 12:5cb359f981f3 224 if (button_status == 0)
hi1000 12:5cb359f981f3 225 {
hi1000 12:5cb359f981f3 226 printf("button2 down\r\n");
hi1000 14:2e17a27f56b2 227 button_event_flags.set(BUTTON2_HOLD_EVENT);
hi1000 12:5cb359f981f3 228 }
hi1000 12:5cb359f981f3 229 else
hi1000 14:2e17a27f56b2 230 {
hi1000 12:5cb359f981f3 231 printf("button2 released\r\n");
hi1000 14:2e17a27f56b2 232 button_event_flags.set(BUTTON2_PRESSED_EVENT);
hi1000 14:2e17a27f56b2 233 }
hi1000 12:5cb359f981f3 234 button2_enabled = true;
hi1000 12:5cb359f981f3 235 }
hi1000 0:765cf978c3e5 236
hi1000 12:5cb359f981f3 237 // ISR handling button pressed event
hi1000 12:5cb359f981f3 238 void button2_onpressed_cb(void)
hi1000 12:5cb359f981f3 239 {
hi1000 12:5cb359f981f3 240 if (button2_enabled) { // Disabled while the button is bouncing
hi1000 12:5cb359f981f3 241 button2_enabled = false;
hi1000 12:5cb359f981f3 242 button2_pressed = true; // To be read by the main loop
hi1000 12:5cb359f981f3 243 button2_timeout.attach(callback(button2_enabled_cb), 0.3); // Debounce time 300 ms
hi1000 12:5cb359f981f3 244 }
hi1000 12:5cb359f981f3 245 }
hi1000 12:5cb359f981f3 246 //button2--
hi1000 12:5cb359f981f3 247 //button3
hi1000 12:5cb359f981f3 248 void button3_enabled_cb(void)
hi1000 12:5cb359f981f3 249 {
hi1000 12:5cb359f981f3 250 int button_status;
hi1000 12:5cb359f981f3 251 button_status = button3.read();
hi1000 12:5cb359f981f3 252 if (button_status == 0)
hi1000 12:5cb359f981f3 253 {
hi1000 12:5cb359f981f3 254 printf("button3 down\r\n");
hi1000 14:2e17a27f56b2 255 button_event_flags.set(BUTTON3_HOLD_EVENT);
hi1000 12:5cb359f981f3 256 }
hi1000 12:5cb359f981f3 257 else
hi1000 14:2e17a27f56b2 258 {
hi1000 12:5cb359f981f3 259 printf("button3 released\r\n");
hi1000 14:2e17a27f56b2 260 button_event_flags.set(BUTTON3_PRESSED_EVENT);
hi1000 14:2e17a27f56b2 261 }
hi1000 12:5cb359f981f3 262 button3_enabled = true;
hi1000 12:5cb359f981f3 263 }
hi1000 12:5cb359f981f3 264
hi1000 12:5cb359f981f3 265 // ISR handling button pressed event
hi1000 12:5cb359f981f3 266 void button3_onpressed_cb(void)
hi1000 12:5cb359f981f3 267 {
hi1000 12:5cb359f981f3 268 if (button3_enabled) { // Disabled while the button is bouncing
hi1000 12:5cb359f981f3 269 button3_enabled = false;
hi1000 12:5cb359f981f3 270 button3_pressed = true; // To be read by the main loop
hi1000 12:5cb359f981f3 271 button3_timeout.attach(callback(button3_enabled_cb), 0.3); // Debounce time 300 ms
hi1000 12:5cb359f981f3 272 }
hi1000 12:5cb359f981f3 273 }
hi1000 12:5cb359f981f3 274 //button3--
hi1000 12:5cb359f981f3 275 //button4
hi1000 12:5cb359f981f3 276 void button4_enabled_cb(void)
hi1000 12:5cb359f981f3 277 {
hi1000 12:5cb359f981f3 278 int button_status;
hi1000 12:5cb359f981f3 279 button_status = button4.read();
hi1000 12:5cb359f981f3 280 if (button_status == 0)
hi1000 12:5cb359f981f3 281 {
hi1000 12:5cb359f981f3 282 printf("button4 down\r\n");
hi1000 14:2e17a27f56b2 283 button_event_flags.set(BUTTON4_HOLD_EVENT);
hi1000 12:5cb359f981f3 284 }
hi1000 12:5cb359f981f3 285 else
hi1000 14:2e17a27f56b2 286 {
hi1000 12:5cb359f981f3 287 printf("button4 released\r\n");
hi1000 14:2e17a27f56b2 288 button_event_flags.set(BUTTON4_PRESSED_EVENT);
hi1000 14:2e17a27f56b2 289 }
hi1000 12:5cb359f981f3 290 button4_enabled = true;
hi1000 12:5cb359f981f3 291 }
hi1000 12:5cb359f981f3 292
hi1000 12:5cb359f981f3 293 // ISR handling button pressed event
hi1000 12:5cb359f981f3 294 void button4_onpressed_cb(void)
hi1000 12:5cb359f981f3 295 {
hi1000 12:5cb359f981f3 296 if (button4_enabled) { // Disabled while the button is bouncing
hi1000 12:5cb359f981f3 297 button4_enabled = false;
hi1000 12:5cb359f981f3 298 button4_pressed = true; // To be read by the main loop
hi1000 12:5cb359f981f3 299 button4_timeout.attach(callback(button4_enabled_cb), 0.3); // Debounce time 300 ms
hi1000 12:5cb359f981f3 300 }
hi1000 12:5cb359f981f3 301 }
hi1000 12:5cb359f981f3 302 //button4--
hi1000 19:0356e54240cc 303 #if 1
hi1000 17:faa4d4976d22 304 void can_sendData(int can_id, uint8_t *tx_data, int length)
hi1000 17:faa4d4976d22 305 {
hi1000 17:faa4d4976d22 306 CANMessage txmsg;
hi1000 17:faa4d4976d22 307
hi1000 17:faa4d4976d22 308 txmsg.format = CANExtended;
hi1000 17:faa4d4976d22 309 txmsg.id = can_id;
hi1000 17:faa4d4976d22 310 txmsg.len = length;
hi1000 17:faa4d4976d22 311 txmsg.data[0] = tx_data[0];
hi1000 17:faa4d4976d22 312 txmsg.data[1] = tx_data[1];
hi1000 17:faa4d4976d22 313 txmsg.data[2] = tx_data[2];
hi1000 17:faa4d4976d22 314 txmsg.data[3] = tx_data[3];
hi1000 17:faa4d4976d22 315 txmsg.data[4] = tx_data[4];
hi1000 17:faa4d4976d22 316 txmsg.data[5] = tx_data[5];
hi1000 17:faa4d4976d22 317 txmsg.data[6] = tx_data[6];
hi1000 17:faa4d4976d22 318 txmsg.data[7] = tx_data[7];
hi1000 17:faa4d4976d22 319
hi1000 19:0356e54240cc 320 // printf("can_sendData can_id=0x%08x \r\n", can_id);
hi1000 17:faa4d4976d22 321 can1.write(txmsg);
hi1000 17:faa4d4976d22 322 }
hi1000 17:faa4d4976d22 323
hi1000 8:6105ffbaf237 324 void can_rxthread()
hi1000 0:765cf978c3e5 325 {
hi1000 9:486f65124378 326 int loop;
hi1000 0:765cf978c3e5 327 while (true) {
hi1000 9:486f65124378 328 #if 1
hi1000 0:765cf978c3e5 329 if(can1.read(msg)) {
hi1000 0:765cf978c3e5 330 print_char();
hi1000 0:765cf978c3e5 331 printf("got message id=%d 0x%08x\r\n", msg.id, msg.id);
hi1000 0:765cf978c3e5 332 // b = *reinterpret_cast<int*>(msg.data);
hi1000 9:486f65124378 333 for (loop = 0; loop < msg.len; loop++)
hi1000 8:6105ffbaf237 334 {
hi1000 9:486f65124378 335 can_rx_data[loop] = msg.data[loop];
hi1000 8:6105ffbaf237 336 }
hi1000 8:6105ffbaf237 337
hi1000 9:486f65124378 338 printf("got data: length:%d\r\n", msg.len);
hi1000 9:486f65124378 339 for (loop = 0; loop < msg.len; loop++)
hi1000 9:486f65124378 340 {
hi1000 9:486f65124378 341 printf("data[%d]=%d\r\n", loop, can_rx_data[loop]);
hi1000 9:486f65124378 342 }
hi1000 14:2e17a27f56b2 343 // if(msg.id == 1337)
hi1000 14:2e17a27f56b2 344 {
hi1000 9:486f65124378 345 //only queue the message belongs to you
hi1000 9:486f65124378 346 CANMessage *can_message = can_mpool.alloc();
hi1000 9:486f65124378 347 memcpy((void *)can_message, (void *)&msg, sizeof(msg));
hi1000 9:486f65124378 348 if (!can_queue.full())
hi1000 9:486f65124378 349 can_queue.put(can_message);
hi1000 9:486f65124378 350 else
hi1000 9:486f65124378 351 {
hi1000 9:486f65124378 352 printf("message queue is full. \r\n");
hi1000 9:486f65124378 353 }
hi1000 0:765cf978c3e5 354 led2 = !led2;
hi1000 0:765cf978c3e5 355 }
hi1000 0:765cf978c3e5 356 }
hi1000 9:486f65124378 357 #endif
hi1000 20:ec9d4f6a16ac 358 wait(0.2);
hi1000 0:765cf978c3e5 359 }
hi1000 0:765cf978c3e5 360 }
hi1000 19:0356e54240cc 361 #endif
hi1000 19:0356e54240cc 362 void i2c_scanner(PinName sda, PinName scl)
hi1000 19:0356e54240cc 363 {
hi1000 19:0356e54240cc 364 I2C i2c(sda, scl);
hi1000 19:0356e54240cc 365
hi1000 19:0356e54240cc 366 int error, address;
hi1000 19:0356e54240cc 367 int nDevices;
hi1000 19:0356e54240cc 368
hi1000 19:0356e54240cc 369 i2c.frequency(100000);
hi1000 19:0356e54240cc 370 printf("i2c_scanner sda=%d scl=%d \r\n", (int)sda, (int)scl);
hi1000 19:0356e54240cc 371 printf("Scanning...\r\n");
hi1000 19:0356e54240cc 372
hi1000 19:0356e54240cc 373 nDevices = 0;
hi1000 19:0356e54240cc 374
hi1000 19:0356e54240cc 375 for(address = 0; address < 127; address++ )
hi1000 19:0356e54240cc 376 {
hi1000 19:0356e54240cc 377 i2c.start();
hi1000 19:0356e54240cc 378 // error = i2c.write(address << 1); //We shift it left because mbed takes in 8 bit addreses
hi1000 19:0356e54240cc 379 error = i2c.write(address << 1, "1", 1, false);
hi1000 19:0356e54240cc 380 i2c.stop();
hi1000 19:0356e54240cc 381 if (error == 0)
hi1000 19:0356e54240cc 382 {
hi1000 19:0356e54240cc 383 printf("I2C device found at address 7bit:0x%X (8bit:0x%X)\r\n", address, (address<<1)); //Returns 8-bit addres
hi1000 19:0356e54240cc 384 nDevices++;
hi1000 19:0356e54240cc 385 }
hi1000 19:0356e54240cc 386 }
hi1000 19:0356e54240cc 387 if (nDevices == 0)
hi1000 19:0356e54240cc 388 printf("No I2C devices found\r\n");
hi1000 19:0356e54240cc 389 else
hi1000 19:0356e54240cc 390 printf("\r\ndone\r\n");
hi1000 19:0356e54240cc 391 }
hi1000 0:765cf978c3e5 392 int main()
hi1000 0:765cf978c3e5 393 {
hi1000 9:486f65124378 394 int loop = 0;
hi1000 9:486f65124378 395 int8_t ival;
hi1000 19:0356e54240cc 396 unsigned int can_id;
hi1000 20:ec9d4f6a16ac 397 int distance = 0;
hi1000 20:ec9d4f6a16ac 398 #if 0
hi1000 20:ec9d4f6a16ac 399 int hour;
hi1000 20:ec9d4f6a16ac 400 int minute;
hi1000 20:ec9d4f6a16ac 401 int second;
hi1000 20:ec9d4f6a16ac 402
hi1000 20:ec9d4f6a16ac 403 int dayOfWeek;
hi1000 20:ec9d4f6a16ac 404 int date;
hi1000 20:ec9d4f6a16ac 405 int month;
hi1000 20:ec9d4f6a16ac 406 int year;
hi1000 20:ec9d4f6a16ac 407 DS3231 rtc_test(SDA, SCL);
hi1000 20:ec9d4f6a16ac 408 // DS3231 rtc_test(PF_0, PF_1);
hi1000 21:acd050bf2f28 409 // printf("\r\n\nDS3231 Library test program\r\nremi cormier 2012\r\n\n");
hi1000 20:ec9d4f6a16ac 410
hi1000 20:ec9d4f6a16ac 411 rtc_test.setI2Cfrequency(400000);
hi1000 20:ec9d4f6a16ac 412
hi1000 20:ec9d4f6a16ac 413 //rtc_test.writeRegister(DS3231_Aging_Offset,0); // uncomment to set Aging Offset 1LSB = approx. 0.1 ppm according from datasheet = 0.05 ppm @ 21 °C from my measurments
hi1000 20:ec9d4f6a16ac 414
hi1000 20:ec9d4f6a16ac 415 rtc_test.convertTemperature();
hi1000 20:ec9d4f6a16ac 416
hi1000 20:ec9d4f6a16ac 417 int reg=rtc_test.readRegister(DS3231_Aging_Offset);
hi1000 20:ec9d4f6a16ac 418 if (reg>127)
hi1000 20:ec9d4f6a16ac 419 {reg=reg-256;}
hi1000 20:ec9d4f6a16ac 420 printf("Aging offset : %i\r\n",reg);
hi1000 20:ec9d4f6a16ac 421
hi1000 20:ec9d4f6a16ac 422 printf("OSF flag : %i",rtc_test.OSF());
hi1000 20:ec9d4f6a16ac 423 printf("\r\n");
hi1000 20:ec9d4f6a16ac 424
hi1000 20:ec9d4f6a16ac 425 rtc_test.readDate(&date,&month,&year);
hi1000 20:ec9d4f6a16ac 426 printf("date : %02i-%02i-%02i",date,month,year);
hi1000 20:ec9d4f6a16ac 427 printf("\r\n");
hi1000 20:ec9d4f6a16ac 428
hi1000 20:ec9d4f6a16ac 429 rtc_test.setTime(19,48,45); // uncomment to set time
hi1000 20:ec9d4f6a16ac 430
hi1000 20:ec9d4f6a16ac 431 rtc_test.readTime(&hour,&minute,&second);
hi1000 20:ec9d4f6a16ac 432 printf("time : %02i:%02i:%02i",hour,minute,second);
hi1000 20:ec9d4f6a16ac 433 printf("\r\n");
hi1000 20:ec9d4f6a16ac 434
hi1000 20:ec9d4f6a16ac 435 rtc_test.setDate(6,22,12,2012); // uncomment to set date
hi1000 20:ec9d4f6a16ac 436 #endif
hi1000 21:acd050bf2f28 437 uart1.baud(115200);
hi1000 21:acd050bf2f28 438 uart1.printf("\n\n*** Hello Yoda2! ***\r\n");
hi1000 21:acd050bf2f28 439 printf("\n\n*** Hello Yoda2! ***\r\n");
hi1000 20:ec9d4f6a16ac 440
hi1000 9:486f65124378 441 // wait(1);
hi1000 19:0356e54240cc 442 #if 1
hi1000 14:2e17a27f56b2 443 ep.read((uint32_t)EEPROM_DEVICE_ADDRESS_ADDRESS,device_address);
hi1000 14:2e17a27f56b2 444 printf("EEPROM: read device address:%d 0x%08x\r\n", device_address, device_address);
hi1000 14:2e17a27f56b2 445 if ((device_address == 0) || (device_address == 0xFFFFFFFF))
hi1000 14:2e17a27f56b2 446 device_address = DEVICE_DEFAULT_ADDRESS;
hi1000 16:f4277e9b8612 447 device_type = (device_address & 0x00000700) >> 8;
hi1000 19:0356e54240cc 448 device_type_v = (Device_Type_d)device_type;
hi1000 8:6105ffbaf237 449 #ifdef LCD_1621
hi1000 4:40bb33497de4 450 lcd.clear(); // clears display
hi1000 4:40bb33497de4 451 lcd.allsegson();
hi1000 5:4585215afd11 452
hi1000 4:40bb33497de4 453 // lcd.printf("ABCDEFGHI"); // Standard printf function, All ASCII characters will display
hi1000 5:4585215afd11 454 #endif
hi1000 19:0356e54240cc 455 #ifdef YODA2
hi1000 20:ec9d4f6a16ac 456 #if 1
hi1000 19:0356e54240cc 457 lcd.cls();
hi1000 19:0356e54240cc 458 lcd.setContrast(31);
hi1000 19:0356e54240cc 459 lcd.setCursor(TextLCD::CurOff_BlkOff);
hi1000 19:0356e54240cc 460 lcd.setAddress(0,0);
hi1000 19:0356e54240cc 461 lcd.printf("Hello Yoda2!");
hi1000 20:ec9d4f6a16ac 462 #endif
hi1000 19:0356e54240cc 463 #endif
hi1000 5:4585215afd11 464 #ifdef LCD_1602
hi1000 16:f4277e9b8612 465 // lcd.printf( 0, "Hello world!" ); // line# (0 or 1), string
hi1000 16:f4277e9b8612 466 // lcd.printf( 1, "pi = %.6f", 3.14159265 );
hi1000 16:f4277e9b8612 467 // lcd.putcxy(0x55, 5, 1);
hi1000 16:f4277e9b8612 468 // lcd.printf(5, 0, "UUU");
hi1000 16:f4277e9b8612 469 // lcd.printf(0, 0, "pressed!" );
hi1000 9:486f65124378 470 #endif
hi1000 11:8702316d7fc8 471
hi1000 19:0356e54240cc 472 // input1.mode(PullUp);
hi1000 19:0356e54240cc 473 // input2.mode(PullUp);
hi1000 13:9f581a090e53 474
hi1000 0:765cf978c3e5 475 // can1.reset();
hi1000 0:765cf978c3e5 476 // can2.reset();
hi1000 20:ec9d4f6a16ac 477
hi1000 20:ec9d4f6a16ac 478 #if 1
hi1000 16:f4277e9b8612 479 printf("device_address =0x%08x \r\n", (device_address<<18));
hi1000 2:61a0169765bf 480 can1.frequency(100000);
hi1000 14:2e17a27f56b2 481 can1.filter((device_address<<18), 0x1FFC0000, CANExtended, init_filter_handle); // 0x1FFC0000 to filter the last 18bits 0-17
hi1000 16:f4277e9b8612 482 device_address = (device_address & 0x000000FF);
hi1000 14:2e17a27f56b2 483 //only support one filter
hi1000 14:2e17a27f56b2 484 // can1.filter(broadcast_id, 0x1FFC0000, CANExtended, broadcast_filter_handle); // the broadcast id
hi1000 0:765cf978c3e5 485 // can2.frequency(100000);
hi1000 12:5cb359f981f3 486 //button0.mode(PullUp); // Activate pull-up
hi1000 13:9f581a090e53 487 can_receivethread.start(can_rxthread);
hi1000 13:9f581a090e53 488 can_handlethread.start(analyzePayload);
hi1000 20:ec9d4f6a16ac 489 #endif
hi1000 20:ec9d4f6a16ac 490
hi1000 19:0356e54240cc 491 #endif
hi1000 19:0356e54240cc 492 button1.mode(PullUp);
hi1000 19:0356e54240cc 493 button2.mode(PullUp);
hi1000 19:0356e54240cc 494 button3.mode(PullUp);
hi1000 19:0356e54240cc 495 button4.mode(PullUp);
hi1000 12:5cb359f981f3 496 button0.fall(callback(button0_onpressed_cb)); // Attach ISR to handle button press event
hi1000 12:5cb359f981f3 497 button0.rise(callback(button0_onpressed_cb)); // Attach ISR to handle button press event
hi1000 2:61a0169765bf 498 button1.fall(callback(button1_onpressed_cb)); // Attach ISR to handle button press event
hi1000 12:5cb359f981f3 499 button1.rise(callback(button1_onpressed_cb)); // Attach ISR to handle button press event
hi1000 12:5cb359f981f3 500 button2.fall(callback(button2_onpressed_cb)); // Attach ISR to handle button press event
hi1000 12:5cb359f981f3 501 button2.rise(callback(button2_onpressed_cb)); // Attach ISR to handle button press event
hi1000 12:5cb359f981f3 502 button3.fall(callback(button3_onpressed_cb)); // Attach ISR to handle button press event
hi1000 12:5cb359f981f3 503 button3.rise(callback(button3_onpressed_cb)); // Attach ISR to handle button press event
hi1000 12:5cb359f981f3 504 button4.fall(callback(button4_onpressed_cb)); // Attach ISR to handle button press event
hi1000 12:5cb359f981f3 505 button4.rise(callback(button4_onpressed_cb)); // Attach ISR to handle button press event
hi1000 19:0356e54240cc 506 // i2c_scanner(PB_9, PB_8);
hi1000 11:8702316d7fc8 507 // eeprom_test();
hi1000 0:765cf978c3e5 508
hi1000 11:8702316d7fc8 509 #if 1
hi1000 18:e6ed582f7022 510 // scaleCalibration(true);
hi1000 19:0356e54240cc 511 switch (device_type_v)
hi1000 19:0356e54240cc 512 {
hi1000 21:acd050bf2f28 513 case CupTrack:
hi1000 21:acd050bf2f28 514 lcd.setAddress(0,1);
hi1000 21:acd050bf2f28 515 lcd.printf("CupTrack ");
hi1000 21:acd050bf2f28 516 break;
hi1000 19:0356e54240cc 517 case JamTrack:
hi1000 21:acd050bf2f28 518 lcd.setAddress(0,1);
hi1000 21:acd050bf2f28 519 lcd.printf("JamTrack ");
hi1000 21:acd050bf2f28 520 break;
hi1000 19:0356e54240cc 521 case TeaTrack:
hi1000 21:acd050bf2f28 522 lcd.setAddress(0,1);
hi1000 21:acd050bf2f28 523 lcd.printf("TeaTrack ");
hi1000 19:0356e54240cc 524 break;
hi1000 19:0356e54240cc 525 case Tea:
hi1000 21:acd050bf2f28 526 lcd.setAddress(0,1);
hi1000 21:acd050bf2f28 527 lcd.printf("Tea ");
hi1000 21:acd050bf2f28 528 init_scale();
hi1000 21:acd050bf2f28 529 scale_thread.start(scale_reading);
hi1000 21:acd050bf2f28 530 break;
hi1000 19:0356e54240cc 531 case Jam:
hi1000 21:acd050bf2f28 532 lcd.setAddress(0,1);
hi1000 21:acd050bf2f28 533 lcd.printf("Jam ");
hi1000 19:0356e54240cc 534 init_scale();
hi1000 19:0356e54240cc 535 scale_thread.start(scale_reading);
hi1000 19:0356e54240cc 536 break;
hi1000 19:0356e54240cc 537 case Shaker:
hi1000 21:acd050bf2f28 538 lcd.setAddress(0,1);
hi1000 21:acd050bf2f28 539 lcd.printf("Shaker ");
hi1000 19:0356e54240cc 540 break;
hi1000 19:0356e54240cc 541 default:
hi1000 19:0356e54240cc 542 break;
hi1000 19:0356e54240cc 543 }
hi1000 21:acd050bf2f28 544 lcd.printf("%d", device_address);
hi1000 14:2e17a27f56b2 545 mainmenu_thread.start(main_menu);
hi1000 14:2e17a27f56b2 546
hi1000 11:8702316d7fc8 547 #endif
hi1000 20:ec9d4f6a16ac 548 moveMotor3(0, true, false, false);
hi1000 20:ec9d4f6a16ac 549 wait(2);
hi1000 14:2e17a27f56b2 550 while(1) {
hi1000 20:ec9d4f6a16ac 551 wait(2);
hi1000 21:acd050bf2f28 552 #if 1
hi1000 21:acd050bf2f28 553 printf("Sensors:\r\n");
hi1000 21:acd050bf2f28 554 printf("%d %d %d %d \r\n", din1.read(), din2.read(), din3.read(), din4.read());
hi1000 21:acd050bf2f28 555 printf("%d %d %d %d \r\n", din5.read(), din6.read(), din7.read(), din8.read());
hi1000 21:acd050bf2f28 556 printf("Sensors:\r\n");
hi1000 21:acd050bf2f28 557 printf("%d %d %d %d \r\n", din1.read(), din2.read(), din3.read(), din4.read());
hi1000 21:acd050bf2f28 558 printf("%d %d %d %d \r\n", din5.read(), din6.read(), din7.read(), din8.read());
hi1000 21:acd050bf2f28 559 #endif
hi1000 20:ec9d4f6a16ac 560 #if 0
hi1000 20:ec9d4f6a16ac 561 distance = 0;
hi1000 20:ec9d4f6a16ac 562 distance = moveMotor3Until(true, din5);
hi1000 21:acd050bf2f28 563 printf("F distance=%d \r\n", distance);
hi1000 20:ec9d4f6a16ac 564 printf("Sensors:\r\n");
hi1000 20:ec9d4f6a16ac 565 printf("%d %d %d %d \r\n", din1.read(), din2.read(), din3.read(), din4.read());
hi1000 20:ec9d4f6a16ac 566 printf("%d %d %d %d \r\n", din5.read(), din6.read(), din7.read(), din8.read());
hi1000 20:ec9d4f6a16ac 567 wait(1);
hi1000 20:ec9d4f6a16ac 568 distance = 0;
hi1000 20:ec9d4f6a16ac 569 distance = moveMotor3Until(false, din5);
hi1000 20:ec9d4f6a16ac 570 printf("Sensors:\r\n");
hi1000 20:ec9d4f6a16ac 571 printf("%d %d %d %d \r\n", din1.read(), din2.read(), din3.read(), din4.read());
hi1000 20:ec9d4f6a16ac 572 printf("%d %d %d %d \r\n", din5.read(), din6.read(), din7.read(), din8.read());
hi1000 20:ec9d4f6a16ac 573 printf("B distance=%d \r\n", distance);
hi1000 20:ec9d4f6a16ac 574 #endif
hi1000 20:ec9d4f6a16ac 575 #if 0
hi1000 20:ec9d4f6a16ac 576 relay4 = 1;
hi1000 20:ec9d4f6a16ac 577 printf("relay4 turn on\r\n");
hi1000 20:ec9d4f6a16ac 578 wait(2);
hi1000 20:ec9d4f6a16ac 579 relay3 = 1;
hi1000 20:ec9d4f6a16ac 580 printf("relay3 turn on\r\n");
hi1000 20:ec9d4f6a16ac 581 wait(2);
hi1000 20:ec9d4f6a16ac 582 relay2 = 1;
hi1000 20:ec9d4f6a16ac 583 printf("relay2 turn on\r\n");
hi1000 20:ec9d4f6a16ac 584 wait(2);
hi1000 20:ec9d4f6a16ac 585 relay1 = 1;
hi1000 20:ec9d4f6a16ac 586 printf("relay1 turn on\r\n");
hi1000 20:ec9d4f6a16ac 587 wait(2);
hi1000 20:ec9d4f6a16ac 588 relay4 = 0;
hi1000 20:ec9d4f6a16ac 589 relay3 = 0;
hi1000 20:ec9d4f6a16ac 590 relay2 = 0;
hi1000 20:ec9d4f6a16ac 591 relay1 = 0;
hi1000 20:ec9d4f6a16ac 592 #endif
hi1000 20:ec9d4f6a16ac 593 #if 0
hi1000 20:ec9d4f6a16ac 594 rtc_test.readDateTime(&dayOfWeek,&date,&month,&year,&hour,&minute,&second);
hi1000 20:ec9d4f6a16ac 595 printf("date time : %i / %02i-%02i-%02i %02i:%02i:%02i",dayOfWeek,date,month,year,hour,minute,second);
hi1000 20:ec9d4f6a16ac 596 printf("\r\n");
hi1000 20:ec9d4f6a16ac 597
hi1000 20:ec9d4f6a16ac 598 printf("temperature :%6.2f", rtc_test.readTemp());
hi1000 20:ec9d4f6a16ac 599 printf("\r\n");
hi1000 20:ec9d4f6a16ac 600 #endif
hi1000 20:ec9d4f6a16ac 601 #if 0
hi1000 20:ec9d4f6a16ac 602 moveMotor3(850, true, false, false);
hi1000 20:ec9d4f6a16ac 603 wait(5);
hi1000 20:ec9d4f6a16ac 604 moveMotor3(850, false, false, false);
hi1000 20:ec9d4f6a16ac 605 #endif
hi1000 20:ec9d4f6a16ac 606 #if 0
hi1000 20:ec9d4f6a16ac 607 moveMotor1(100, true, false, false);
hi1000 20:ec9d4f6a16ac 608 moveMotor2(100, true, false, false);
hi1000 20:ec9d4f6a16ac 609 moveMotor3(100, true, false, false);
hi1000 20:ec9d4f6a16ac 610 wait(1);
hi1000 20:ec9d4f6a16ac 611 moveMotor1(150, true, false, false);
hi1000 20:ec9d4f6a16ac 612 moveMotor2(150, true, false, false);
hi1000 20:ec9d4f6a16ac 613 moveMotor3(150, true, false, false);
hi1000 20:ec9d4f6a16ac 614 wait(1);
hi1000 20:ec9d4f6a16ac 615 moveMotor1(250, false, false, false);
hi1000 20:ec9d4f6a16ac 616 moveMotor2(250, false, false, false);
hi1000 20:ec9d4f6a16ac 617 moveMotor3(250, false, false, false);
hi1000 20:ec9d4f6a16ac 618 #endif
hi1000 20:ec9d4f6a16ac 619 #if 1
hi1000 19:0356e54240cc 620 if (!can_register_success)
hi1000 19:0356e54240cc 621 {
hi1000 19:0356e54240cc 622 can_txdata_frame.cmd = COMMAND_REGISTER;
hi1000 19:0356e54240cc 623 can_txdata_frame.value1 = 0;
hi1000 19:0356e54240cc 624 can_txdata_frame.value2 = 0;
hi1000 19:0356e54240cc 625 can_txdata_frame.value3 = 0;
hi1000 19:0356e54240cc 626 memcpy(can_tx_data, (unsigned char *)&can_txdata_frame, sizeof(can_tx_data));
hi1000 19:0356e54240cc 627 // printf("cmd=0x%08x value1=0x%08x size=%d %d\r\n", can_txdata_frame.cmd, can_txdata_frame.value1, sizeof(can_tx_data), sizeof(can_txdata_frame));
hi1000 19:0356e54240cc 628 // printf("data 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x \r\n", can_tx_data[0], can_tx_data[1], can_tx_data[2], can_tx_data[3], can_tx_data[4], can_tx_data[5], can_tx_data[6], can_tx_data[7]);
hi1000 19:0356e54240cc 629 can_id = (RASPBERRY_PI_CAN_ADDRESS << 18) | (((device_type << 8) |device_address) << 7) | 0x80000000;
hi1000 19:0356e54240cc 630 // printf("device_address = 0x%08x can_id=0x%08x \r\n", device_address, can_id);
hi1000 19:0356e54240cc 631 can_sendData(can_id, can_tx_data, 8);
hi1000 19:0356e54240cc 632 }
hi1000 19:0356e54240cc 633 #endif
hi1000 14:2e17a27f56b2 634 }
hi1000 14:2e17a27f56b2 635
hi1000 14:2e17a27f56b2 636 #if 0
hi1000 0:765cf978c3e5 637 int idx = 0; // Just for printf below
hi1000 9:486f65124378 638 can_tx_data[0] = 0;
hi1000 0:765cf978c3e5 639 while(1) {
hi1000 12:5cb359f981f3 640 if (button0_pressed) { // Set when button is pressed
hi1000 9:486f65124378 641 #if 0
hi1000 1:eb499e2a1b9b 642 printf("scale value %f. \r\n", hx711.getGram());
hi1000 9:486f65124378 643 #endif
hi1000 9:486f65124378 644 can_tx_data[1] = can_tx_data[0]+1;
hi1000 9:486f65124378 645 can_tx_data[2] = can_tx_data[1]+1;
hi1000 9:486f65124378 646 can_tx_data[3] = can_tx_data[2]+1;
hi1000 9:486f65124378 647 can_tx_data[4] = can_tx_data[3]+1;
hi1000 9:486f65124378 648 can_tx_data[5] = can_tx_data[4]+1;
hi1000 9:486f65124378 649 can_tx_data[6] = can_tx_data[5]+1;
hi1000 9:486f65124378 650 can_tx_data[7] = can_tx_data[6]+1;
hi1000 12:5cb359f981f3 651 button0_pressed = false;
hi1000 2:61a0169765bf 652 printf("Button pressed %d\r\n", idx++);
hi1000 9:486f65124378 653 printf("ID=%d data[0]=%d. \r\n", init_id + idx%10, can_tx_data[0]);
hi1000 9:486f65124378 654 #ifdef LCD_1602
hi1000 9:486f65124378 655 lcd.printf(0, 0, "%d ", idx ); // line# (0 or 1), string
hi1000 9:486f65124378 656 #endif
hi1000 17:faa4d4976d22 657 can1.write(CANMessage((init_id + idx%10), reinterpret_cast<char*>(can_tx_data), 8, CANData,CANExtended));
hi1000 0:765cf978c3e5 658 led1 = !led1;
hi1000 9:486f65124378 659 can_tx_data[0]++;
hi1000 0:765cf978c3e5 660 }
hi1000 0:765cf978c3e5 661 }
hi1000 14:2e17a27f56b2 662 #endif
hi1000 9:486f65124378 663
hi1000 0:765cf978c3e5 664 }