AndreiLux / Perseus-UNIVERSAL5410

This is a clean kernel glued together upon Samsung's last public branch of android-exynos-3.4 with sources provided by the OSRC releases. The OSRC release has been stripped clean of all non-i9500 related code and sourced, as much as possible through the original patches.
https://github.com/AndreiLux/Perseus-UNIVERSAL5410/wiki
Other
30 stars 19 forks source link

Quick negative screen toggle #22

Closed sorgelig closed 11 years ago

sorgelig commented 11 years ago

Inspired by similar feature in Siyah kernel for SGS3 where you could toggle negative screen by triple home button press, i've made patch for SGS4, but for menu touch button. In this case you won't leave application and won't wear hardware home button.

You need to press menu button quickly (less than 300ms between clicks) 4 times. Because it's in kernel, it will work absolutely everywhere.

Here are patches. For kernel:

diff --git a/drivers/input/keyboard/cypress/cypress-touchkey.c b/drivers/input/keyboard/cypress/cypress-touchkey.c
index 7d6bdb6..239bdc5 100644
--- a/drivers/input/keyboard/cypress/cypress-touchkey.c
+++ b/drivers/input/keyboard/cypress/cypress-touchkey.c
@@ -848,9 +848,27 @@ static int touchkey_firmware_update(struct touchkey_i2c *tkey_i2c)
 #endif

 #ifndef TEST_JIG_MODE
+
+static int mdnie_shortcut_enabled = 0;
+module_param_named(mdnie_shortcut_enabled, mdnie_shortcut_enabled, int, S_IRUGO | S_IWUSR | S_IWGRP);
+
+static inline int64_t get_time_inms(void) {
+    int64_t tinms;
+    struct timespec cur_time = current_kernel_time();
+    tinms =  cur_time.tv_sec * MSEC_PER_SEC;
+    tinms += cur_time.tv_nsec / NSEC_PER_MSEC;
+    return tinms;
+}
+
+extern void mdnie_toggle_negative(void);
+static int homekey_trg_cnt = 4;
+static int homekey_trg_ms = 300;
+
 static irqreturn_t touchkey_interrupt(int irq, void *dev_id)
 {
    struct touchkey_i2c *tkey_i2c = dev_id;
+   static int64_t homekey_lasttime = 0;
+   static int homekey_count = -1;
    u8 data[3];
    int ret;
    int retry = 10;
@@ -879,6 +897,24 @@ static irqreturn_t touchkey_interrupt(int irq, void *dev_id)
        return IRQ_HANDLED;
    }

+   if(pressed && (touchkey_keycode[keycode_type] == KEY_MENU) && mdnie_shortcut_enabled)
+   {
+       if (get_time_inms() - homekey_lasttime < homekey_trg_ms)
+       {
+           homekey_count++;
+       if(homekey_count>=homekey_trg_cnt - 1)
+       {
+           mdnie_toggle_negative();
+           homekey_count = 0;
+       }
+       }
+       else
+       {
+           homekey_count = 0;
+       }
+       homekey_lasttime = get_time_inms();
+   }
+
    input_report_key(tkey_i2c->input_dev,
             touchkey_keycode[keycode_type], pressed);
    input_sync(tkey_i2c->input_dev);
diff --git a/drivers/video/mdnie.c b/drivers/video/mdnie.c
index 4df9ac1..c558719 100644
--- a/drivers/video/mdnie.c
+++ b/drivers/video/mdnie.c
@@ -1064,6 +1064,15 @@ static int mdnie_remove(struct platform_device *pdev)
    return 0;
 }

+void mdnie_toggle_negative(void)
+{
+   mutex_lock(&g_mdnie->lock);
+   g_mdnie->negative = (g_mdnie->negative == NEGATIVE_ON) ? NEGATIVE_OFF : NEGATIVE_ON;
+   mutex_unlock(&g_mdnie->lock);
+
+   mdnie_update(g_mdnie, 0);
+}
+
 static struct platform_driver mdnie_driver = {
    .driver     = {
        .name   = "mdnie", 

and for STweak settings:

--- a/customconfig.xml.generate.screen  2013-07-20 11:18:30.000000000 +0800
+++ b/customconfig.xml.generate.screen  2013-08-17 18:13:46.966524625 +0800
@@ -3,6 +3,12 @@

 cat << ENDCONFIG
   <settingsTab name="Screen">
+    <settingsPane description=""
+         name="Front Buffer">
+
+       <checkbox description="Enable inverting the screen colors by quickly pressing MENU button 4 times" name="Negative Screen Toggle" action="generic01 /sys/module/cypress_touchkey/parameters/mdnie_shortcut_enabled" label="Enabled"/>
+    </settingsPane>
+
     <settingsPane description="mobile Digital Natural Image engine control. Samsungs hardware image post-processor controls virtually any image manipulation. All control master switches, if left as delta controls, will negate the sequence setting if checked. Master sequence has SCR and CS enabled by default."
          name="Global controls">
AndreiLux commented 11 years ago

Can you please post such patches to a Gist or directly as a commit so I can pull them? I had to manually patch it since the formatting got screwed up.

Anyway, thanks for the feature.

(Also, use the labels instead of [tags] :) )

sorgelig commented 11 years ago

Here are patches: http://www.mediafire.com/download/zov0uomj4ffgvxi/quick_toggle.zip

Ready to apply. Let me know if you have an issues.

AndreiLux commented 11 years ago

I already patched it, works fine. Just meant to say it for next time. You can use https://gist.github.com/

AndreiLux commented 11 years ago

Excuse me on that, I spoke too early. Patched and compiled fine, but it doesn't have any effect?

sorgelig commented 11 years ago

Didn't you forget to enable it in STweaks?

4 quick presses on left sensor button (menu)

sorgelig commented 11 years ago

should press it really quick.. approximately all 4 clicks should be within 1 second.

sorgelig commented 11 years ago

btw, try to download my patches and apply. May be something missed when you copied from here.

AndreiLux commented 11 years ago

Fixed it, put it wrongly during the manual patching above the pressed declaration instead of below it.