]> git.donarmstrong.com Git - qmk_firmware.git/commitdiff
Add effect speed support for RGB Matrix *No EEPROM yet* (#2922)
authoryiancar <yiangosyiangou@cytanet.com.cy>
Wed, 9 May 2018 03:23:21 +0000 (04:23 +0100)
committerJack Humbert <jack.humb@gmail.com>
Wed, 9 May 2018 03:23:21 +0000 (23:23 -0400)
* Added Modular keyboards L,R and NUM

Created code modules for the 3 modules of the modular keyboard.
Original idea by MechboardsUK. Uses i2c implementation similar to lets
split

* Remove modular from master

This is to fix incorrect branching

* Add effect speed support for RGB Matrix *No eeprom yet*

Keycodes RGB_SPI and RGB_SPD have been added to increase and decrease effect speed.

Speed is not saved in EEPROM yet as per Jack's request.

* Update rgb_matrix.c

* RGB Matrix speed fix rgblight.h

* More fixes for rgb speed. Speed functions declared but not used in rgblight

* More travis fixes..

* Another one for travis..

docs/feature_rgb_matrix.md
quantum/quantum.c
quantum/quantum_keycodes.h
quantum/rgb.h
quantum/rgb_matrix.c
quantum/rgb_matrix.h
quantum/rgblight.c
quantum/rgblight.h

index dfc103247acbf2a9c83e8ecfbf8f8936c86b65ed..084e87ec4840efe84e8b6669d2af17f1591e69ec 100644 (file)
@@ -69,6 +69,8 @@ All RGB keycodes are currently shared with the RGBLIGHT system:
        * `RGB_SAD` - decrease saturation
        * `RGB_VAI` - increase value
        * `RGB_VAD` - decrease value
+       * `RGB_SPI` - increase speed effect (no EEPROM support)
+       * `RGB_SPD` - decrease speed effect (no EEPROM support)
 
 
        * `RGB_MODE_*` keycodes will generally work, but are not currently mapped to the correct effects for the RGB Matrix system
index e1bc8b242eba51079dc12e0bc7d4827cabf4931b..f9b3e2197d90db4e4b862cd0109f5920ca0a2381 100644 (file)
@@ -368,6 +368,16 @@ bool process_record_quantum(keyrecord_t *record) {
       rgblight_decrease_val();
     }
     return false;
+  case RGB_SPI:
+    if (record->event.pressed) {
+      rgblight_increase_speed();
+    }
+    return false;
+  case RGB_SPD:
+    if (record->event.pressed) {
+      rgblight_decrease_speed();
+    }
+    return false;
   case RGB_MODE_PLAIN:
     if (record->event.pressed) {
       rgblight_mode(1);
index d6030284a9152aa85c5f67aae353d3401200e7e5..405741eb153a93be63dd22b7d7e65c18c1441100 100644 (file)
@@ -413,6 +413,8 @@ enum quantum_keycodes {
     RGB_SAD,
     RGB_VAI,
     RGB_VAD,
+    RGB_SPI,
+    RGB_SPD,
     RGB_MODE_PLAIN,
     RGB_MODE_BREATHE,
     RGB_MODE_RAINBOW,
index fbdda293f47004744ba2d6f33874b3a421299cd0..ce674ce6bce7f3d21abfbd552257a6888b475685 100644 (file)
@@ -44,4 +44,10 @@ void rgblight_increase_val(void) {};
 __attribute__((weak))
 void rgblight_decrease_val(void) {};
 
+__attribute__((weak))
+void rgblight_increase_speed(void) {};
+
+__attribute__((weak))
+void rgblight_decrease_speed(void) {};
+
 #endif
\ No newline at end of file
index 6cb0478f71efd872c4bccd28531e89a08e6b02f8..558e28decebe77e4b6abc5960c6ffd11d941ea73 100644 (file)
@@ -69,6 +69,7 @@ void eeconfig_update_rgb_matrix_default(void) {
   rgb_matrix_config.hue = 0;
   rgb_matrix_config.sat = 255;
   rgb_matrix_config.val = 255;
+  rgb_matrix_config.speed = 0;
   eeconfig_update_rgb_matrix(rgb_matrix_config.raw);
 }
 void eeconfig_debug_rgb_matrix(void) {
@@ -78,6 +79,7 @@ void eeconfig_debug_rgb_matrix(void) {
   dprintf("rgb_matrix_config.hue = %d\n", rgb_matrix_config.hue);
   dprintf("rgb_matrix_config.sat = %d\n", rgb_matrix_config.sat);
   dprintf("rgb_matrix_config.val = %d\n", rgb_matrix_config.val);
+  dprintf("rgb_matrix_config.speed = %d\n", rgb_matrix_config.speed);
 }
 
 // Last led hit
@@ -343,7 +345,7 @@ void rgb_matrix_raindrops(bool initialize) {
 }
 
 void rgb_matrix_cycle_all(void) {
-    uint8_t offset = g_tick & 0xFF;
+    uint8_t offset = ( g_tick << rgb_matrix_config.speed ) & 0xFF;
 
     rgb_led led;
 
@@ -364,7 +366,7 @@ void rgb_matrix_cycle_all(void) {
 }
 
 void rgb_matrix_cycle_left_right(void) {
-    uint8_t offset = g_tick & 0xFF;
+    uint8_t offset = ( g_tick << rgb_matrix_config.speed ) & 0xFF;
     HSV hsv = { .h = 0, .s = 255, .v = rgb_matrix_config.val };
     RGB rgb;
     Point point;
@@ -388,7 +390,7 @@ void rgb_matrix_cycle_left_right(void) {
 }
 
 void rgb_matrix_cycle_up_down(void) {
-    uint8_t offset = g_tick & 0xFF;
+    uint8_t offset = ( g_tick << rgb_matrix_config.speed ) & 0xFF;
     HSV hsv = { .h = 0, .s = 255, .v = rgb_matrix_config.val };
     RGB rgb;
     Point point;
@@ -863,6 +865,16 @@ void rgblight_decrease_val(void) {
     eeconfig_update_rgb_matrix(rgb_matrix_config.raw);
 }
 
+void rgblight_increase_speed(void) {
+    rgb_matrix_config.speed = increment( rgb_matrix_config.speed, 1, 0, 3 );
+    eeconfig_update_rgb_matrix(rgb_matrix_config.raw);//EECONFIG needs to be increased to support this
+}
+
+void rgblight_decrease_speed(void) {
+    rgb_matrix_config.speed = decrement( rgb_matrix_config.speed, 1, 0, 3 );
+    eeconfig_update_rgb_matrix(rgb_matrix_config.raw);//EECONFIG needs to be increased to support this
+}
+
 void rgblight_mode(uint8_t mode) {
     rgb_matrix_config.mode = mode;
     eeconfig_update_rgb_matrix(rgb_matrix_config.raw);
index ef93c6d5cb8acf45ab7dc4801028e7562dc60931..1552d591038fb7c954d68e965ea29ac2763c3a40 100644 (file)
@@ -58,6 +58,7 @@ typedef union {
     uint16_t hue     :9;
     uint8_t  sat     :8;
     uint8_t  val     :8;
+    uint8_t  speed   :8;//EECONFIG needs to be increased to support this
   };
 } rgb_config_t;
 
@@ -129,6 +130,8 @@ void rgblight_increase_sat(void);
 void rgblight_decrease_sat(void);
 void rgblight_increase_val(void);
 void rgblight_decrease_val(void);
+void rgblight_increase_speed(void);
+void rgblight_decrease_speed(void);
 void rgblight_mode(uint8_t mode);
 uint32_t rgblight_get_mode(void);
 
index ae183440817e0daf46ca581528d3449bad94cb83..75512e97a7ff65fa06f15eabb1c95890d2a1f742 100644 (file)
@@ -27,6 +27,9 @@
 #define RGBLIGHT_LIMIT_VAL 255
 #endif
 
+#define MIN(a,b) (((a)<(b))?(a):(b))
+#define MAX(a,b) (((a)>(b))?(a):(b))
+
 __attribute__ ((weak))
 const uint8_t RGBLED_BREATHING_INTERVALS[] PROGMEM = {30, 20, 10, 5};
 __attribute__ ((weak))
@@ -122,6 +125,7 @@ void eeconfig_update_rgblight_default(void) {
   rgblight_config.hue = 0;
   rgblight_config.sat = 255;
   rgblight_config.val = RGBLIGHT_LIMIT_VAL;
+  rgblight_config.speed = 0;
   eeconfig_update_rgblight(rgblight_config.raw);
 }
 void eeconfig_debug_rgblight(void) {
@@ -131,6 +135,7 @@ void eeconfig_debug_rgblight(void) {
   dprintf("rgblight_config.hue = %d\n", rgblight_config.hue);
   dprintf("rgblight_config.sat = %d\n", rgblight_config.sat);
   dprintf("rgblight_config.val = %d\n", rgblight_config.val);
+  dprintf("rgblight_config.speed = %d\n", rgblight_config.speed);
 }
 
 void rgblight_init(void) {
@@ -280,6 +285,18 @@ void rgblight_disable(void) {
   rgblight_set();
 }
 
+// Deals with the messy details of incrementing an integer
+uint8_t increment( uint8_t value, uint8_t step, uint8_t min, uint8_t max ) {
+    int16_t new_value = value;
+    new_value += step;
+    return MIN( MAX( new_value, min ), max );
+}
+
+uint8_t decrement( uint8_t value, uint8_t step, uint8_t min, uint8_t max ) {
+    int16_t new_value = value;
+    new_value -= step;
+    return MIN( MAX( new_value, min ), max );
+}
 
 void rgblight_increase_hue(void) {
   uint16_t hue;
@@ -331,6 +348,15 @@ void rgblight_decrease_val(void) {
   }
   rgblight_sethsv(rgblight_config.hue, rgblight_config.sat, val);
 }
+void rgblight_increase_speed(void) {
+    rgblight_config.speed = increment( rgblight_config.speed, 1, 0, 3 );
+    eeconfig_update_rgblight(rgblight_config.raw);//EECONFIG needs to be increased to support this
+}
+
+void rgblight_decrease_speed(void) {
+    rgblight_config.speed = decrement( rgblight_config.speed, 1, 0, 3 );
+    eeconfig_update_rgblight(rgblight_config.raw);//EECONFIG needs to be increased to support this
+}
 
 void rgblight_sethsv_noeeprom(uint16_t hue, uint8_t sat, uint8_t val) {
   inmem_config.raw = rgblight_config.raw;
index 8c33f1a8fc95944fa7b81f39fa259b62f636b89a..a6593af98bac6c55daff419393f95fe99ff933d9 100644 (file)
@@ -92,6 +92,7 @@ typedef union {
     uint16_t hue     :9;
     uint8_t  sat     :8;
     uint8_t  val     :8;
+    uint8_t  speed   :8;//EECONFIG needs to be increased to support this
   };
 } rgblight_config_t;
 
@@ -113,6 +114,8 @@ void rgblight_increase_sat(void);
 void rgblight_decrease_sat(void);
 void rgblight_increase_val(void);
 void rgblight_decrease_val(void);
+void rgblight_increase_speed(void);
+void rgblight_decrease_speed(void);
 void rgblight_sethsv(uint16_t hue, uint8_t sat, uint8_t val);
 uint16_t rgblight_get_hue(void);
 uint8_t rgblight_get_sat(void);
@@ -126,6 +129,9 @@ void eeconfig_update_rgblight(uint32_t val);
 void eeconfig_update_rgblight_default(void);
 void eeconfig_debug_rgblight(void);
 
+void rgb_matrix_increase(void);
+void rgb_matrix_decrease(void);
+
 void sethsv(uint16_t hue, uint8_t sat, uint8_t val, LED_TYPE *led1);
 void setrgb(uint8_t r, uint8_t g, uint8_t b, LED_TYPE *led1);
 void rgblight_sethsv_noeeprom(uint16_t hue, uint8_t sat, uint8_t val);