Feng Hong / Mbed OS Nucleo_rtos_basic
Committer:
hi1000
Date:
Sat Oct 19 02:10:12 2019 +0000
Revision:
20:ec9d4f6a16ac
Parent:
19:0356e54240cc
Child:
21:5c6b3657c3cb
The first version of ROT-CANBUS R01/0819

Who changed what in which revision?

UserRevisionLine numberNew contents of line
hi1000 19:0356e54240cc 1 //#define RASPBERRY_PI_CAN_ADDRESS 0x01
hi1000 19:0356e54240cc 2 #define YODA2
hi1000 19:0356e54240cc 3 #define RASPBERRY_PI_CAN_TYPE 0x07
hi1000 19:0356e54240cc 4 #define RASPBERRY_PI_CAN_ID 0x01
hi1000 19:0356e54240cc 5 #define RASPBERRY_PI_CAN_ADDRESS ((RASPBERRY_PI_CAN_TYPE<<8) | RASPBERRY_PI_CAN_ID)
hi1000 19:0356e54240cc 6
hi1000 19:0356e54240cc 7 #ifdef OWN_SOLDER_BOARD
hi1000 19:0356e54240cc 8 #define BUTTON1 PB_4 // right // up
hi1000 19:0356e54240cc 9 #define BUTTON2 PC_1 // left // down
hi1000 19:0356e54240cc 10 #define BUTTON3 PC_7 // enter // next
hi1000 19:0356e54240cc 11 #define BUTTON4 PA_9 // menu // back
hi1000 19:0356e54240cc 12 #endif
hi1000 19:0356e54240cc 13
hi1000 19:0356e54240cc 14 #ifdef YODA2
hi1000 19:0356e54240cc 15 #define BUTTON1 PA_8 // right // up
hi1000 19:0356e54240cc 16 #define BUTTON2 PB_10 // left // down
hi1000 19:0356e54240cc 17 #define BUTTON3 PB_4 // enter // next
hi1000 19:0356e54240cc 18 #define BUTTON4 PB_5 // menu // back
hi1000 20:ec9d4f6a16ac 19 #define RELAY_4 PD_2
hi1000 20:ec9d4f6a16ac 20 #define RELAY_3 PC_11
hi1000 20:ec9d4f6a16ac 21 #define RELAY_2 PC_10
hi1000 20:ec9d4f6a16ac 22 #define RELAY_1 PC_12
hi1000 19:0356e54240cc 23 #endif
hi1000 19:0356e54240cc 24
hi1000 14:2e17a27f56b2 25 #define BUTTON1_HOLD_EVENT 0x0001
hi1000 14:2e17a27f56b2 26 #define BUTTON1_PRESSED_EVENT 0x0002
hi1000 14:2e17a27f56b2 27 #define BUTTON2_HOLD_EVENT 0x0004
hi1000 14:2e17a27f56b2 28 #define BUTTON2_PRESSED_EVENT 0x0008
hi1000 14:2e17a27f56b2 29 #define BUTTON3_HOLD_EVENT 0x0010
hi1000 14:2e17a27f56b2 30 #define BUTTON3_PRESSED_EVENT 0x0020
hi1000 14:2e17a27f56b2 31 #define BUTTON4_HOLD_EVENT 0x0040
hi1000 14:2e17a27f56b2 32 #define BUTTON4_PRESSED_EVENT 0x0080
hi1000 19:0356e54240cc 33 #define NEXT_HOLD_EVENT BUTTON4_HOLD_EVENT
hi1000 19:0356e54240cc 34 #define NEXT_PRESSED_EVENT BUTTON4_PRESSED_EVENT
hi1000 19:0356e54240cc 35 #define BACK_HOLD_EVENT BUTTON3_HOLD_EVENT
hi1000 19:0356e54240cc 36 #define BACK_PRESSED_EVENT BUTTON3_PRESSED_EVENT
hi1000 19:0356e54240cc 37 #define DOWN_HOLD_EVENT BUTTON2_HOLD_EVENT
hi1000 19:0356e54240cc 38 #define DOWN_PRESSED_EVENT BUTTON2_PRESSED_EVENT
hi1000 19:0356e54240cc 39 #define UP_HOLD_EVENT BUTTON1_HOLD_EVENT
hi1000 19:0356e54240cc 40 #define UP_PRESSED_EVENT BUTTON1_PRESSED_EVENT
hi1000 14:2e17a27f56b2 41 #define LCD_DISPLAY_HOLD_EVENT 0x0001
hi1000 17:faa4d4976d22 42 #define LCD_DISPLAY_RELEASE_EVENT 0x0002
hi1000 17:faa4d4976d22 43
hi1000 17:faa4d4976d22 44 #define COMMAND_INIT 0 // all the devices return to the point 0 and return the current possition or current weight
hi1000 17:faa4d4976d22 45 #define COMMAND_PLUS 1 // for the devices to plus weight return the weight
hi1000 17:faa4d4976d22 46 #define COMMAND_MINUS 2 // for the devices to minus weight return the weight
hi1000 17:faa4d4976d22 47 #define COMMAND_MOVE_ABSOLUTE 3 // for the devices to move to the absolute position return the current absolute position
hi1000 17:faa4d4976d22 48 #define COMMAND_MOVE_RELATIVE 4 // for the devices to move relative distance return the current absolute position
hi1000 17:faa4d4976d22 49 #define COMMAND_REPORT_WEIGHT 5 // for the devices to report the current weight
hi1000 17:faa4d4976d22 50 #define COMMAND_REPORT_POSITION 6 // for the devices to report the current absolute position
hi1000 17:faa4d4976d22 51 #define COMMAND_CLEAN 7 // for the devices to clean the cups return done or failed
hi1000 17:faa4d4976d22 52 #define COMMAND_TARE 8 // for the devices to tare the scale return done or failed
hi1000 17:faa4d4976d22 53 #define COMMAND_SHAKE_CUP 9 // for the device to shake the cups return done or failed
hi1000 17:faa4d4976d22 54 #define COMMAND_POUR_TEA 10 // for the device to pour the tea return done or failed
hi1000 17:faa4d4976d22 55 #define COMMAND_FINISH 11 // for everything finished return done or failed
hi1000 18:e6ed582f7022 56 #define COMMAND_RESET 12 // for the devices return to the point 0 and clean themselvies
hi1000 19:0356e54240cc 57 #define COMMAND_REGISTER 13 // for device to register itself to raspberry pi
hi1000 18:e6ed582f7022 58
hi1000 18:e6ed582f7022 59
hi1000 18:e6ed582f7022 60 #define WEIGHT_DIFFERENCE 200 // 10g ADC value minimum difference
hi1000 18:e6ed582f7022 61 #define CALIBRATION_WEIGHT 2000 // calibration weight
hi1000 18:e6ed582f7022 62 #define MAXIMUM_CALIBRATION_WEIGHT 5000
hi1000 18:e6ed582f7022 63 #define MINIMUM_CALIBRATION_WEIGHT 100
hi1000 18:e6ed582f7022 64
hi1000 19:0356e54240cc 65 #ifdef OWN_SOLDER_BOARD
hi1000 19:0356e54240cc 66 #define EEPROM_ADDR 0x0 // I2c EEPROM address is 0x00
hi1000 19:0356e54240cc 67 #endif
hi1000 19:0356e54240cc 68 #ifdef YODA2
hi1000 19:0356e54240cc 69 #define EEPROM_ADDR 0x57
hi1000 19:0356e54240cc 70 #endif
hi1000 19:0356e54240cc 71 #ifdef STM32F207xx
hi1000 19:0356e54240cc 72 #define SDA PB_9 // I2C SDA pin
hi1000 19:0356e54240cc 73 #define SCL PB_8 // I2C SCL pin
hi1000 19:0356e54240cc 74 #endif
hi1000 19:0356e54240cc 75
hi1000 19:0356e54240cc 76 #ifdef STM32F303xE
hi1000 19:0356e54240cc 77 #ifdef OWN_SOLDER_BOARD
hi1000 19:0356e54240cc 78 #define SDA PC_9//D2//D2//PB_9 //PF_0 // I2C SDA pin
hi1000 19:0356e54240cc 79 #define SCL D7//D8//D8//PB_8 //PF_1 // I2C SCL pin
hi1000 19:0356e54240cc 80 #endif
hi1000 19:0356e54240cc 81 #ifdef YODA2
hi1000 19:0356e54240cc 82 #define SDA PA_10//D2//D2//PB_9 //PF_0 // I2C SDA pin
hi1000 19:0356e54240cc 83 #define SCL PA_9//D8//D8//PB_8 //PF_1 // I2C SCL pin
hi1000 20:ec9d4f6a16ac 84 #define LCD_SDA PB_9 // I2C SDA pin
hi1000 20:ec9d4f6a16ac 85 #define LCD_SCL PB_8 // I2C SCL pin
hi1000 20:ec9d4f6a16ac 86 #define SCALE_SDA PA_1
hi1000 20:ec9d4f6a16ac 87 #define SCALE_SCL PA_0
hi1000 20:ec9d4f6a16ac 88 #define CAN_RD PA_11
hi1000 20:ec9d4f6a16ac 89 #define CAN_TD PA_12
hi1000 20:ec9d4f6a16ac 90 #define DIN1 PC_0
hi1000 20:ec9d4f6a16ac 91 #define DIN2 PC_1
hi1000 20:ec9d4f6a16ac 92 #define DIN3 PB_0
hi1000 20:ec9d4f6a16ac 93 #define DIN4 PA_4
hi1000 20:ec9d4f6a16ac 94 #define DIN5 PC_3
hi1000 20:ec9d4f6a16ac 95 #define DIN6 PC_2
hi1000 20:ec9d4f6a16ac 96 #define DIN7 PB_7
hi1000 20:ec9d4f6a16ac 97 #define DIN8 PA_15
hi1000 19:0356e54240cc 98 #endif
hi1000 19:0356e54240cc 99 #endif
hi1000 19:0356e54240cc 100
hi1000 19:0356e54240cc 101 #define MIN(X,Y) ((X) < (Y) ? (X) : (Y))
hi1000 19:0356e54240cc 102 #define MAX(X,Y) ((X) > (Y) ? (X) : (Y))
hi1000 19:0356e54240cc 103
hi1000 19:0356e54240cc 104 #define EEPROM_DEVICE_ADDRESS_ADDRESS 0x40
hi1000 19:0356e54240cc 105 #define DEVICE_DEFAULT_ADDRESS 12
hi1000 19:0356e54240cc 106
hi1000 19:0356e54240cc 107
hi1000 18:e6ed582f7022 108 enum Device_Type_d
hi1000 18:e6ed582f7022 109 {
hi1000 18:e6ed582f7022 110 CupTrack=0,
hi1000 18:e6ed582f7022 111 JamTrack=1,
hi1000 18:e6ed582f7022 112 TeaTrack=2,
hi1000 18:e6ed582f7022 113 Tea=3,
hi1000 18:e6ed582f7022 114 Jam=4,
hi1000 19:0356e54240cc 115 Shaker=5,
hi1000 19:0356e54240cc 116 IceMaker=6
hi1000 18:e6ed582f7022 117 };
hi1000 18:e6ed582f7022 118
hi1000 20:ec9d4f6a16ac 119
hi1000 18:e6ed582f7022 120 struct ScaleCalibrationData {
hi1000 18:e6ed582f7022 121 unsigned int calibrationWeight; // the weight (g) used for calibration for example 1000g or 10g. The maximum value is 3000.
hi1000 18:e6ed582f7022 122 long offsetValue; // the value for scale offset
hi1000 18:e6ed582f7022 123 float scaleValue; // the ADC increment for 1g
hi1000 18:e6ed582f7022 124 uint8_t checksum;
hi1000 19:0356e54240cc 125 };
hi1000 19:0356e54240cc 126
hi1000 19:0356e54240cc 127 // because memcpy is 16 byte alignment no byte in struct
hi1000 19:0356e54240cc 128 struct data_field_d {
hi1000 19:0356e54240cc 129 uint16_t cmd;
hi1000 19:0356e54240cc 130 uint16_t value1;
hi1000 19:0356e54240cc 131 uint16_t value2;
hi1000 19:0356e54240cc 132 uint16_t value3;
hi1000 19:0356e54240cc 133 };