]> git.donarmstrong.com Git - qmk_firmware.git/blobdiff - quantum/rgblight.c
First pass at reorganizing docs
[qmk_firmware.git] / quantum / rgblight.c
index 4e2671d24337da972ad870eab2005d3b6e2eb3ca..4919ae4abfe4fac3fe6cc1173245ed778cc944b6 100644 (file)
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 #include <math.h>
-#include <avr/eeprom.h>
-#include <avr/interrupt.h>
-#include <util/delay.h>
+#ifdef __AVR__
+  #include <avr/eeprom.h>
+  #include <avr/interrupt.h>
+#endif
+#include "wait.h"
 #include "progmem.h"
 #include "timer.h"
 #include "rgblight.h"
@@ -113,13 +115,19 @@ void setrgb(uint8_t r, uint8_t g, uint8_t b, LED_TYPE *led1) {
 
 
 uint32_t eeconfig_read_rgblight(void) {
-  return eeprom_read_dword(EECONFIG_RGBLIGHT);
+  #ifdef __AVR__
+    return eeprom_read_dword(EECONFIG_RGBLIGHT);
+  #else
+    return 0;
+  #endif
 }
 void eeconfig_update_rgblight(uint32_t val) {
-  eeprom_update_dword(EECONFIG_RGBLIGHT, val);
+  #ifdef __AVR__
+    eeprom_update_dword(EECONFIG_RGBLIGHT, val);
+  #endif
 }
 void eeconfig_update_rgblight_default(void) {
-  dprintf("eeconfig_update_rgblight_default\n");
+  //dprintf("eeconfig_update_rgblight_default\n");
   rgblight_config.enable = 1;
   rgblight_config.mode = 1;
   rgblight_config.hue = 0;
@@ -239,7 +247,7 @@ void rgblight_mode_eeprom_helper(uint8_t mode, bool write_to_eeprom) {
       rgblight_timer_disable();
     #endif
   } else if ((rgblight_config.mode >= 2 && rgblight_config.mode <= 24) ||
-            rgblight_config.mode == 35 ) {
+            rgblight_config.mode == 35 || rgblight_config.mode == 36) {
     // MODE 2-5, breathing
     // MODE 6-8, rainbow mood
     // MODE 9-14, rainbow swirl
@@ -247,6 +255,7 @@ void rgblight_mode_eeprom_helper(uint8_t mode, bool write_to_eeprom) {
     // MODE 21-23, knight
     // MODE 24, xmas
     // MODE 35  RGB test
+    // MODE 36, alterating
 
     #ifdef RGBLIGHT_ANIMATIONS
       rgblight_timer_enable();
@@ -311,7 +320,7 @@ void rgblight_disable(void) {
   #ifdef RGBLIGHT_ANIMATIONS
     rgblight_timer_disable();
   #endif
-  _delay_ms(50);
+  wait_ms(50);
   rgblight_set();
 }
 
@@ -583,6 +592,8 @@ void rgblight_task(void) {
     } else if (rgblight_config.mode == 35) {
       // mode = 35, RGB test
       rgblight_effect_rgbtest();
+    } else if (rgblight_config.mode == 36){
+      rgblight_effect_alternating();
     }
   }
 }
@@ -764,4 +775,25 @@ void rgblight_effect_rgbtest(void) {
   pos = (pos + 1) % 3;
 }
 
+void rgblight_effect_alternating(void){
+  static uint16_t last_timer = 0;
+  static uint16_t pos = 0;
+  if (timer_elapsed(last_timer) < 500) {
+    return;
+  }
+  last_timer = timer_read();
+
+  for(int i = 0; i<RGBLED_NUM; i++){
+                 if(i<RGBLED_NUM/2 && pos){
+                         rgblight_sethsv_at(rgblight_config.hue, rgblight_config.sat, rgblight_config.val, i);
+                 }else if (i>=RGBLED_NUM/2 && !pos){
+                         rgblight_sethsv_at(rgblight_config.hue, rgblight_config.sat, rgblight_config.val, i);
+                 }else{
+                         rgblight_sethsv_at(rgblight_config.hue, rgblight_config.sat, 0, i);
+                 }
+  }
+  rgblight_set();
+  pos = (pos + 1) % 2;
+}
+
 #endif /* RGBLIGHT_ANIMATIONS */