From 33de7fc81a0322d06ad33238d1d9d9ed763204c4 Mon Sep 17 00:00:00 2001
From: =?utf-8?q?Marco=20Trevisan=20(Trevi=C3=B1o)?= <mail@3v1n0.net>
Date: Wed, 15 Oct 2008 06:33:56 +0200
Subject: [PATCH] Add Ficgta01ModemHiddenFeatures class
 I've reworked the enable-echo-suppression-on-dialing-and-accepting.patch
 creating a new class that allow to set all the known hidden modem at commands.
 All this is based on the informations released in the hardware mailing list:
  - http://lists.openmoko.org/pipermail/hardware/2008-August/000451.html

---
 .../phonevendors/ficgta01/vendor_ficgta01.cpp      |   58 ++++++++++++++++++--
 .../phonevendors/ficgta01/vendor_ficgta01_p.h      |   17 +++++-
 2 files changed, 68 insertions(+), 7 deletions(-)

diff --git a/devices/ficgta01/src/plugins/phonevendors/ficgta01/vendor_ficgta01.cpp b/devices/ficgta01/src/plugins/phonevendors/ficgta01/vendor_ficgta01.cpp
index afd5d37..4847634 100644
--- a/devices/ficgta01/src/plugins/phonevendors/ficgta01/vendor_ficgta01.cpp
+++ b/devices/ficgta01/src/plugins/phonevendors/ficgta01/vendor_ficgta01.cpp
@@ -769,14 +769,15 @@ void Ficgta01ModemService::modemDied()
         m_vibratorService->setVibrateNow(false);
 }
 
-void Ficgta01ModemService::echoCancellation(QAtChat * atChat)
+void Ficgta01ModemService::echoCancellation(QAtChat* atChat)
 {
-        atChat->chat( "AT@ST=\"-26\"" ); // audio side tone: set to minimum
-        atChat->chat( "AT%N028B" ); // Long Echo Cancellation: active, -6db
-        atChat->chat( "AT%N0125" ); // Noise reduction: active, -6db
+    Ficgta01ModemHiddenFeatures* hs = new Ficgta01ModemHiddenFeatures(atChat);
+    atChat->chat( "AT@ST=\"-26\"" );  // audio side tone: set to minimum
+    hs->enableAEC( -6, true );        // Long Echo Cancellation: active, -6db
+    hs->enableNoiseReduction( -6 );   // Noise reduction: active, -6db
 }
 
- Ficgta01VibrateAccessory::Ficgta01VibrateAccessory
+Ficgta01VibrateAccessory::Ficgta01VibrateAccessory
         ( QModemService *service )
     : QVibrateAccessoryProvider( service->service(), service )
 {
@@ -909,3 +910,50 @@ Ficgta01PreferredNetworkOperators::Ficgta01PreferredNetworkOperators( QModemServ
 Ficgta01PreferredNetworkOperators::~Ficgta01PreferredNetworkOperators()
 {
 }
+
+Ficgta01ModemHiddenFeatures::Ficgta01ModemHiddenFeatures(QAtChat* atChat) :
+    atPrefix( "AT%N" )
+{
+    m_atChat = atChat;
+}
+
+Ficgta01ModemHiddenFeatures::~Ficgta01ModemHiddenFeatures()
+{
+}
+
+void Ficgta01ModemHiddenFeatures::sendHiddenFeatureCommand(int code)
+{
+    m_atChat->chat(atPrefix + QString::number(code, 16).toUpper().rightJustified(4, '0'));
+}
+
+void Ficgta01ModemHiddenFeatures::enableAEC(int type, bool longAEC = true)
+{
+    if (type <= 0 && type >= -18 && (-type) % 6 == 0) {
+        int code = 0x0083 + (((-type) / 6) * 0x8);
+        
+        if (longAEC)
+            code += 0x0200;
+            
+         sendHiddenFeatureCommand(code);
+    }
+}
+
+void Ficgta01ModemHiddenFeatures::enableNoiseReduction(int type)
+{
+    if (type <= 0 && type >= -18 && (-type) % 6 == 0) {
+        int code = 0x0105 + (((-type) / 6) * 0x20);
+            
+        sendHiddenFeatureCommand(code);
+    }
+}
+
+void Ficgta01ModemHiddenFeatures::enableNoiseReductionAEC()
+{
+    sendHiddenFeatureCommand(0x0187);
+}
+
+void Ficgta01ModemHiddenFeatures::disableNoiseReductionAEC()
+{
+    sendHiddenFeatureCommand(0x0001);
+}
+
diff --git a/devices/ficgta01/src/plugins/phonevendors/ficgta01/vendor_ficgta01_p.h b/devices/ficgta01/src/plugins/phonevendors/ficgta01/vendor_ficgta01_p.h
index b5cc651..92e5aae 100644
--- a/devices/ficgta01/src/plugins/phonevendors/ficgta01/vendor_ficgta01_p.h
+++ b/devices/ficgta01/src/plugins/phonevendors/ficgta01/vendor_ficgta01_p.h
@@ -168,8 +168,6 @@ public slots:
     void setVibrateOnRing( const bool value );
 };
 
-
-
 class Ficgta01CallVolume : public QModemCallVolume
 {
       Q_OBJECT
@@ -211,7 +209,22 @@ public Q_SLOTS:
     void setChannels(const QList<int>& list);
 };
 
+class Ficgta01ModemHiddenFeatures
+{
+public:
+    Ficgta01ModemHiddenFeatures( QAtChat* );
+    ~Ficgta01ModemHiddenFeatures();
 
+    void sendHiddenFeatureCommand( int );
+    void enableAEC( int, bool );
+    void enableNoiseReduction( int );
+    void enableNoiseReductionAEC();
+    void disableNoiseReductionAEC();
+
+private:
+    QAtChat * m_atChat;
+    const QString atPrefix;
+};
 
 
 #endif
-- 
1.5.4.3

