TeensyVariablePlayback library could not compiled with keypad library

charnjit

Well-known member
Am sorry to raise issue again. I don't want disturb you all . But After many efforts I learnt that a problem in
TeensyVariablePlayback library in my
Post .
There is something wrong in library, which is reason of error with keypad code.
Could you please reply if it can be solved by editing in any.h or.cpp file of library or request to TeensyVariablePlayback library developers to fix it ...
Thank you
 
You are right this is yet another duplicate post...

Isn't this maybe the third different thread?

The first recent thread was by @graydetroit

As jmarsh mentioned in another of your threads:
This is a problem with the TeensyVariablePlayback code, it has "using namespace std;" in a header which causes type collisions.

Could you please reply if it can be solved by editing in any.h or.cpp file of library or request to TeensyVariablePlayback library developers to fix it ...
Thank you
Of course it can be fixed... It's just code. What have you tried?

a) Have you contacted the owner of the library? I don't see any new issues raised in the library:

b) Have you tried simply to comment out the using namespace std line in waveheaderParser.h?
Code:
#ifndef TEENSY_RESAMPLING_SDREADER_WAVEHEADERPARSER_H
#define TEENSY_RESAMPLING_SDREADER_WAVEHEADERPARSER_H

#include <string>
#include <cstdint>
#include <SD.h>
#include "spi_interrupt.h"

//using namespace std;
The one example I tried sd_play_all appeared to still be able to compile. No idea if it runs and/or other examples that
may or may not compile...

c) Don't include/use both libraries in the same source file. That is, you could create your own header and cpp files in your project
that includes for example only the keypad library and potentially exposes your own APIS or the like, that is used in your main code.

d) edit the keypad library and change all byte variables to uint8_t like mentioned in the other thread.

...
 
You are right this is yet another duplicate post...

Isn't this maybe the third different thread?

The first recent thread was by @graydetroit

As jmarsh mentioned in another of your threads:



Of course it can be fixed... It's just code. What have you tried?

a) Have you contacted the owner of the library? I don't see any new issues raised in the library:

b) Have you tried simply to comment out the using namespace std line in waveheaderParser.h?
Code:
#ifndef TEENSY_RESAMPLING_SDREADER_WAVEHEADERPARSER_H
#define TEENSY_RESAMPLING_SDREADER_WAVEHEADERPARSER_H

#include <string>
#include <cstdint>
#include <SD.h>
#include "spi_interrupt.h"

//using namespace std;
The one example I tried sd_play_all appeared to still be able to compile. No idea if it runs and/or other examples that
may or may not compile...

c) Don't include/use both libraries in the same source file. That is, you could create your own header and cpp files in your project
that includes for example only the keypad library and potentially exposes your own APIS or the like, that is used in your main code.

d) edit the keypad library and change all byte variables to uint8_t like mentioned in the other thread.

...
a) i did not contact to library owner, before contact , i am searching threads..
b) i have no line
Code:
// using namespace std;
in my sketch.
i also tried comment out last lines.
Code:
//namespace std {
  //  void __throw_bad_function_call() {}
   // void __throw_length_error(char const*) {}
//}
c) i did not understand . which both libraries are included in same Source code ????please describe..
d) i also edit byte variables to uint8_t ,
Code:
#include <Bounce.h>
#include <Arduino.h>
#include <Audio.h>
#include <SD.h>
#include <TeensyVariablePlayback.h>
#include <Keypad.h>              //   working   4x7 keypad and oled Display
#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>

// GUItool: begin automatically generated code
AudioPlaySdResmp         playSdWav1;     //xy=324,457
AudioOutputI2S           i2s2;           //xy=840.8571472167969,445.5714416503906
AudioConnection          patchCord1(playSdWav1, 0, i2s2, 0);
AudioConnection          patchCord2(playSdWav1, 0, i2s2, 1);
AudioControlSGTL5000     audioShield;
// GUItool: end automatically generated code

#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 32 // OLED display height, in pixels

#define OLED_RESET     -1
#define SCREEN_ADDRESS 0x3C ///< See datasheet for Address; 0x3D for 128x64, 0x3C for 128x32
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);

uint8_t ROWS = 7; // 7 rows
uint8_t COLS = 4; //4 columns    //   Analog pin_22 ,  Enc (2,3)  ,   
char keys[ROWS][COLS] = {
{1,2,3,4},
{5,6,7,8},
{9,10,11,12},
{13,14,15,16},
{17,18,19,20},
{21,22,23,24},
{25,26,27,28}
};
uint8_t rowPins[ROWS] = {33,34,35,36,37,38,39}; //connect to the row pinouts of the kpd
uint8_t colPins[COLS] = {40,41,14,16}; //connect to the column pinouts of the kpd

