1

我已经在运行流畅的树莓派 b+ 上成功构建和编译了 JUCE。现在我正在尝试在 JUCE 中使用带有旋钮/旋转编码器的 WiringPi 在液晶显示器上显示文本。一切正常,但是当我尝试在我的 juce 应用程序中调用wiringPi 函数时,我得到wiringPi 的“未定义引用错误”。

我的问题是,我如何同时构建 WiringPi 和 Juce,以便我可以在 JUCE 中调用 WiringPi 方法/函数。下面是我的代码片段

这是我得到的错误:

Source/SynthUsingMidiInputTutorial_01.h:114: undefined reference to `wiringPiSetup'
Source/rotary_encoder.h:40: undefined reference to `digitalRead'
Source/SynthUsingMidiInputTutorial_01.h:122: undefined reference to `pinMode'
Source/SynthUsingMidiInputTutorial_01.h:125: undefined reference to `pullUpDnControl'

源代码:

//SynthUsingMidiInputTutorial_01.h
#include "rotary_encoder.h"

class SynthAudioSource : public AudioSource
{
public:
SynthAudioSource (MidiKeyboardState& keyState)
: keyboardState (keyState)
{
    // add voices to our sampler
    for (int i = 0; i < MAX_VOICES; i++)
    {
        synth.addVoice(new SamplerVoice());
    }

    // set up our AudioFormatManager class as detailed in the API docs
    audioFormatManager.registerBasicFormats();
    // now that we have our manager, lets read a simple file so we can pass it to our SamplerSound object.
    File* file1 = new File("bass.wav");
    ScopedPointer<AudioFormatReader> reader1 = audioFormatManager.createReaderFor(*file1);
    File* file2 = new File("lead.wav");
    ScopedPointer<AudioFormatReader> reader2 = audioFormatManager.createReaderFor(*file2);
    File* file3 = new File("organ.wav");
    ScopedPointer<AudioFormatReader> reader3 = audioFormatManager.createReaderFor(*file3);
    BigInteger notes;

    notes.setRange (0, 1, true);
    SamplerSound::Ptr sound1 = new SamplerSound ("xx1", *reader1, notes, 0, 0.0, 1.0, 10.0);
    synth.addSound (sound1);
    BigInteger notes2;
    notes2.setRange (1, 1, true);
    SamplerSound::Ptr sound2 = new SamplerSound ("xx2", *reader2, notes2, 0, 0.0, 1.0, 10.0);

    synth.addSound (sound2);
    BigInteger notes3;
    notes3.setRange (2, 1, true);
    SamplerSound::Ptr sound3 = new SamplerSound ("xx3", *reader3, notes3, 0, 0.0, 1.0, 10.0);

    synth.addSound (sound3);
    int lcd;                //Handle for LCD
    wiringPiSetup();        //Initialise WiringPi

    //Initialise LCD
    if (lcd = lcdInit (2, 16,4, LCD_RS, LCD_E ,LCD_D4 , LCD_D5, LCD_D6,LCD_D7,0,0,0,0))
    {
        std::cout << "LcdInit failed!:";
    }

    pinMode(SwitchPin, INPUT);
    pinMode(RotateAPin, INPUT);
    pinMode(RotateBPin, INPUT);
    pullUpDnControl(SwitchPin, PUD_UP);

    if (wiringPiISR(SwitchPin, INT_EDGE_FALLING, &btnISR) < 0) 
    {
        cout << "Unable to init ISR" << endl;
    }

    int tmp = 0;
    while (1) 
    {
        rotaryDeal();
        if (tmp != globalCounter) 
        {
            tmp = globalCounter;
            if(globalCounter >= 10)
            break;
        }    
    }

    lcdPosition(lcd,0,0);           //Position cursor on the first line in the first column
    lcdPuts(lcd, "Lead Bass:");  //Print the text on the LCD at the current cursor postion
}

和:

//rotary_encoder.h
#include <wiringPi>

static volatile int globalCounter = 0;
unsigned char flag;
unsigned char Last_RoB_Status;
unsigned char Current_RoB_Status;

void btnISR(void) 
{
    globalCounter = 0;
}

void rotaryDeal() 
{
    Last_RoB_Status = digitalRead(RotateBPin);
    while (!digitalRead(RotateAPin))
    {
        Current_RoB_Status = digitalRead(RotateBPin);
        flag = 1;
    }
    if (flag == 1)
    {
        flag = 0;
        if ((Last_RoB_Status == 0) && (Current_RoB_Status == 1)) 
        {
            globalCounter++;
        }
        if ((Last_RoB_Status == 1) && (Current_RoB_Status == 0)) {
            globalCounter--;
        }
    }
}
4

0 回答 0