не называет ошибку типа, используя 2 библиотеки [решено] - PullRequest
0 голосов
/ 10 июля 2019

Редактировать: это работает!я столкнулся с другой проблемой, сказав, что он не может скомпилировать для Uno, но я исправил ее, и она работает!

Я пытаюсь создать последовательный фидер Vjoy из контроллера PS2, используя arduino uno r3.Я получаю сообщение об ошибке «ibus не называет тип» в моем коде (который должен быть написан плохо), и я понятия не имею, что искать.Для этого я использую 2 библиотеки: ps2x: https://github.com/madsci1016/Arduino-PS2X, для получения входных данных от контроллера ps2

VjoySerialFeeder: https://github.com/Cleric-K/vJoySerialFeeder, для отправки этих входов через последовательный порт на приложение фидераэмулировать работающий контроллер для ПК.

Похоже, проблема связана с VjoySerialFeeder и его классом IBus.

Вот мой код:

    #include <PS2X_lib.h> // Bill Porter's PS2 Library
#include <ibus.h>

// //////////////////
// Edit here to customize

// How often to send data?
#define UPDATE_INTERVAL 10 // milliseconds


// 1. Analog channels. Data can be read with the Arduino's 10-bit ADC.
// This gives values from 0 to 1023.
// Specify below the analog pin numbers (as for analogRead) you would like to use.
// Every analog input is sent as a single channel.
#define NUM_ANALOG_INPUTS 4
byte analogPins[] = {0, 1, 2, 3}; // element count MUST be == NUM_ANALOG_INPUTS


// 2. Digital channels. Data can be read from Arduino's digital pins.
// They could be either LOW or HIGH.
// Specify below the digital pin numbers (as for digitalRead) you would like to use.
// Every pin is sent as a single channel. LOW is encoded as 0, HIGH - as 1023


// 3. Digital bit-mapped channels. Sending a single binary state as a 16-bit
// channel is pretty wasteful. Instead, we can encode one digital input
// in each of the 16 channel bits.
// Specify below the digital pins (as for digitalRead) you would like to send as
// bitmapped channel data. Data will be automatically organized in channels.
// The first 16 pins will go in one channel (the first pin goes into the LSB of the channel).
// The next 16 pins go in another channel and so on
// LOW pins are encoded as 0 bit, HIGH - as 1.


// Define the appropriate analog reference source. See
// https://www.arduino.cc/reference/en/language/functions/analog-io/analogreference/
#define ANALOG_REFERENCE DEFAULT

// Define the baud rate
#define BAUD_RATE 115200

// /////////////////





#define NUM_CHANNELS ( (NUM_ANALOG_INPUTS) )

PS2X ps2x;  //The PS2 Controller Class

#define PS2_DAT        8  //14    
#define PS2_CMD        11  //15
#define PS2_SEL        10  //16
#define PS2_CLK        12  //17

void setup()
{
  ps2x.config_gamepad(PS2_CLK, PS2_CMD, PS2_SEL, PS2_DAT, false, false);

  analogReference(ANALOG_REFERENCE); // use the defined ADC reference voltage source
  Serial.begin(BAUD_RATE); // setup serial
}
IBus ibus(NUM_CHANNELS);
void loop()
{
  int i, bm_ch = 0;
  unsigned long time = millis();
  ps2x.read_gamepad(); //This needs to be called at least once a second

  int PlyStn[] = {ps2x.Analog(PSS_RY), ps2x.Analog(PSS_RX), ps2x.Analog(PSS_LY), ps2x.Analog(PSS_LX)}; //Left Stick Left and Right


  ibus.begin();

  // read analog pins - one per channel
  for (i = 0; i < NUM_ANALOG_INPUTS; i++)
    ibus.write(analogRead(PlyStn[i]));

  // read digital pins - one per channel

  // read digital bit-mapped pins - 16 pins go in one channel

}

ibus.end();

time = millis() - time; // time elapsed in reading the inputs
if (time < UPDATE_INTERVAL)
  // sleep till it is time for the next update
  delay(UPDATE_INTERVAL  - time);
}

Вот ibus.cpp

#include "Arduino.h"
#include "ibus.h"

/*
 * See IbusReader.cs for details about the IBUS protocol
 */

#define COMMAND40 0x40

IBus::IBus(int numChannels) {
  len = 4 + numChannels*2;
}

void IBus::begin() {
  checksum = 0xffff - len - COMMAND40;
  Serial.write(len);
  Serial.write(COMMAND40);
}

void IBus::end() {
  // write checksum
  Serial.write(checksum & 0xff);
  Serial.write(checksum >> 8);
}

/*
 * Write 16bit value in little endian format and update checksum
 */
void IBus::write(unsigned short val) {
  byte b = val & 0xff;
  Serial.write(b);
  checksum -= b;
  b = val >> 8;
  Serial.write(b);
  checksum -= b;
}

и ibus.h:

#pragma once

class IBus {
  private:
    int len;
    int checksum;
  public:
    IBus(int numChannels);

    void begin();
    void end();
    void write(unsigned short);

};

Если у вас есть идеи, откуда может возникнуть эта ошибка, извините, если это простое решение, я действительно потерян здесь.

Большое спасибо.

...