Keypad kpd = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );


String msg;


  float Speed = 1.00;
 
void setup() {


    Serial.begin(57600);

          if(!display.begin(SSD1306_SWITCHCAPVCC, SCREEN_ADDRESS)) {
    Serial.println(F("SSD1306 allocation failed"));
    for(;;); // Don't proceed, loop forever
  }
    display.display();
    delay(2000);
    display.clearDisplay();
    msg = "";

    if (!(SD.begin(BUILTIN_SDCARD))) {
        while (1) {
            Serial.println("Unable to access the SD card");
            delay(500);
        }
    }

    AudioMemory(24);
    audioShield.enable();
    audioShield.volume(0.5);
    playSdWav1.enableInterpolation(true);

}

void loop() {

    if (kpd.getKeys())
    {
        for (int i=0; i<LIST_MAX; i++)   // Scan the whole key list.
        {   int mykey = (kpd.key[i].kchar);

                      if ( kpd.key[i].stateChanged ) //  ---------------------------------------------------------
            {    switch (kpd.key[i].kstate) {
                    case PRESSED:
                  msg = "  is presed";   SCN_MAIN (mykey);  Serial.println(mykey);  Serial.println("pressed");
                break;
                    case RELEASED:
                    msg = "  is Released";   SCN_MAIN (mykey);   Serial.println(mykey);  Serial.println("releassed");
                break;
                } }  //-----------------------------------------------------------------------------------------------------
           }  }
      
       // -------------------------------------------------------
   if (Serial.available() > 0) {
    int incomingByte = Serial.read();
    if (incomingByte == 49) {                           // key 1
                                   Speed = Speed + 0.01;
                                   playSdWav1.setPlaybackRate(Speed);   
                                   Serial.println(Speed);
                                   }
     if (incomingByte == 50) {                               //  key 2
                                  Speed = Speed - 0.01;   
                                  playSdWav1.setPlaybackRate(Speed);   
                                  Serial.println(Speed);
                                  }   
      if (incomingByte == 51) {                                // key 3
                                  playSdWav1.playWav("13.WAV");
                                   playSdWav1.setLoopType(looptype_repeat);   
                                  Serial.println("Playing 13.wav in loop mode");   
                                 }
       if (incomingByte == 52) {                                         // key 4
                                
                                 Serial.println("stopped");   
                                 playSdWav1.stop();
                                }
     if (incomingByte == 53) {                                        // key5
                               playSdWav1.setPlaybackRate(Speed);   
                             Serial.println("speed 1.00");   
                             }   
  }      // ------------------------------------------------------
 
}


//namespace std {
  //  void __throw_bad_function_call() {}
   // void __throw_length_error(char const*) {}
//}

void SCN_MAIN (int number) {
       display.clearDisplay();
       display.setTextSize(1);      // Normal 1:1 pixel scale
       display.setTextColor(SSD1306_WHITE); // Draw white text
       display.setCursor(0, 0);     // Start at top-left corner
       display.print(number);  display.print(msg);
       display.display();
}
but got error
Code:
Multiple libraries were found for "Audio.h"
 Used: C:\Program Files\Arduino\hardware\teensy\avr\libraries\Audio
 Not used: C:\Users\acer\Documents\Arduino\libraries\Audio-feature-buffered-SD
Multiple libraries were found for "SD.h"
 Used: C:\Program Files\Arduino\hardware\teensy\avr\libraries\SD
 Not used: C:\Program Files\Arduino\libraries\SD
Multiple libraries were found for "Keypad.h"
 Used: C:\Program Files\Arduino\hardware\teensy\avr\libraries\Keypad
 Not used: C:\Users\acer\Documents\Arduino\libraries\Keypad-3.1.1
