Subversion Repositories Tronxy-X3A-Marlin

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
1 ron 1
/**
2
 * Marlin 3D Printer Firmware
3
 * Copyright (C) 2016 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
4
 *
5
 * Based on Sprinter and grbl.
6
 * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
7
 *
8
 * This program is free software: you can redistribute it and/or modify
9
 * it under the terms of the GNU General Public License as published by
10
 * the Free Software Foundation, either version 3 of the License, or
11
 * (at your option) any later version.
12
 *
13
 * This program is distributed in the hope that it will be useful,
14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
 * GNU General Public License for more details.
17
 *
18
 * You should have received a copy of the GNU General Public License
19
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
20
 *
21
 */
22
 
23
/**
24
 * leds.cpp - Marlin RGB LED general support
25
 */
26
 
27
#include "MarlinConfig.h"
28
 
29
#if HAS_COLOR_LEDS
30
 
31
#include "leds.h"
32
 
33
#if ENABLED(BLINKM)
34
  #include "blinkm.h"
35
#endif
36
 
37
#if ENABLED(PCA9632)
38
  #include "pca9632.h"
39
#endif
40
 
41
#if ENABLED(LED_COLOR_PRESETS)
42
  const LEDColor LEDLights::defaultLEDColor = MakeLEDColor(
43
    LED_USER_PRESET_RED,
44
    LED_USER_PRESET_GREEN,
45
    LED_USER_PRESET_BLUE,
46
    LED_USER_PRESET_WHITE,
47
    LED_USER_PRESET_BRIGHTNESS
48
  );
49
#endif
50
 
51
#if ENABLED(LED_CONTROL_MENU)
52
  LEDColor LEDLights::color;
53
  bool LEDLights::lights_on;
54
#endif
55
 
56
LEDLights leds;
57
 
58
void LEDLights::setup() {
59
  #if ENABLED(NEOPIXEL_LED)
60
    setup_neopixel();
61
  #endif
62
  #if ENABLED(LED_USER_PRESET_STARTUP)
63
    set_default();
64
  #endif
65
}
66
 
67
void LEDLights::set_color(const LEDColor &incol
68
  #if ENABLED(NEOPIXEL_LED)
69
    , bool isSequence/*=false*/
70
  #endif
71
) {
72
 
73
  #if ENABLED(NEOPIXEL_LED)
74
 
75
    const uint32_t neocolor = pixels.Color(incol.r, incol.g, incol.b, incol.w);
76
    static uint16_t nextLed = 0;
77
 
78
    pixels.setBrightness(incol.i);
79
    if (!isSequence)
80
      set_neopixel_color(neocolor);
81
    else {
82
      pixels.setPixelColor(nextLed, neocolor);
83
      pixels.show();
84
      if (++nextLed >= pixels.numPixels()) nextLed = 0;
85
      return;
86
    }
87
 
88
  #endif
89
 
90
  #if ENABLED(BLINKM)
91
 
92
    // This variant uses i2c to send the RGB components to the device.
93
    blinkm_set_led_color(incol);
94
 
95
  #endif
96
 
97
  #if ENABLED(RGB_LED) || ENABLED(RGBW_LED)
98
 
99
    // This variant uses 3-4 separate pins for the RGB(W) components.
100
    // If the pins can do PWM then their intensity will be set.
101
    WRITE(RGB_LED_R_PIN, incol.r ? HIGH : LOW);
102
    WRITE(RGB_LED_G_PIN, incol.g ? HIGH : LOW);
103
    WRITE(RGB_LED_B_PIN, incol.b ? HIGH : LOW);
104
    analogWrite(RGB_LED_R_PIN, incol.r);
105
    analogWrite(RGB_LED_G_PIN, incol.g);
106
    analogWrite(RGB_LED_B_PIN, incol.b);
107
 
108
    #if ENABLED(RGBW_LED)
109
      WRITE(RGB_LED_W_PIN, incol.w ? HIGH : LOW);
110
      analogWrite(RGB_LED_W_PIN, incol.w);
111
    #endif
112
 
113
  #endif
114
 
115
  #if ENABLED(PCA9632)
116
    // Update I2C LED driver
117
    pca9632_set_led_color(incol);
118
  #endif
119
 
120
  #if ENABLED(LED_CONTROL_MENU)
121
    // Don't update the color when OFF
122
    lights_on = !incol.is_off();
123
    if (lights_on) color = incol;
124
  #endif
125
}
126
 
127
void LEDLights::set_white() {
128
  #if ENABLED(RGB_LED) || ENABLED(RGBW_LED) || ENABLED(BLINKM) || ENABLED(PCA9632)
129
    set_color(LEDColorWhite());
130
  #endif
131
  #if ENABLED(NEOPIXEL_LED)
132
    set_neopixel_color(pixels.Color(NEO_WHITE));
133
  #endif
134
}
135
 
136
#if ENABLED(LED_CONTROL_MENU)
137
  void LEDLights::toggle() { if (lights_on) set_off(); else update(); }
138
#endif
139
 
140
#endif // HAS_COLOR_LEDS