Oscar de Jesus Vasquez
/
USBHID_TestCase_LV
-----
Fork of USBHID_TestCase by
Diff: main.cpp
- Revision:
- 5:c18b39f0db84
- Parent:
- 4:a5fa0d7873b4
--- a/main.cpp Thu Sep 11 18:42:31 2014 +0000 +++ b/main.cpp Tue Nov 25 17:44:52 2014 +0000 @@ -1,34 +1,121 @@ #include "mbed.h" #include "USBHID.h" - -//We declare a USBHID device. Input out output reports have a length of 8 bytes -USBHID hid(1, 1); -BusOut a(p13,p14,p15,p16,p17,p18,p19,p20); - -//This report will contain data to be sent + + +//Definicion de los buffer de envio y recepcion +USBHID hid(8,8); + +//Reportes de envio +HID_REPORT recv_report; HID_REPORT send_report; -HID_REPORT recv_report; -uint8_t n; -int main(void) -{ - + + +//Definicion del bus para PORTS +BusInOut PA(p30,p29,p28,p27,p26,p25,p24,p23); +BusInOut PB(p5,p6,p7,p8,p9,p10,p11,p12); + +//Declaracion de los pines analogicos +AnalogIn ana0(p17); +AnalogIn ana1(p19); +AnalogIn ana2(p20); + +//Declaracion de PWM +PwmOut PWM0(LED1); +PwmOut PWM1(LED2); +PwmOut PWM2(LED3); +PwmOut PWM3(LED4); -send_report.length = 1; +//Variables para el seccionamiento de los analogicos +uint8_t an0div[2]; +uint8_t an1div[2]; +uint8_t an2div[2]; + +int main(void) { + +//Buffer para guardar los analogicos en lectura +uint16_t ana0buff = 0; +uint16_t ana1buff = 0; +uint16_t ana2buff = 0; - while (1) +send_report.length = 8; +recv_report.length = 8; + +while (1) +{ + + + //Seleccioanador de caso para Bus IN/OUT en PA + if (hid.readNB(&recv_report)) { - - if(hid.readNB(&recv_report)) + if(recv_report.data[0]==1) + { + PA.output(); + PA.write(recv_report.data[1]) ; + } + else { - for(int i = 0; i < recv_report.length; i++) - { - hid.send(&recv_report); - a=recv_report.data[0]; - - - } - } + PA.input(); + send_report.data[0] = PA.read(); + hid.send(&send_report); + } + + + + if(recv_report.data[6]==1) + { + PB.output(); + PB.write(recv_report.data[7]) ; + } + else + { + PB.input(); + send_report.data[7] = PB.read(); + hid.send(&send_report); + } + + + + + } + //Lectura del 1er Analogico + if (ana0.read() != ana0buff) + { + ana0buff = ana0.read()*4096; + an0div[0]=ana0buff & 0xff; + an0div[1]=(ana0buff >> 8); + send_report.data[1] = an0div[0]; + send_report.data[2] = an0div[1]; + hid.send(&send_report); + } + + //Lectura del 2do Analogico + if (ana1.read() != ana1buff) + { + ana1buff = ana1.read()*4096; + an1div[0]=ana1buff & 0xff; + an1div[1]=(ana1buff >> 8); + send_report.data[3] = an1div[0]; + send_report.data[4] = an1div[1]; + hid.send(&send_report); } + //Lectura del 3er Analogico + if (ana2.read() != ana2buff) + { + ana2buff = ana2.read()*4096; + an2div[0]=ana2buff & 0xff; + an2div[1]=(ana2buff >> 8); + send_report.data[5] = an2div[0]; + send_report.data[6] = an2div[1]; + hid.send(&send_report); + } + + PWM0.write(float(recv_report.data[2])/255); + PWM1.write(float(recv_report.data[3])/255); + PWM2.write(float(recv_report.data[4])/255); + PWM3.write(float(recv_report.data[5])/255); + + } + } \ No newline at end of file