Using library Bounce in folder: C:\Program Files\Arduino\hardware\teensy\avr\libraries\Bounce (legacy)
Using library Audio at version 1.3 in folder: C:\Program Files\Arduino\hardware\teensy\avr\libraries\Audio
Using library SPI at version 1.0 in folder: C:\Program Files\Arduino\hardware\teensy\avr\libraries\SPI
Using library SD at version 2.0.0 in folder: C:\Program Files\Arduino\hardware\teensy\avr\libraries\SD
Using library SdFat at version 2.1.2 in folder: C:\Program Files\Arduino\hardware\teensy\avr\libraries\SdFat
Using library SerialFlash at version 0.5 in folder: C:\Program Files\Arduino\hardware\teensy\avr\libraries\SerialFlash
Using library TeensyVariablePlayback at version 1.0.16 in folder: C:\Users\acer\Documents\Arduino\libraries\TeensyVariablePlayback
Using library LittleFS at version 1.0.0 in folder: C:\Program Files\Arduino\hardware\teensy\avr\libraries\LittleFS
Using library Keypad at version 3.1.1 in folder: C:\Program Files\Arduino\hardware\teensy\avr\libraries\Keypad
Using library Wire at version 1.0 in folder: C:\Program Files\Arduino\hardware\teensy\avr\libraries\Wire
Using library Adafruit_GFX_Library at version 1.7.5 in folder: C:\Users\acer\Documents\Arduino\libraries\Adafruit_GFX_Library
Using library Adafruit_SSD1306 at version 2.5.7 in folder: C:\Users\acer\Documents\Arduino\libraries\Adafruit_SSD1306
size of array 'keys' is not an integral constant-expression
in line pink shaded
Code:
char keys[ROWS][COLS] = {
i also tried "uint8_t" and "int" .
but not solved.....
 
Code:
char keys[ROWS][COLS] = {
i also tried "uint8_t" and "int" .
but not solved.....
Different issue:
Code:
uint8_t ROWS = 7; // 7 rows
uint8_t COLS = 4; //4 columns    //   Analog pin_22 ,  Enc (2,3)  ,   
char keys[ROWS][COLS] = {
{1,2,3,4},
{5,6,7,8},
{9,10,11,12},
{13,14,15,16},
{17,18,19,20},
{21,22,23,24},
{25,26,27,28}
};
uint8_t rowPins[ROWS] = {33,34,35,36,37,38,39}; //connect to the row pinouts of the kpd
uint8_t colPins[COLS] = {40,41,14,16}; //connect to the column pinouts of the kpd
The compiler does not like you using ROWS and COLS in these defines as they are not constant and could be changed.
Two easy fixes for those:
Code:
#define ROWS 7
or
Code:
const uint8_t ROWS = 7; // 7 rows
(Obviously same for COLS)

With that change and the change to comment out the using namespace std
your posted sketch compiles
 
Alternative -
c) i did not understand . which both libraries are included in same Source code ????please describe..
Here is a quick and dirty which did not require any edits to any of the libraries.

I added two files to the sketch process_keypad.h and process_keypad.cpp - this file did not include
Code:
#include <TeensyVariablePlayback.h>
Header file has a couple of extern defines in it for things tht your main sketch could call, and to be quick and dirty,
things in the main sketch that the keypad function might call or use...
 

Attachments

  • sketch_nov4a-241104a.zip
    2.5 KB · Views: 23
Yes, my fork and branch (guessing OP may be using this) of the upstream repo needs to merge a few fixes, including the “using namespace” one.
 
Thank you kurtE ,
your .ino ,process_keypad.cpp, process_keypad.h file helped me to compile /upload my sketch.
but other thing,
when i write key 25 to get output in Serial monitor (in process_keypad.cpp),
Code:
 if ((kpd.key[i].stateChanged) && (mykey==25)) //  ---------------------------------------------------------
            {
                switch (kpd.key[i].kstate) {
                    case PRESSED:
                        break;
                    case RELEASED:
                     Serial.println("Key 25 Detected");
                        break;
                }
            }  //--------------------------------------------------------------------------------------------------
it is working .
but when i write key 25 to play "13.WAV"
Code:
 if ((kpd.key[i].stateChanged) && (mykey==25)) //  ---------------------------------------------------------
            {
                switch (kpd.key[i].kstate) {
                    case PRESSED:
                     playSdWav1.playWav("13.WAV");
            playSdWav1.setLoopType(looptype_repeat);
            Serial.println("Playing 13.wav in loop mode");
                        break;
                    case RELEASED:                
                        break;
                }
            }  //--------------------------------------------------------------------------------------------------
getting error
Code:
'playSdWav1' was not declared in this scope
i also can not write keypad functions in my main sketch, it also giving error 'was not declared in this scope' etc
please find more way
how to use below functions from [TeensyVariablePlayback] like​
Code:
            playSdWav1.playWav("13.WAV");
            playSdWav1.setLoopType(looptype_repeat);
            playSdWav1.setPlaybackRate(Speed);
            playSdWav1.stop();

from keypad input fastly
 
Yes - with c++ (.h .cpp) files, you can only reference those things that are defined in the source file or header files

Note: I have not used the keypad library or at least much so I can't give you the best code...

that were included in the source file. For example, you could simply have the .cpp file method:
Code:
void process_my_keypad() {
        if (kpd.getKeys()) {
        for (int i = 0; i < LIST_MAX; i++)  // Scan the whole key list.
        {
            int mykey = (kpd.key[i].kchar);

            if (kpd.key[i].stateChanged)  //  ---------------------------------------------------------
            {
                switch (kpd.key[i].kstate) {
                    case PRESSED:
                        msg = "  is presed";
                        SCN_MAIN(mykey);
                        Serial.println(mykey);
                        Serial.println("pressed");
                        break;
                    case RELEASED:
                        msg = "  is Released";
                        SCN_MAIN(mykey);
                        Serial.println(mykey);
                        Serial.println("releassed");
                        break;
                }
            }  //-----------------------------------------------------------------------------------------------------
        }
    }

}
to something like:
Code:
void process_my_keypad() {
        if (kpd.getKeys()) {
        for (int i = 0; i < LIST_MAX; i++)  // Scan the whole key list.
        {
            int mykey = (kpd.key[i].kchar);

            if (kpd.key[i].stateChanged)  //  ---------------------------------------------------------
            {
                switch (kpd.key[i].kstate) {
                    case PRESSED:
                        process_key_pressed(mykey);
                        break;
                    case RELEASED:
                        process_key_released(mykey);
                        break;
                }
            }  //-----------------------------------------------------------------------------------------------------
        }
    }

}
Define those two functions in your .ino file and add them to the header file, like:
Code:
extern void process_key_pressed(int mykey);
extern void process_key_released(int mykey);

And then you are free in those two functions to call/use anything defined in your main sketch file.
 
i use below code , see my full .cpp file
Code:
#include <Arduino.h>
#include <Keypad.h>  //   working   4x7 keypad and oled Display
#include "process_keypad.h"

const uint8_t ROWS = 7;  // 7 rows
const uint8_t COLS = 4;  //4 columns    //   Analog pin_22 ,  Enc (2,3)  ,
char keys[ROWS][COLS] = {
    { 1, 2, 3, 4 },
    { 5, 6, 7, 8 },
    { 9, 10, 11, 12 },
    { 13, 14, 15, 16 },
    { 17, 18, 19, 20 },
    { 21, 22, 23, 24 },
    { 25, 26, 27, 28 }
};
uint8_t rowPins[ROWS] = { 33, 34, 35, 36, 37, 38, 39 };  //connect to the row pinouts of the kpd
uint8_t colPins[COLS] = { 40, 41, 14, 16 };              //connect to the column pinouts of the kpd

Keypad kpd = Keypad(makeKeymap(keys), rowPins, colPins, ROWS, COLS);


void init_my_keypad() {
    // not sure if we need to do anything to initialize?
}

void process_my_keypad() {
        if (kpd.getKeys()) {
        for (int i = 0; i < LIST_MAX; i++)  // Scan the whole key list.
        {
            int mykey = (kpd.key[i].kchar);

            if (kpd.key[i].stateChanged)  //  ---------------------------------------------------------
            {
                switch (kpd.key[i].kstate) {
                    case PRESSED:
                        process_key_pressed(mykey);
                        break;
                    case RELEASED:
                        process_key_released(mykey);
                        break;
                }
            }  //--------------------------------------------------------------------------------------------------                  
        }
    }

}
and also added code to .h file , see my full .h file
Code:
extern void init_my_keypad();
extern void process_my_keypad();
extern void process_key_pressed(int mykey);
extern void process_key_released(int mykey);

// in main sketch
extern void SCN_MAIN(int number);
extern String msg;
and see my main sketch ..
Code:
#include <Bounce.h>
#include <Arduino.h>
#include <Audio.h>
#include <SD.h>
#include <TeensyVariablePlayback.h>
#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>

#include "process_keypad.h"

// GUItool: begin automatically generated code
AudioPlaySdResmp playSdWav1;  //xy=324,457
AudioOutputI2S i2s2;          //xy=840.8571472167969,445.5714416503906
AudioConnection patchCord1(playSdWav1, 0, i2s2, 0);
AudioConnection patchCord2(playSdWav1, 0, i2s2, 1);
AudioControlSGTL5000 audioShield;
// GUItool: end automatically generated code

#define SCREEN_WIDTH 128  // OLED display width, in pixels
#define SCREEN_HEIGHT 32  // OLED display height, in pixels

#define OLED_RESET -1
#define SCREEN_ADDRESS 0x3C  ///< See datasheet for Address; 0x3D for 128x64, 0x3C for 128x32
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);


