0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

ESP32-S2開発機でALLONE アローン PC用コントローラー ALG-PCCBKで遊ぶ(2 end)。

0
Last updated at Posted at 2026-09-17

参考

いろいろ注意

  • 過去ログを見るべし!!!

結果

image_original(155).jpg

Screenshot From 2026-09-18 06-13-21.png

(A)

Screenshot From 2026-09-18 06-15-11.png

(UE)

Screenshot From 2026-09-18 06-16-27.png

プログラム



//インクルド
#include <Arduino.h>     //arduino標準
#include "EspUsbHost.h"  //USB関連


//定義
EspUsbHost usb;  //USB関連


//bit
static void printBit(int c) {

  Serial.printf("%02x ", c);


  int b0, b1, b2, b3, b4, b5, b6, b7;

  b0 = c & 0x01;
  c = c >> 1;
  b1 = c & 0x01;
  c = c >> 1;
  b2 = c & 0x01;
  c = c >> 1;
  b3 = c & 0x01;
  c = c >> 1;
  b4 = c & 0x01;
  c = c >> 1;
  b5 = c & 0x01;
  c = c >> 1;
  b6 = c & 0x01;
  c = c >> 1;
  b7 = c & 0x01;

  Serial.print(b7);  //^
  Serial.print(b6);  //_
  Serial.print(b5);  //<-
  Serial.print(b4);  //->

  Serial.print(b3);  //y
  Serial.print(b2);  //x
  Serial.print(b1);  //b
  Serial.print(b0);  //a

  Serial.print(' ');

}  //printBit


//初期化
void setup() {

  //シリアルの初期化
  Serial.begin(115200);
  delay(500);
  Serial.print("\n\nSTART\n\n");  //caa45040
  delay(3000);                    //caa45040


  //ゲームパッドからのイベントいろいろ (ゲームパッドのボタンが押されたら)
  usb.onHIDInput([](const EspUsbHostHIDInput &input) {
    // en: Example mapping. Replace VID/PID and usage choices with your controller.
    // ja: マッピング例です。VID/PIDとusageの選択はコントローラーに合わせて置き換えてください。
    if (input.vid == 0x0079 && input.pid == 0x181c && input.length == 11) {  //caa45040


      int c = 0x00;
      int a;

      //a

      a = (input.data[6]) & 0x01;
      c = c | a;

      //b

      a = (input.data[6]) & 0x02;
      c = c | a;

      //x

      a = ((input.data[6]) >> 1) & 0x04;
      c = c | a;

      //y

      a = ((input.data[6]) >> 1) & 0x08;
      c = c | a;

      //十字キー

      static int pad_bitmap[] = {
        0b10000000,  //0 ^
        0b10010000,  //1
        0b00010000,  //2 ->
        0b01010000,  //3

        0b01000000,  //4 _
        0b01100000,  //5
        0b00100000,  //6 <-
        0b10100000,  //7

        0x00,  //8
        0x00,  //9
        0x00,  //10
        0x00,  //11

        0x00,  //12
        0x00,  //13
        0x00,  //14
        0x00   //15 0x0f
      };

      a = pad_bitmap[(input.data[5]) & 0x0f];
      c = c | a;


      printBit(c);

      // en: Raw HID input fires before any keyboard/mouse/vendor-specific parsing.
      // ja: Raw HID入力は、キーボード/マウス/ベンダー固有の解析前に通知されます。
      espUsbHostPrint(input);

    }  //end-if
  });


  //ゲームパッドの接続イベント
  usb.onDeviceConnected([](const EspUsbHostDeviceInfo &device) {
    Serial.print("connected: ");
    espUsbHostPrint(device);
  });


  //ゲームパッドの切断イベント
  usb.onDeviceDisconnected([](const EspUsbHostDeviceInfo &device) {
    Serial.print("disconnected: ");
    espUsbHostPrint(device);
  });


  //USBの開始
  if (!usb.begin()) {  //失敗か?
    Serial.printf("usb.begin() failed: %s\n", usb.lastErrorName());
  } else {
    Serial.printf("usb.begin() OK\n");
  }  //end-if USB //caa45040

  delay(1000);  //caa45040

}  //setup


//メインループ
void loop() {

  delay(1);  //ダミー  //caa45040

}  //loop



0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?