thomas ya
/
LV_FGSE_Controller_Interface
for HTTP-3A
main.cpp@4:c1438ffd88dd, 2019-07-11 (annotated)
- Committer:
- thomasya
- Date:
- Thu Jul 11 09:29:11 2019 +0000
- Revision:
- 4:c1438ffd88dd
- Parent:
- 3:043e5e06f325
- Child:
- 5:1d817b3c42f1
show bar + res integration done;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
thomasya | 3:043e5e06f325 | 1 | #include "mbed.h" |
thomasya | 4:c1438ffd88dd | 2 | #include "TextLCD.h" |
thomasya | 4:c1438ffd88dd | 3 | #define VMAX 0.36f |
thomasya | 4:c1438ffd88dd | 4 | #define VMIN 0.05f |
thomasya | 3:043e5e06f325 | 5 | |
thomasya | 4:c1438ffd88dd | 6 | |
thomasya | 3:043e5e06f325 | 7 | Serial pc(USBTX, USBRX, 115200); |
group-ST | 0:6e8275981824 | 8 | |
thomasya | 3:043e5e06f325 | 9 | Ticker ticker1; |
thomasya | 3:043e5e06f325 | 10 | |
thomasya | 4:c1438ffd88dd | 11 | CAN can1(PB_8, PB_9); |
thomasya | 3:043e5e06f325 | 12 | CANMessage can_msg_1; |
thomasya | 3:043e5e06f325 | 13 | CANMessage can_msg_send; |
thomasya | 4:c1438ffd88dd | 14 | char data_msg[3] = {0x11,0x22,0x33}; |
thomasya | 4:c1438ffd88dd | 15 | |
thomasya | 4:c1438ffd88dd | 16 | |
thomasya | 3:043e5e06f325 | 17 | bool armed = false; |
thomasya | 4:c1438ffd88dd | 18 | AnalogIn res(PA_0); |
thomasya | 4:c1438ffd88dd | 19 | float volt = 0; |
group-ST | 0:6e8275981824 | 20 | |
thomasya | 3:043e5e06f325 | 21 | |
thomasya | 4:c1438ffd88dd | 22 | I2C i2c_lcd(PB_7,PB_6); // SDA, SCL |
thomasya | 4:c1438ffd88dd | 23 | TextLCD_I2C lcd(&i2c_lcd, 0x7E, TextLCD::LCD16x2); // I2C bus, PCF8574 Slaveaddress, LCD Type |
thomasya | 4:c1438ffd88dd | 24 | |
thomasya | 4:c1438ffd88dd | 25 | const char fill[] = {0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x00}; |
thomasya | 4:c1438ffd88dd | 26 | const char empty[] = {0x1F, 0x11, 0x11, 0x11, 0x11, 0x11, 0x1F, 0x00}; |
thomasya | 4:c1438ffd88dd | 27 | |
thomasya | 4:c1438ffd88dd | 28 | |
thomasya | 4:c1438ffd88dd | 29 | void showBar(void); |
thomasya | 3:043e5e06f325 | 30 | |
thomasya | 3:043e5e06f325 | 31 | void CAN_RX1(void); |
group-ST | 0:6e8275981824 | 32 | |
thomasya | 3:043e5e06f325 | 33 | void sendCMD(void) |
thomasya | 3:043e5e06f325 | 34 | { |
thomasya | 4:c1438ffd88dd | 35 | if(armed) |
thomasya | 4:c1438ffd88dd | 36 | { |
thomasya | 4:c1438ffd88dd | 37 | can_msg_send = CANMessage(0x111,data_msg,3,CANData,CANStandard); |
thomasya | 4:c1438ffd88dd | 38 | can1.write(can_msg_send); |
thomasya | 4:c1438ffd88dd | 39 | } |
thomasya | 3:043e5e06f325 | 40 | |
thomasya | 3:043e5e06f325 | 41 | //printf("res: %f\n", res.read()); |
thomasya | 3:043e5e06f325 | 42 | } |
group-ST | 0:6e8275981824 | 43 | |
group-ST | 0:6e8275981824 | 44 | int main() |
group-ST | 0:6e8275981824 | 45 | { |
thomasya | 3:043e5e06f325 | 46 | |
thomasya | 4:c1438ffd88dd | 47 | can1.frequency(500000); |
thomasya | 4:c1438ffd88dd | 48 | can1.attach(&CAN_RX1, CAN::RxIrq); |
thomasya | 4:c1438ffd88dd | 49 | ticker1.attach(&sendCMD, 1); |
thomasya | 3:043e5e06f325 | 50 | pc.printf("start\n"); |
thomasya | 3:043e5e06f325 | 51 | |
thomasya | 4:c1438ffd88dd | 52 | |
thomasya | 4:c1438ffd88dd | 53 | |
thomasya | 4:c1438ffd88dd | 54 | lcd.setCursor(TextLCD::CurOff_BlkOff); |
thomasya | 4:c1438ffd88dd | 55 | lcd.setBacklight(TextLCD::LightOn); |
thomasya | 4:c1438ffd88dd | 56 | lcd.setUDC(0, (char *) fill); |
thomasya | 4:c1438ffd88dd | 57 | lcd.setUDC(1, (char *) empty); |
thomasya | 4:c1438ffd88dd | 58 | pc.printf("set done\n\r"); |
thomasya | 4:c1438ffd88dd | 59 | |
thomasya | 3:043e5e06f325 | 60 | while(1) |
thomasya | 4:c1438ffd88dd | 61 | { |
thomasya | 4:c1438ffd88dd | 62 | volt = res.read(); |
thomasya | 4:c1438ffd88dd | 63 | showBar(); |
thomasya | 3:043e5e06f325 | 64 | } |
thomasya | 3:043e5e06f325 | 65 | |
thomasya | 3:043e5e06f325 | 66 | } |
thomasya | 3:043e5e06f325 | 67 | |
thomasya | 3:043e5e06f325 | 68 | |
thomasya | 3:043e5e06f325 | 69 | |
thomasya | 3:043e5e06f325 | 70 | void CAN_RX1(void) |
thomasya | 3:043e5e06f325 | 71 | { |
thomasya | 3:043e5e06f325 | 72 | if(can1.read(can_msg_1)) |
thomasya | 3:043e5e06f325 | 73 | { |
thomasya | 3:043e5e06f325 | 74 | pc.printf("CAN RX %d\n", can_msg_1.id); |
thomasya | 3:043e5e06f325 | 75 | |
group-ST | 0:6e8275981824 | 76 | } |
group-ST | 0:6e8275981824 | 77 | } |
thomasya | 4:c1438ffd88dd | 78 | |
thomasya | 4:c1438ffd88dd | 79 | void showBar(void) |
thomasya | 4:c1438ffd88dd | 80 | { |
thomasya | 4:c1438ffd88dd | 81 | int bars = 16 * (volt-VMIN)/(VMAX-VMIN); |
thomasya | 4:c1438ffd88dd | 82 | if (bars > 16) |
thomasya | 4:c1438ffd88dd | 83 | bars = 16; |
thomasya | 4:c1438ffd88dd | 84 | else if( bars < 0 ) |
thomasya | 4:c1438ffd88dd | 85 | bars = 0; |
thomasya | 4:c1438ffd88dd | 86 | |
thomasya | 4:c1438ffd88dd | 87 | |
thomasya | 4:c1438ffd88dd | 88 | for(int i = 0; i<bars ;i++) |
thomasya | 4:c1438ffd88dd | 89 | { |
thomasya | 4:c1438ffd88dd | 90 | lcd.locate(i,0); |
thomasya | 4:c1438ffd88dd | 91 | lcd.putc(0); |
thomasya | 4:c1438ffd88dd | 92 | } |
thomasya | 4:c1438ffd88dd | 93 | for(int i = bars; i<16 ;i++) |
thomasya | 4:c1438ffd88dd | 94 | { |
thomasya | 4:c1438ffd88dd | 95 | lcd.locate(i,0); |
thomasya | 4:c1438ffd88dd | 96 | lcd.putc(1); |
thomasya | 4:c1438ffd88dd | 97 | } |
thomasya | 4:c1438ffd88dd | 98 | } |