Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed
Fork of PS3conOut by
User.cpp
- Committer:
- ideguti
- Date:
- 2015-05-18
- Revision:
- 1:7b9e3032bb7b
- Parent:
- 0:0805c5a1b328
- Child:
- 3:4d19e16fdf4c
File content as of revision 1:7b9e3032bb7b:
#include <math.h> #include "Utils.h" #include "USBHost.h" #include "hci.h" #include "ps3.h" #include "TestShell.h" #include "User.h" #include "caninit.h" #include "mbed.h" #ifndef M_PI #define M_PI 3.14159265f #endif #ifdef common #define ab 15 #define buf 14 #define ga 13 #define shdn 12 #define LSXcent 128 #define LSYcent 128 #define RSXcent 128 #define RSYcent 128 //Ticker ticker1; //Timer timer1; SPI slave(p5, p6, p7); CAN can1(p9, p10); CANMessage msg; // pin settings //DigitalOut air1(p5); //DigitalOut air2(p6); //SPI settings// //SPI spi(p11,p12,p13); //DigitalOut ss1(p20); //DigitalOut ss2(p19); //DigitalOut ss3(p18); //DigitalOut ss4(p17); //PINsettings //DigitalOut ldac1(p21); //DigitalOut ldac2(p22); //DigitalOut ldac3(p23); //DigitalOut ldac4(p24); // LED settings// DigitalOut led1(LED1); DigitalOut led2(LED2); DigitalOut led3(LED3); DigitalOut led4(LED4); // int serial_counter = 0; int dac_data=0; double debug_val = 0, debug_val2 = 0; double real_val[4] = {}; double tar_val[4] = {}; double val[4] = {}; int send_val[4] = {}; double c_accel=5000; char teisu=13;//23; char can_send_data[8]; int con_x; int con_y; int con_theta; double val_ratio, math1; double sai_time[5]={}, sai_hensa[5]={}; long angle_ulong; float raw_angle; float angle; float axis_angle = 0; double sin2, cos2; float kitai_angle = 0; bool caninit_triger = 0; int can_counter = 0; double avr_accel_x, avr_accel_y; // u8 RSX,RSY,LSX,LSY,BSU,BSL; //コントローラ断線時対策用 u8 accel[5]; u8 accel_nowsub=0; ////////// char cnt=0; void UserLoopSetting(){ //spi.format(16,0); //spi.frequency(1000000);//1M /* ss1=1; ss2=1; ss3=1; ss4=1; ldac1=1; ldac2=1; ldac3=1; ldac4=1; */ can1.frequency(125000); slave.format(16,0); slave.frequency(1000000); } void UserLoop(char n,const u8* data){ //PS3conSTATE--->value u16 ButtonState; char Send_data[8] = {}; u16 spi_send_data[10] = {}; if(n==0){//有線Ps3USB.cpp RSX = ((ps3report*)data)->RightStickX; RSY = ((ps3report*)data)->RightStickY; LSX = ((ps3report*)data)->LeftStickX; LSY = ((ps3report*)data)->LeftStickY; BSU = (u8)(((ps3report*)data)->ButtonState & 0x00ff); BSL = (u8)(((ps3report*)data)->ButtonState >> 8); //ボタンの処理 ButtonState = ((ps3report*)data)->ButtonState; }else {//無線TestShell.cpp RSX = ((ps3report*)(data + 1))->RightStickX; RSY = ((ps3report*)(data + 1))->RightStickY; LSX = ((ps3report*)(data + 1))->LeftStickX; LSY = ((ps3report*)(data + 1))->LeftStickY; BSU = (u8)(((ps3report*)(data + 1))->ButtonState & 0x00ff); BSL = (u8)(((ps3report*)(data + 1))->ButtonState >> 8); //ボタンの処理 ButtonState = ((ps3report*)(data + 1))->ButtonState; } Send_data[0] = RSX; Send_data[1] = RSY; Send_data[2] = LSX; Send_data[3] = LSY; Send_data[4] = BSU; Send_data[5] = BSL; Send_data[6] = ButtonState & 0xFF; Send_data[7] = (ButtonState >> 8) & 0xFF; can1.write(CANMessage(100, &Send_data[0], 8)); static int can1_counter = 0; can1_counter ++; if(can1_counter > 100){ led1 = !led1; can1_counter = 0; } /* spi_send_data[0] = ButtonState; spi_send_data[1] = RSX; spi_send_data[1] = (spi_send_data[1] << 8) & 0xFF00; spi_send_data[1] = spi_send_data[1] | RSY; spi_send_data[2] = RSX; spi_send_data[2] = (spi_send_data[2] << 8) & 0xFF00; spi_send_data[2] = spi_send_data[2] | RSY; */ /* if(slave.receive()){ int recive = slave.read(); switch(recive){ case 1: slave.reply(spi_send_data[0]); break; case 2: slave.reply(spi_send_data[1]); break; case 3: slave.reply(spi_send_data[2]); break; } } */ //slave.write(1); //can1.read(msg); //CAN読み取り //LRの処理 serial_counter ++; #ifdef DEBUG_MODE if(serial_counter > REFRESHRATE_PRINTF){ printf("angle %f",angle*180/M_PI); printf("\t avr_accel_x %f",avr_accel_x); printf("\t math1 %f",math1); printf("\t c_accel %f",c_accel); //printf("\t con_rtheta %f",con_rtheta*180/M_PI); printf("\t kitai_angle %f",kitai_angle*180/M_PI); printf("\n"); printf("data[0] %f",val[0]); printf("\t"); printf("data[1] %f",val[1]); printf("\t"); printf("data[2] %f",val[2]); printf("\t"); printf("data[3] %f",val[3]); printf("\n"); serial_counter = 0; } #endif #endif }