for HTTP-3A

Dependencies:   mbed TextLCD

Committer:
thomasya
Date:
Thu Jul 11 12:24:29 2019 +0000
Revision:
5:1d817b3c42f1
Parent:
4:c1438ffd88dd
Child:
6:572219c7c378
Arm/disarm fct add;

Who changed what in which revision?

UserRevisionLine numberNew 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 5:1d817b3c42f1 16 DigitalIn armSwitch(PF_7, PullDown);
thomasya 5:1d817b3c42f1 17 bool armed = false;
thomasya 4:c1438ffd88dd 18
thomasya 4:c1438ffd88dd 19 AnalogIn res(PA_0);
thomasya 4:c1438ffd88dd 20 float volt = 0;
group-ST 0:6e8275981824 21
thomasya 3:043e5e06f325 22
thomasya 5:1d817b3c42f1 23 //I2C i2c_lcd(PB_7,PB_6); // SDA, SCL
thomasya 5:1d817b3c42f1 24 I2C i2c_lcd(PF_0,PF_1); // SDA, SCL
thomasya 4:c1438ffd88dd 25 TextLCD_I2C lcd(&i2c_lcd, 0x7E, TextLCD::LCD16x2); // I2C bus, PCF8574 Slaveaddress, LCD Type
thomasya 4:c1438ffd88dd 26
thomasya 4:c1438ffd88dd 27 const char fill[] = {0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x00};
thomasya 4:c1438ffd88dd 28 const char empty[] = {0x1F, 0x11, 0x11, 0x11, 0x11, 0x11, 0x1F, 0x00};
thomasya 5:1d817b3c42f1 29 const char cross[] = {0x00, 0x11, 0x0A, 0x04, 0x0A, 0x11, 0x00, 0x00};
thomasya 4:c1438ffd88dd 30
thomasya 4:c1438ffd88dd 31 void showBar(void);
thomasya 3:043e5e06f325 32
thomasya 5:1d817b3c42f1 33 void showArm(void);
thomasya 5:1d817b3c42f1 34
thomasya 3:043e5e06f325 35 void CAN_RX1(void);
group-ST 0:6e8275981824 36
thomasya 3:043e5e06f325 37 void sendCMD(void)
thomasya 3:043e5e06f325 38 {
thomasya 4:c1438ffd88dd 39 if(armed)
thomasya 4:c1438ffd88dd 40 {
thomasya 4:c1438ffd88dd 41 can_msg_send = CANMessage(0x111,data_msg,3,CANData,CANStandard);
thomasya 4:c1438ffd88dd 42 can1.write(can_msg_send);
thomasya 4:c1438ffd88dd 43 }
thomasya 3:043e5e06f325 44
thomasya 3:043e5e06f325 45 //printf("res: %f\n", res.read());
thomasya 3:043e5e06f325 46 }
group-ST 0:6e8275981824 47
group-ST 0:6e8275981824 48 int main()
group-ST 0:6e8275981824 49 {
thomasya 3:043e5e06f325 50
thomasya 4:c1438ffd88dd 51 can1.frequency(500000);
thomasya 4:c1438ffd88dd 52 can1.attach(&CAN_RX1, CAN::RxIrq);
thomasya 4:c1438ffd88dd 53 ticker1.attach(&sendCMD, 1);
thomasya 3:043e5e06f325 54 pc.printf("start\n");
thomasya 3:043e5e06f325 55
thomasya 4:c1438ffd88dd 56
thomasya 4:c1438ffd88dd 57
thomasya 4:c1438ffd88dd 58 lcd.setCursor(TextLCD::CurOff_BlkOff);
thomasya 4:c1438ffd88dd 59 lcd.setBacklight(TextLCD::LightOn);
thomasya 4:c1438ffd88dd 60 lcd.setUDC(0, (char *) fill);
thomasya 4:c1438ffd88dd 61 lcd.setUDC(1, (char *) empty);
thomasya 5:1d817b3c42f1 62 lcd.setUDC(2, (char *) cross);
thomasya 4:c1438ffd88dd 63 pc.printf("set done\n\r");
thomasya 4:c1438ffd88dd 64
thomasya 3:043e5e06f325 65 while(1)
thomasya 4:c1438ffd88dd 66 {
thomasya 4:c1438ffd88dd 67 volt = res.read();
thomasya 4:c1438ffd88dd 68 showBar();
thomasya 5:1d817b3c42f1 69 showArm();
thomasya 5:1d817b3c42f1 70
thomasya 5:1d817b3c42f1 71
thomasya 3:043e5e06f325 72 }
thomasya 3:043e5e06f325 73
thomasya 3:043e5e06f325 74 }
thomasya 3:043e5e06f325 75
thomasya 3:043e5e06f325 76
thomasya 3:043e5e06f325 77
thomasya 3:043e5e06f325 78 void CAN_RX1(void)
thomasya 3:043e5e06f325 79 {
thomasya 3:043e5e06f325 80 if(can1.read(can_msg_1))
thomasya 3:043e5e06f325 81 {
thomasya 3:043e5e06f325 82 pc.printf("CAN RX %d\n", can_msg_1.id);
thomasya 3:043e5e06f325 83
group-ST 0:6e8275981824 84 }
group-ST 0:6e8275981824 85 }
thomasya 4:c1438ffd88dd 86
thomasya 4:c1438ffd88dd 87 void showBar(void)
thomasya 4:c1438ffd88dd 88 {
thomasya 4:c1438ffd88dd 89 int bars = 16 * (volt-VMIN)/(VMAX-VMIN);
thomasya 4:c1438ffd88dd 90 if (bars > 16)
thomasya 4:c1438ffd88dd 91 bars = 16;
thomasya 4:c1438ffd88dd 92 else if( bars < 0 )
thomasya 4:c1438ffd88dd 93 bars = 0;
thomasya 4:c1438ffd88dd 94
thomasya 5:1d817b3c42f1 95 if (armed)
thomasya 4:c1438ffd88dd 96 {
thomasya 5:1d817b3c42f1 97 for(int i = 0; i<bars ;i++)
thomasya 5:1d817b3c42f1 98 {
thomasya 5:1d817b3c42f1 99 lcd.locate(i,0);
thomasya 5:1d817b3c42f1 100 lcd.putc(0);
thomasya 5:1d817b3c42f1 101 }
thomasya 5:1d817b3c42f1 102 for(int i = bars; i<16 ;i++)
thomasya 5:1d817b3c42f1 103 {
thomasya 5:1d817b3c42f1 104 lcd.locate(i,0);
thomasya 5:1d817b3c42f1 105 lcd.putc(1);
thomasya 5:1d817b3c42f1 106 }
thomasya 5:1d817b3c42f1 107 }
thomasya 5:1d817b3c42f1 108 else
thomasya 4:c1438ffd88dd 109 {
thomasya 5:1d817b3c42f1 110 for(int i = 0; i<bars ;i++)
thomasya 5:1d817b3c42f1 111 {
thomasya 5:1d817b3c42f1 112 lcd.locate(i,0);
thomasya 5:1d817b3c42f1 113 lcd.putc(2);
thomasya 5:1d817b3c42f1 114 }
thomasya 5:1d817b3c42f1 115 for(int i = bars; i<16 ;i++)
thomasya 5:1d817b3c42f1 116 {
thomasya 5:1d817b3c42f1 117 lcd.locate(i,0);
thomasya 5:1d817b3c42f1 118 lcd.putc(1);
thomasya 5:1d817b3c42f1 119 }
thomasya 4:c1438ffd88dd 120 }
thomasya 4:c1438ffd88dd 121 }
thomasya 5:1d817b3c42f1 122
thomasya 5:1d817b3c42f1 123 void showArm(void)
thomasya 5:1d817b3c42f1 124 {
thomasya 5:1d817b3c42f1 125 if (armSwitch)
thomasya 5:1d817b3c42f1 126 armed = true;
thomasya 5:1d817b3c42f1 127 else
thomasya 5:1d817b3c42f1 128 armed = false;
thomasya 5:1d817b3c42f1 129
thomasya 5:1d817b3c42f1 130 if (armed)
thomasya 5:1d817b3c42f1 131 {
thomasya 5:1d817b3c42f1 132 lcd.locate(0,1);
thomasya 5:1d817b3c42f1 133 lcd.printf("ARMED ");
thomasya 5:1d817b3c42f1 134 }
thomasya 5:1d817b3c42f1 135 else
thomasya 5:1d817b3c42f1 136 {
thomasya 5:1d817b3c42f1 137 lcd.locate(0,1);
thomasya 5:1d817b3c42f1 138 lcd.printf("DISARMED");
thomasya 5:1d817b3c42f1 139 }
thomasya 5:1d817b3c42f1 140
thomasya 5:1d817b3c42f1 141 }