#include//for v1.6/******************************************************************* set pins connected to PS2 controller: *设置连接到PS2控制器的引脚:* - 1e column: original* - 2e colmun: Stef?* replace pin numbers by the ones you use *用您使用的密码替换密码******************************************************************/// ESP32 pin // https://github.com/espressif/arduino-esp32/blob/master/docs/esp32_pinmap.png#define PS2_DAT 19 //MISO #define PS2_CMD 23 //MOSI #define PS2_SEL 5 //SS #define PS2_CLK 18 //SLK/******************************************************************* select modes of PS2 controller: *选择PS2控制器的模式:* - pressures = analog reading of push-butttons* - rumble = motor rumbling* uncomment 1 of the lines for each mode selection******************************************************************/ #define pressures false #define rumble falsePS2X ps2x;// create PS2 Controller Class //创建PS2控制器类//right now, the library does NOT support hot pluggable controllers, meaning //目前,该库不支持热插拔控制器,这意味着 //you must always either restart your Arduino after you connect the controller, //您必须始终在连接控制器后重新启动Arduino, //or call config_gamepad(pins) again after connecting the controller. //或在连接控制器后再次调用config_gamepad(pins)。int error =-1; byte type =0; byte vibrate =0; int tryNum =1;voidsetup(){// 115200Serial.begin(115200);//added delay to give wireless ps2 module some time to startup, before configuring it //添加了延迟,以使无线ps2模块在配置之前有一些启动时间//CHANGES for v1.6 HERE!!! **************PAY ATTENTION************* //此处已更改v1.6 !!!**************请注意*************while(error !=0){delay(1000);// 1 second wait//setup pins and settings: GamePad(clock, command, attention, data, Pressures?, Rumble?) check for error //设置引脚和设置:GamePad(clock, command, attention, data, Pressures?, Rumble?)检查错误error = ps2x.config_gamepad(PS2_CLK, PS2_CMD, PS2_SEL, PS2_DAT, pressures, rumble);Serial.print("#try config ");Serial.println(tryNum);tryNum ++;}Serial.println(ps2x.Analog(1), HEX);type = ps2x.readType();switch(type){case0:Serial.println(" Unknown Controller type found ");break;case1:Serial.println(" DualShock Controller found ");break;case2:Serial.println(" GuitarHero Controller found ");break;case3:Serial.println(" Wireless Sony DualShock Controller found ");break;} }voidloop(){if(type ==1){//DualShock Controllerps2x.read_gamepad(false, vibrate);//read controller and set large motor to spin at 'vibrate' speed //读取控制器并设置大型电机以“振动”速度旋转//will be TRUE as long as button is pressed //只要按下按钮就为TRUEif(ps2x.Button(PSB_START))Serial.println("Start is being held");if(ps2x.Button(PSB_SELECT))Serial.println("Select is being held");//will be TRUE as long as button is pressed //只要按下按钮就为TRUEif(ps2x.Button(PSB_PAD_UP)){Serial.print("Up held this hard: ");Serial.println(ps2x.Analog(PSAB_PAD_UP), DEC);}if(ps2x.Button(PSB_PAD_RIGHT)){Serial.print("Right held this hard: ");Serial.println(ps2x.Analog(PSAB_PAD_RIGHT), DEC);}if(ps2x.Button(PSB_PAD_LEFT)){Serial.print("LEFT held this hard: ");Serial.println(ps2x.Analog(PSAB_PAD_LEFT), DEC);}if(ps2x.Button(PSB_PAD_DOWN)){Serial.print("DOWN held this hard: ");Serial.println(ps2x.Analog(PSAB_PAD_DOWN), DEC);}vibrate = ps2x.Analog(PSAB_CROSS);//this will set the large motor vibrate speed based on how hard you press the blue (X) button //这将根据您按下蓝色(X)按钮的力度来设置大型电机的振动速度if(ps2x.NewButtonState()){//will be TRUE if any button changes state (on to off, or off to on) //如果任一按钮改变状态(开到关,或关到开)将是TRUEif(ps2x.Button(PSB_L3))Serial.println("L3 pressed");if(ps2x.Button(PSB_R3))Serial.println("R3 pressed");if(ps2x.Button(PSB_L2))Serial.println("L2 pressed");if(ps2x.Button(PSB_R2))Serial.println("R2 pressed");}//△□○×if(ps2x.Button(PSB_TRIANGLE))Serial.println("△ pressed");if(ps2x.ButtonPressed(PSB_CIRCLE))//will be TRUE if button was JUST pressed //如果按钮被按下,将是TRUESerial.println("○ just pressed");if(ps2x.NewButtonState(PSB_CROSS))//will be TRUE if button was JUST pressed OR released //如果按钮被按下或释放,将是TRUESerial.println("× just changed");if(ps2x.ButtonReleased(PSB_SQUARE))//will be TRUE if button was JUST released //如果按钮被释放,将是TRUESerial.println("□ just released");if(ps2x.Button(PSB_L1)|| ps2x.Button(PSB_R1)){//print stick values if either is TRUE //打印棒值如果任一为TRUESerial.print("Stick Values:");Serial.print(ps2x.Analog(PSS_LY));//Left stick, Y axis. Other options: LX, RY, RX //左摇杆,Y轴。其他选项:LX,RY,RXSerial.print(",");Serial.print(ps2x.Analog(PSS_LX), DEC);Serial.print(",");Serial.print(ps2x.Analog(PSS_RY), DEC);Serial.print(",");Serial.println(ps2x.Analog(PSS_RX), DEC);}}delay(50); }
在视频传输领域,MP4虽然常见,但在直播场景中直接使用MP4格式存在诸多问题。例如,MP4文件的头部信息(如ftyp、moov)较大,导致初始加载时间较长,影响用户体验。相比之下,HLS(HTTP Live Streaming)协议及其M3U8格式更具优势。HLS通过将视频切分成多个小片段,并生成一个M3U8播放列表文件,实现低延迟和高稳定性。本文详细介绍了如何将TS文件转换为M3U8直播流,包括技术原理和具体操作步骤,帮助读者更好地理解和应用这一技术。 ...
[详细]