String msg;


float Speed = 1.00;

void setup() {


    Serial.begin(57600);

    if (!display.begin(SSD1306_SWITCHCAPVCC, SCREEN_ADDRESS)) {
        Serial.println(F("SSD1306 allocation failed"));
        for (;;)
            ;  // Don't proceed, loop forever
    }
    display.display();
    delay(2000);
    display.clearDisplay();
    msg = "";

    if (!(SD.begin(BUILTIN_SDCARD))) {
        while (1) {
            Serial.println("Unable to access the SD card");
            delay(500);
        }
    }

    AudioMemory(24);
    audioShield.enable();
    audioShield.volume(0.5);
    playSdWav1.enableInterpolation(true);

    // in case the keypad needs to be init
    init_my_keypad();
      Serial.println("kurte Quick and Dirty");
}

void loop() {

    // process the keypad
   process_my_keypad();
    if ( process_key_pressed(25));  { Serial.println("Process keypad testing for key 25 pressed"); }
      if ( process_key_pressed(25));  { Serial.println("Process keypad testing for key 25 released"); }
    // -------------------------------------------------------
    if (Serial.available() > 0) {
        int incomingByte = Serial.read();
        if (incomingByte == 49) {  // key 1
            Speed = Speed + 0.01;
            playSdWav1.setPlaybackRate(Speed);
            Serial.println(Speed);
        }
        if (incomingByte == 50) {  //  key 2
            Speed = Speed - 0.01;
            playSdWav1.setPlaybackRate(Speed);
            Serial.println(Speed);
        }
        if (incomingByte == 51) {  // key 3
            playSdWav1.playWav("13.WAV");
            playSdWav1.setLoopType(looptype_repeat);
            Serial.println("Playing 13.wav in loop mode");
        }
        if (incomingByte == 52) {  // key 4

            Serial.println("stopped");
            playSdWav1.stop();
        }
        if (incomingByte == 53) {  // key5
            playSdWav1.setPlaybackRate(Speed);
            Serial.println("speed 1.00");
        }
    }  // ------------------------------------------------------
}


