diff --git a/libraries/PT2314/CHANGELOG.md b/libraries/PT2314/CHANGELOG.md index b02ec9a1..3fe0dc8f 100644 --- a/libraries/PT2314/CHANGELOG.md +++ b/libraries/PT2314/CHANGELOG.md @@ -6,11 +6,19 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/). +## [0.2.0] - 2023-12-08 +- refactor API, begin() +- update readme.md +- added **void setAttn(uint8_t attn)** +- removed setAttn(left, right). +- minor edits + +---- + ## [0.1.2] - 2023-09-24 - add Wire1 support for ESP32 - update readme.md - ## [0.1.1] - 2023-08-01 - add **PT7313** derived class - 3 input 2 output version diff --git a/libraries/PT2314/PT2314.cpp b/libraries/PT2314/PT2314.cpp index 6197add4..ef083c3e 100644 --- a/libraries/PT2314/PT2314.cpp +++ b/libraries/PT2314/PT2314.cpp @@ -2,7 +2,7 @@ // FILE: PT2314.cpp // AUTHOR: Rob Tillaart // DATE: 2023-07-30 -// VERSION: 0.1.2 +// VERSION: 0.2.0 // PURPOSE: Arduino library for PT2314 i2C 4 channel audio processor. // URL: https://github.com/RobTillaart/PT2314 @@ -12,36 +12,12 @@ PT2314::PT2314(TwoWire *wire) { - _wire = wire; + _wire = wire; } -#if defined (ESP8266) || defined(ESP32) -bool PT2314::begin(int dataPin, int clockPin) -{ - if ((dataPin < 255) && (clockPin < 255)) - { - _wire->begin(dataPin, clockPin); - } else { - _wire->begin(); - } - if (! isConnected()) return false; - setChannel(); - setMute(); - setLoudness(); - setVolume(); - setBass(); - setTreble(); - setGain(); - // setAttn(31,31); // already muted - return true; -} -#endif - - bool PT2314::begin() { - _wire->begin(); if (! isConnected()) return false; setChannel(); setMute(); @@ -50,7 +26,7 @@ bool PT2314::begin() setBass(); setTreble(); setGain(); - // setAttn(31,31); // already muted + // setAttn(31, 31); // already muted return true; } @@ -131,7 +107,7 @@ uint8_t PT2314::getVolume() void PT2314::setBass(int8_t bass) { if (bass < -14) bass = -14; - if (bass > 14) bass = 14; + if (bass > 14) bass = 14; _bass = bass; uint8_t value; if (_bass <= 0) value = 7 + (_bass / 2); @@ -149,7 +125,7 @@ int8_t PT2314::getBass() void PT2314::setTreble(int8_t treble) { if (treble < -14) treble = -14; - if (treble > 14) treble = 14; + if (treble > 14) treble = 14; _treble = treble; uint8_t value; if (_treble <= 0) value = 7 + (_treble / 2); @@ -206,14 +182,15 @@ uint8_t PT2314::getAttnRight() } -void PT2314::setAttn(uint8_t attnLeft, uint8_t attnRight) +void PT2314::setAttn(uint8_t attn) { - setAttnLeft(attnLeft); - setAttnRight(attnRight); + setAttnLeft(attn); + setAttnRight(attn); } + /////////////////////////////////////////////////// // // PROTECTED @@ -330,5 +307,14 @@ uint8_t PT7313::getAttnRightFront() } +void PT7313::setAttn(uint8_t attn) +{ + setAttnLeft(attn); + setAttnRight(attn); + setAttnLeftFront(attn); + setAttnRightFront(attn); +} + + // -- END OF FILE -- diff --git a/libraries/PT2314/PT2314.h b/libraries/PT2314/PT2314.h index 682bfd49..3ec3cade 100644 --- a/libraries/PT2314/PT2314.h +++ b/libraries/PT2314/PT2314.h @@ -3,7 +3,7 @@ // FILE: PT2314.h // AUTHOR: Rob Tillaart // DATE: 2023-07-30 -// VERSION: 0.1.2 +// VERSION: 0.2.0 // PURPOSE: Arduino library for PT2314 i2C 4 channel audio processor. // URL: https://github.com/RobTillaart/PT2314 @@ -12,7 +12,7 @@ #include "Wire.h" -#define PT2314_LIB_VERSION (F("0.1.2")) +#define PT2314_LIB_VERSION (F("0.2.0")) class PT2314 @@ -20,9 +20,6 @@ class PT2314 public: PT2314(TwoWire *wire = &Wire); -#if defined (ESP8266) || defined(ESP32) - bool begin(int sda, int scl); -#endif bool begin(); bool isConnected(); @@ -42,14 +39,18 @@ public: void setTreble(int8_t treble = 0); // -14..14 int8_t getTreble(); + // GAIN void setGain(uint8_t gain = 0); // 0..3 uint8_t getGain(); + // ATTENUATION void setAttnLeft(uint8_t value = 31); // 0..31 uint8_t getAttnLeft(); void setAttnRight(uint8_t value = 31); // 0..31 uint8_t getAttnRight(); - void setAttn(uint8_t attnLeft, uint8_t attnRight); + + // set all to same level + void setAttn(uint8_t attn); protected: @@ -72,6 +73,7 @@ protected: int _error = 0; }; + /////////////////////////////////////////////////////////////// // // DERIVED @@ -92,15 +94,21 @@ public: void setMute(bool on); void setChannel(uint8_t channel = 0); // 0..2 + // BACK void setAttnLeftBack(uint8_t value = 31); // 0..31 uint8_t getAttnLeftBack(); void setAttnRightBack(uint8_t value = 31); // 0..31 uint8_t getAttnRightBack(); + + // FRONT void setAttnLeftFront(uint8_t value = 31); // 0..31 uint8_t getAttnLeftFront(); void setAttnRightFront(uint8_t value = 31); // 0..31 uint8_t getAttnRightFront(); + // ALL + void setAttn(uint8_t attn); + protected: uint8_t _attnLeftFront = 0; uint8_t _attnRightFront = 0; diff --git a/libraries/PT2314/README.md b/libraries/PT2314/README.md index 5bd0d6b5..56ca6393 100644 --- a/libraries/PT2314/README.md +++ b/libraries/PT2314/README.md @@ -35,9 +35,24 @@ It is used in automotive to control front and back speakers. | PT7314 | 4 | 1 | V1.0 Jan, 2010 | | PT7313 | 3 | 2 | V1.0 feb, 2010 | + +| processor | volume | attn | gain | bass | treble | +|:-----------:|:--------:|:-------:|:------:|:---------:|:---------:| +| PT2314 | 0..63 | 0..31 | 0..3 | -14..14 | -14..14 | +| PT7314 | 0..63 | 0..31 | 0..3 | -14..14 | -14..14 | +| PT7313 | 0..63 | 0..31 | 0..3 | -14..14 | -14..14 | + + Feedback as always, is welcome. -The library is based upon Datasheet: PT2314 V1.4 July, 2005 + +#### 0.2.0 Breaking change + +Version 0.2.0 introduced a breaking change. +You cannot set the pins in **begin()** any more. +This reduces the dependency of processor dependent Wire implementations. +The user has to call **Wire.begin()** and can optionally set the Wire pins +before calling **begin()**. #### I2C @@ -50,8 +65,24 @@ The library is based upon Datasheet: PT2314 V1.4 July, 2005 Note: Datasheet PT7314 states that the device needs at least 50 ms -to wake up before it can process I2C commands. So one might need -to give it some time to get started. +to wake up before it can process I2C commands. +So one might need to give it some time to get started. + + +#### Multiplexing + +If you want to put more than one PT2314 on an I2C bus you need an +I2C multiplexer as the device has a fixed address. + +See https://github.com/RobTillaart/TCA9548 + +(not tested, feedback welcome). + + +#### Related + +- https://github.com/RobTillaart/HC4052 (multiplexer for more inputs) +- https://github.com/RobTillaart/TCA9548 (I2C multiplexer) ## Interface PT2314 PT7314 @@ -63,10 +94,11 @@ to give it some time to get started. #### Constructors - **PT2314(TwoWire \*wire = &Wire)** constructor, optional set Wire interface. +- **PT7313(TwoWire \*wire = &Wire)** constructor, optional set Wire interface. - **PT7314(TwoWire \*wire = &Wire)** constructor, optional set Wire interface. -- **bool begin(int sda, int scl)** for ESP32 et al. -- **bool begin()** other platforms. -- **bool isConnected()** device (0x44) can be seen on I2C bus. +- **bool begin()** initialized library. +Returns true if device can be seen on the I2C bus. +- **bool isConnected()** returns true if device (0x44) can be seen on I2C bus. #### Channel @@ -111,27 +143,30 @@ CHeck datasheet for mapping. - **uint8_t getAttnLeft()** get current left attenuation level. - **void setAttnRight(uint8_t value = 31)** set the right attenuation from 0..31. - **uint8_t getAttnRight()** get current right attenuation level. -- **void setAttn(uint8_t attnLeft, uint8_t attnRight)** set both in one call. -Convenience function. +- **void setAttn(uint8_t attn)** set all channels in one call. + Formula attenuation: ```cpp Attn = value * -1.25; // dB 0..-37.50, 31 ==> MUTE. ``` +---- + ## Interface PT7313 ```cpp #include "PT2314.h" ``` -Additional constructor: -- **PT7313(TwoWire \*wire = &Wire)** constructor. +#### Additional +- **PT7313(TwoWire \*wire = &Wire)** constructor. - **void setMute(bool on)** idem, four channel version. - **void setChannel(uint8_t channel = 0)** idem, 0..2. -Additional attenuation: +#### PT7313 attenuation + - **void setAttnLeftBack(uint8_t value = 31)** idem, 0..31. - **uint8_t getAttnLeftBack()** get current level. - **void setAttnRightBack(uint8_t value = 31)** idem, 0..31 @@ -151,9 +186,6 @@ Additional attenuation: #### Should -- investigate **setAttn(value)** function for all channels. - - better also for the 7313 - - 0.2.0 ==> remove the setAttn(left, right) ? - add more examples. - check parameters range: 0..63 => -63..0? - some are in dB others not. diff --git a/libraries/PT2314/examples/PT2314_demo/PT2314_demo.ino b/libraries/PT2314/examples/PT2314_demo/PT2314_demo.ino index 84a2efb6..b4af103f 100644 --- a/libraries/PT2314/examples/PT2314_demo/PT2314_demo.ino +++ b/libraries/PT2314/examples/PT2314_demo/PT2314_demo.ino @@ -1,7 +1,7 @@ // // FILE: PT2314_demo.ino // AUTHOR: Rob Tillaart -// PURPOSE: simple demo +// PURPOSE: minimal demo // URL: https://github.com/RobTillaart/PT2314 @@ -17,12 +17,16 @@ void setup() Serial.begin(115200); Serial.println(__FILE__); delay(100); - + + Wire.begin(); pt.begin(); // do your settings pt.setVolume(20); - pt.setAttn(15, 24); // shift the balance + // shift the balance + pt.setAttnLeft(15); + pt.setAttnRight(24); + pt.setLoudness(true); } @@ -31,4 +35,5 @@ void loop() { } + // -- END OF FILE -- diff --git a/libraries/PT2314/examples/PT7313_demo/PT7313_demo.ino b/libraries/PT2314/examples/PT7313_demo/PT7313_demo.ino new file mode 100644 index 00000000..2679fe02 --- /dev/null +++ b/libraries/PT2314/examples/PT7313_demo/PT7313_demo.ino @@ -0,0 +1,65 @@ +// +// FILE: PT7313_demo.ino +// AUTHOR: Rob Tillaart +// PURPOSE: move sound around +// URL: https://github.com/RobTillaart/PT2314 + + +#include "PT2314.h" + +// PT2413 pt; +// PT7314 pt; +PT7313 pt; + + +void setup() +{ + Serial.begin(115200); + Serial.println(__FILE__); + delay(100); + + Wire.begin(); + pt.begin(); + + // do your settings + pt.setVolume(20); + + pt.setAttnLeft(0); + pt.setAttnRight(31); + pt.setAttnLeftBack(31); + pt.setAttnRightBack(31); + + pt.setLoudness(true); +} + + +void loop() +{ + for (int i = 0; i < 32; i++) + { + pt.setAttnLeft(31 - i); + pt.setAttnRight(i); + delay(100); + } + for (int i = 0; i < 32; i++) + { + pt.setAttnRight(31 - i); + pt.setAttnRightBack(i); + delay(100); + } + for (int i = 0; i < 32; i++) + { + pt.setAttnRightBack(31 - i); + pt.setAttnLeftBack(i); + delay(100); + } + for (int i = 0; i < 32; i++) + { + pt.setAttnLeftBack(31 - i); + pt.setAttnLeft(i); + delay(100); + } +} + + +// -- END OF FILE -- diff --git a/libraries/PT2314/keywords.txt b/libraries/PT2314/keywords.txt index 4cc6523b..fece06d0 100644 --- a/libraries/PT2314/keywords.txt +++ b/libraries/PT2314/keywords.txt @@ -2,8 +2,8 @@ # Data types (KEYWORD1) PT2314 KEYWORD1 -PT7314 KEYWORD1 PT7313 KEYWORD1 +PT7314 KEYWORD1 # Methods and Functions (KEYWORD2) diff --git a/libraries/PT2314/library.json b/libraries/PT2314/library.json index 82c7ad9b..02f4b34b 100644 --- a/libraries/PT2314/library.json +++ b/libraries/PT2314/library.json @@ -15,7 +15,7 @@ "type": "git", "url": "https://github.com/RobTillaart/PT2314.git" }, - "version": "0.1.2", + "version": "0.2.0", "license": "MIT", "frameworks": "*", "platforms": "*", diff --git a/libraries/PT2314/library.properties b/libraries/PT2314/library.properties index bcbf78f5..97b6d7e2 100644 --- a/libraries/PT2314/library.properties +++ b/libraries/PT2314/library.properties @@ -1,5 +1,5 @@ name=PT2314 -version=0.1.2 +version=0.2.0 author=Rob Tillaart maintainer=Rob Tillaart sentence=Arduino library for PT2314 i2C 4 channel audio processor, diff --git a/libraries/PT2314/test/unit_test_001.cpp b/libraries/PT2314/test/unit_test_001.cpp index e5a8f71e..5fa470a5 100644 --- a/libraries/PT2314/test/unit_test_001.cpp +++ b/libraries/PT2314/test/unit_test_001.cpp @@ -57,13 +57,14 @@ unittest_teardown() { } - +// not testable withour proper mock-up unittest(test_constructor) { PT2314 pt2; + PT7313 pt3; PT7314 pt7; - assertEqual(1,1); + assertEqual(1, 1); }