Using WiPhone Custom Buttons

There are four User-defined buttons in WiPhone Keypad which can be used by users to directly access any assigned function against each key. You can add any functionality to these buttons and use as per your convenience.In Production version of WiPhone firmware, the functionality of these buttons are kept disabled but you can enable it by following this guide. Below image shows location of these buttons on WiPhone Keypad marked through “User1 … User4”.

_images/keypad_layout-01.png

How to Do in Firmware

To enable functionality of these buttons in firmware, Follow as:
  1. comment #define WIPHONE_PRODUCTION and #define DIAGNOSTICS_ONLY in config.h
  2. uncomment #define STEAL_THE_USER_BUTTONS in config.h

Now in WiPhone.ino F1-F4 keys can be used for user defined functions.

In WiPhone.ino, we already created some example functionalities against each user keys

  • F1 User Key is used for toggling state of LCD, keypad LEDs and Vibration motor.
  • F2 User Key is used for audio test. Ringtone will be played to audio output.
  • F3 User Key is toggle between Loudspeaker and Earspeaker.
  • F4 User Key is used to enter in light sleep mode.

Similarly, you can assign these User Keys to any functions you like and access those functions with ease of just a single button press.

      // Process key
#ifndef STEAL_THE_USER_BUTTONS
      if (keyPressed == WIPHONE_KEY_F1) {
      }

      if (keyPressed == WIPHONE_KEY_F2) {
      }

      if (keyPressed == WIPHONE_KEY_F3) {
      }

      if (keyPressed == WIPHONE_KEY_F4) {
      }

#else
      if (keyPressed == WIPHONE_KEY_F1) {
        gui.toggleScreen();
        //allDigitalWrite(ENABLE_DAUGHTER_33V, HIGH);
        //gui.longBatteryAnimation();
        allDigitalWrite(VIBRO_MOTOR_CONTROL, HIGH);
        allDigitalWrite(KEYBOARD_LED, LOW);
        delay(500);
        allDigitalWrite(VIBRO_MOTOR_CONTROL, LOW);
        allDigitalWrite(KEYBOARD_LED, HIGH);
        gui.toggleScreen();
      }

      if (keyPressed == WIPHONE_KEY_F2) {
        audio_test();
      }

      if (keyPressed == WIPHONE_KEY_F3) {
        bool isLoud = !audio->isLoudspeaker();
        log_d("Loudspeaker: %d", isLoud);
        audio->chooseSpeaker(isLoud);
        log_d("WiFi Mode: %d", WiFi.getMode());
        log_d("WiFi Status: %d", WiFi.status());
      }

      if (keyPressed == WIPHONE_KEY_F4) {
        //esp_sleep_enable_ext0_wakeup((gpio_num_t)KEYBOARD_INTERRUPT_PIN,1);
        //esp_sleep_enable_ext1_wakeup(BUTTON_PIN_BITMASK, ESP_EXT1_WAKEUP_ANY_HIGH);
        esp_sleep_enable_ext0_wakeup((gpio_num_t)KEYBOARD_INTERRUPT_PIN,0); //1 = Low to High, 0 = High to Low. Pin pulled HIGH
        //esp_sleep_enable_timer_wakeup(5000000);
        log_d("begin delay");
        delay(500); // debounce
        log_d("begin light sleep");
        delay(10); // let print finish
        //esp_deep_sleep_start();
        esp_light_sleep_start();
        log_d("awake!!!");

        //LOG_MEM_STATUS;

        //gui.setDumpRegion();
        //gui.frameToSerial();    // "screenshot"
      }
#endif