Explorar el Código

修复brightnes bug

monkeylqd hace 1 mes
padre
commit
fd0b21ec1f
Se han modificado 1 ficheros con 39 adiciones y 17 borrados
  1. 39 17
      light_ring.c

+ 39 - 17
light_ring.c

@@ -131,18 +131,39 @@ static void delay_work_func(struct work_struct *work)
     //自己再启动自己,也可以在其他地方启动
     if(global_dev->lightring->flash_time != 0)
     {
-        if(flag == 0)
+        if(global_dev->lightring->mode == LIGHT_MODE_FLASH_1SEC || \
+           global_dev->lightring->mode == LIGHT_MODE_FLASH_2SEC || \
+           global_dev->lightring->mode == LIGHT_MODE_FLASH_3SEC)
         {
-            // 显示颜色
-            set_color(global_dev->lightring->color);
-            flag = 1;
+            if(flag == 0)
+            {
+                // 显示颜色
+                set_color(global_dev->lightring->color);
+                flag = 1;
+            }
+            else
+            {
+                // 关闭灯带
+                set_color(0);
+                flag = 0;
+            }
         }
-        else
+        else if(global_dev->lightring->mode == LIGHT_MODE_FLASH_SLOW || \
+                global_dev->lightring->mode == LIGHT_MODE_FLASH_MEDIUM || \
+                global_dev->lightring->mode == LIGHT_MODE_FLASH_FAST)
         {
-            // 关闭灯带
-            set_color(0);
-            flag = 0;
+            if(global_dev->lightring->brightness >= 100)
+            {
+                global_dev->lightring->brightness = 1;
+            }
+            global_dev->lightring->brightness += global_dev->lightring->brightness;
+            if(global_dev->lightring->brightness >= 100)
+            {
+                global_dev->lightring->brightness = 100;
+            }
+            set_color(global_dev->lightring->color);
         }
+
 	    schedule_delayed_work(&global_dev->delay_work1, msecs_to_jiffies(global_dev->lightring->flash_time));
     }
 }
@@ -165,9 +186,9 @@ int set_color(unsigned int color)
     unsigned char blue_pwm_l = 0;
     unsigned char blue_pwm_h = 0;
 
-    red = (255 - ((color >> 16) & 0xff)) * global_dev->lightring->brightness / 100;
-    green = (255 - ((color >> 8) & 0xff)) * global_dev->lightring->brightness / 100;
-    blue = (255 - (color & 0xff)) * global_dev->lightring->brightness / 100;
+    red = 255 - (((color >> 16) & 0xff) * global_dev->lightring->brightness / 100);
+    green = 255 - (((color >> 8) & 0xff) * global_dev->lightring->brightness / 100);
+    blue = 255 - ((color & 0xff) * global_dev->lightring->brightness / 100);
 
     red_pwm_l = (red * 4095 / 255) & 0xff;
     red_pwm_h = ((red * 4095 / 255) >> 8) & 0x0f;
@@ -213,10 +234,11 @@ static ssize_t brightness_store(struct kobject *kobj, struct kobj_attribute *att
 
     ret = kstrtou32(buf, 10, &val);
     if (ret < 0)
-    {        
+    {
         printk("Lightring: brightness format error\n");
         return ret;
     }
+
     if(val > 100)
     {
         printk("Lightring: brightness out of range\n");
@@ -402,19 +424,19 @@ static ssize_t mode_store(struct kobject *kobj, struct kobj_attribute *attr,
         mode = LIGHT_MODE_FLASH_3SEC;
         time = 3000;
     }
-    else if (strncmp(buf, "flash_slow", 10) == 0)
+    else if (strncmp(buf, "fade_slow", 9) == 0)
     {
         printk("Lightring: mode set to flash_slow\n");
         mode = LIGHT_MODE_FLASH_SLOW;
-        time = 4000;
+        time = 400;
     }
-    else if (strncmp(buf, "flash_medium", 12) == 0)
+    else if (strncmp(buf, "fade_medium", 11) == 0)
     {
         printk("Lightring: mode set to flash_medium\n");
         mode = LIGHT_MODE_FLASH_MEDIUM;
-        time = 2000;
+        time = 200;
     }
-    else if (strncmp(buf, "flash_fast", 10) == 0)
+    else if (strncmp(buf, "fade_fast", 9) == 0)
     {
         printk("Lightring: mode set to flash_fast\n");
         mode = LIGHT_MODE_FLASH_FAST;