NicoHood / HID

Bring enhanced HID functions to your Arduino!
http://www.nicohood.de
MIT License
2.37k stars 409 forks source link

Android MUTE #81

Closed adrianrb closed 8 years ago

adrianrb commented 8 years ago

Hi!

I'm trying to use a IR remote to control an Android stick (simple commands, UP, DOWN, VOL+, VOL- etc).

I'm using a usb-otg cable and navigation (UP, DOWN, LEFT, RIGHT, ENTER, BACK) works.

But I can't do MEDIA MUTE (Consumer.write(MEDIA_VOLUME_MUTE) doesn't works).

How can I do it? (using this library).

Adrian

Some info: Stick: MK809IV Android 4.4.4 Quad core 2Gb RAM Android keys: https://source.android.com/devices/input/keyboard-devices.html Lines with '###' don't work.

Code:

/*

 * To send arrow keys: http://forum.arduino.cc/index.php?topic=179548.0
 */
#include <HID-Project.h>
#include <IRremote.h>

int RECV_PIN = 2;

IRrecv irrecv(RECV_PIN);

decode_results results;

void setup()
{
    Keyboard.begin();
    Consumer.begin();

    irrecv.enableIRIn(); // Start the receiver
}

// text to send or repeat
char* txt_repeat = "";

// long delays for special keys (power, mute etc.)
int dly1000 = 1000;
int dly3000 = 3000;
int dly5000 = 5000;

void loop()
{
    byte dly = 150; // standard delay

    if (irrecv.decode(&results))
    {
        // this values is for GVT TV receiver remote, AUX button (encoding SONY)
        //Serial.println(results.value);

        if (results.value != 4294967295) // "repeat"
        {
            if (results.value == 5132) // Mute ###
            {
                txt_repeat = "";
                //Consumer.write(MEDIA_VOLUME_MUTE);
                //Keyboard.write(KEY_MUTE);

            }
            else if (results.value == 21516) // Power
            {
                txt_repeat = "";
                Consumer.write(CONSUMER_POWER);
            }
            else if (results.value == 12)
            {
                txt_repeat = "1";
                Keyboard.print(txt_repeat);
            }
            else if (results.value == 16396)
            {
                txt_repeat = "2";
                Keyboard.print(txt_repeat);
            }
            else if (results.value == 8204)
            {
                txt_repeat = "3";
                Keyboard.print(txt_repeat);
            }
            else if (results.value == 24588)
            {
                txt_repeat = "4";
                Keyboard.print(txt_repeat);
            }
            else if (results.value == 4108)
            {
                txt_repeat = "5";
                Keyboard.print(txt_repeat);
            }
            else if (results.value == 20492)
            {
                txt_repeat = "6";
                Keyboard.print(txt_repeat);
            }
            else if (results.value == 12300)
            {
                txt_repeat = "7";
                Keyboard.print(txt_repeat);
            }
            else if (results.value == 28684) 
            {
                txt_repeat = "8";
                Keyboard.print(txt_repeat);
            }
            else if (results.value == 2060) 
            {
                txt_repeat = "9";
                Keyboard.print(txt_repeat);
            }
            else if (results.value == 18444) 
            {
                txt_repeat = "0";
                Keyboard.print(txt_repeat);
            }
            else if (results.value == 21004) // Source ###
            {
                txt_repeat = "";
                Keyboard.write(KEY_HOME);
            }
            else if (results.value == 461714) // Sair
            {
                txt_repeat = "";
                Keyboard.write(KEY_ESC);
            }
            else if (results.value == 363410) // Menu
            {
                txt_repeat = "";
                System.write(HID_SYSTEM_MAIN_MENU);
            }
            else if (results.value == 650130) // UP
            {
                txt_repeat = "";
                Keyboard.write(KEY_UP_ARROW);
            }
            else if (results.value == 256914) // RIGHT
            {
                txt_repeat = "";
                Keyboard.write(KEY_RIGHT_ARROW);
            }
            else if (results.value == 387986) // DOWN
            {
                txt_repeat = "";
                Keyboard.write(KEY_DOWN_ARROW);
            }
            else if (results.value == 912274) // LEFT
            {
                txt_repeat = "";
                Keyboard.write(KEY_LEFT_ARROW);
            }
            else if (results.value == 854930) // OK (ENTER)
            {
                txt_repeat = "";
                Keyboard.write(KEY_RETURN);
            }
            else if (results.value == 9228) // vol+
            {
                txt_repeat = "";
                Consumer.write(MEDIA_VOLUME_UP);
            }
            else if (results.value == 25612) // vol-
            {
                txt_repeat = "";
                Consumer.write(MEDIA_VOLUME_DOWN);
            }
            else if (results.value == 16908) // Info ###
            {
                txt_repeat = "";
                Keyboard.write(KEY_ESC);
            }
        }
        else
        {
            Keyboard.print(txt_repeat);
        }

        delay(dly);

        irrecv.resume(); // Receive the next value
    }
}
NicoHood commented 8 years ago

Your android device does possibly not support the consumer HID device. Does the other consumer keys work (vol up down)? You can try to replace consumer with Keyboard.write(KEY_VOLUME_MUTE);

Can you try the sketch on a pc and see if the pc does mute the sound?

As an alternative, maybe there is another keyboard shortcut that works on android. Also try my IRLRemote library (dev2 branch). https://github.com/NicoHood/IRLremote

adrianrb commented 8 years ago

Hi Nico.

Tks for the answer.

Vol+ and Vol- works, in PC and Android (and Power too - in android), but your suggestion Keyboard.write(KEY_VOLUME_MUTE); does not works (both PC and android).

I will keep trying (any advice will be appreciated).

Adrian

NicoHood commented 8 years ago

Does volume mute work on pc (using the consumer device)?

adrianrb commented 8 years ago

Yes, in PC works, but in android nop (tested again):

Consumer.write(MEDIA_VOLUME_MUTE);

NicoHood commented 8 years ago

Then it is a problem of your android device. Try to find another keyboard command, maybe there is something else. Otherwise I am sorry that there is no other solution.