Dans le cadre d'un TP de réseaux de terrains, nous avons réaliser la mise en place d'un TouchSensor sur un réseau CAN.
main.cpp@0:ab05df6e380e, 2018-06-05 (annotated)
- Committer:
- alex_clin
- Date:
- Tue Jun 05 16:50:16 2018 +0000
- Revision:
- 0:ab05df6e380e
DII4 - TP CAN Clinchamp Alexis Hourcade Paul - TouchSensor;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
alex_clin | 0:ab05df6e380e | 1 | #include "mbed.h" |
alex_clin | 0:ab05df6e380e | 2 | #include "MPR121.h" |
alex_clin | 0:ab05df6e380e | 3 | #define SIG_RX_CAN 0x01 |
alex_clin | 0:ab05df6e380e | 4 | |
alex_clin | 0:ab05df6e380e | 5 | Thread threadEnvoi; |
alex_clin | 0:ab05df6e380e | 6 | |
alex_clin | 0:ab05df6e380e | 7 | unsigned int Id = 0b00000000001; |
alex_clin | 0:ab05df6e380e | 8 | |
alex_clin | 0:ab05df6e380e | 9 | CAN CanPort(p30, p29); |
alex_clin | 0:ab05df6e380e | 10 | CANMessage message; |
alex_clin | 0:ab05df6e380e | 11 | |
alex_clin | 0:ab05df6e380e | 12 | I2C i2c(p28, p27); |
alex_clin | 0:ab05df6e380e | 13 | MPR121 touch_pad(i2c, MPR121::ADDR_VSS); |
alex_clin | 0:ab05df6e380e | 14 | |
alex_clin | 0:ab05df6e380e | 15 | void envoi(){ |
alex_clin | 0:ab05df6e380e | 16 | uint8_t boutons; |
alex_clin | 0:ab05df6e380e | 17 | while(1){ |
alex_clin | 0:ab05df6e380e | 18 | message.format = CANStandard; |
alex_clin | 0:ab05df6e380e | 19 | //message.format = CANExtended; |
alex_clin | 0:ab05df6e380e | 20 | |
alex_clin | 0:ab05df6e380e | 21 | message.id=Id; |
alex_clin | 0:ab05df6e380e | 22 | boutons = touch_pad.buttonPressed(); |
alex_clin | 0:ab05df6e380e | 23 | message.len=1; |
alex_clin | 0:ab05df6e380e | 24 | message.data[0] = boutons; |
alex_clin | 0:ab05df6e380e | 25 | printf("message : %d\n", message.data[0]); |
alex_clin | 0:ab05df6e380e | 26 | CanPort.write(message); |
alex_clin | 0:ab05df6e380e | 27 | |
alex_clin | 0:ab05df6e380e | 28 | wait(1); |
alex_clin | 0:ab05df6e380e | 29 | |
alex_clin | 0:ab05df6e380e | 30 | } |
alex_clin | 0:ab05df6e380e | 31 | } |
alex_clin | 0:ab05df6e380e | 32 | |
alex_clin | 0:ab05df6e380e | 33 | |
alex_clin | 0:ab05df6e380e | 34 | |
alex_clin | 0:ab05df6e380e | 35 | int main() { |
alex_clin | 0:ab05df6e380e | 36 | |
alex_clin | 0:ab05df6e380e | 37 | // init can |
alex_clin | 0:ab05df6e380e | 38 | //CanPort.attach(canReader,CAN::RxIrq); |
alex_clin | 0:ab05df6e380e | 39 | CanPort.frequency(20000); |
alex_clin | 0:ab05df6e380e | 40 | |
alex_clin | 0:ab05df6e380e | 41 | // init touchSensor |
alex_clin | 0:ab05df6e380e | 42 | touch_pad.init(); |
alex_clin | 0:ab05df6e380e | 43 | touch_pad.enable(); |
alex_clin | 0:ab05df6e380e | 44 | |
alex_clin | 0:ab05df6e380e | 45 | threadEnvoi.start(envoi); |
alex_clin | 0:ab05df6e380e | 46 | |
alex_clin | 0:ab05df6e380e | 47 | while(1){ |
alex_clin | 0:ab05df6e380e | 48 | // fonctionnement sur isr timer |
alex_clin | 0:ab05df6e380e | 49 | }; |
alex_clin | 0:ab05df6e380e | 50 | } |