//namespace std {
//  void __throw_bad_function_call() {}
// void __throw_length_error(char const*) {}
//}

void SCN_MAIN(int number) {
    display.clearDisplay();
    display.setTextSize(1);               // Normal 1:1 pixel scale
    display.setTextColor(SSD1306_WHITE);  // Draw white text
    display.setCursor(0, 0);              // Start at top-left corner
    display.print(number);
    display.print(msg);
    display.display();
}
and got error for 70,71 lines.
Code:
could not convert 'process_key_pressed(25)' from 'void' to 'bool'
i think i am going to very near to solution. please reply ,,,
am i wrong in .cpp and .h file ????
what to write in main sketch for key press and release of 25???
thank you....
 
Your error in lines 70/71 is trying to tell you that you have a mismatch in function definitions and/or usages: somewhere, the function process_key_pressed() is defined to return a bool, but the external reference to the same function extern void process_key_pressed(int mykey); declares that it returns nothing (the void in front of the function name indicates nothing returned). You need to resolve these differences.

Hope that helps . . .

Mark J Culross
KD5RXT
 
am sorry . i am puzzle in "extern" word . it is out of my mind . as you are seeing my (main sketch. , process_keypad.cpp ,process_keypad.h ) in mypost #9 please suggest . what line ,what code should be write where in my files to get detect particular key pressed or released in my main sketch and call any function for Example ???????
 
Solved ------Solved
Thank you kurtE
Thank you Mark Culross
My issue solved , I moved all code from CPP to my main sketch. I removed.h file also removed function from main sketch related to extern. Now it is being compiled and uploaded.
Again thank to KurtE and Mark,,,,
 
The compiler does not like you using ROWS and COLS in these defines as they are not constant and could be changed.
Two easy fixes for those:
Code:
#define ROWS 7
or
Code:
const uint8_t ROWS = 7; // 7 rows
(Obviously same for COLS)

Or this:
C++:
constexpr uint8_t ROWS = 7;

This is very similar to a compile-time literal, and is preferred for true constants.
 
Back
Top