From 3b315b3da0464efd39e1f5a379eaeba601c4871f Mon Sep 17 00:00:00 2001 From: Tim Koster Date: Fri, 6 Sep 2013 22:25:39 +0300 Subject: [PATCH 1/5] Added BlinkM support over i2c --- Marlin/BlinkM.cpp | 23 +++++++++++++++++++++++ Marlin/BlinkM.h | 14 ++++++++++++++ Marlin/Configuration.h | 3 +++ Marlin/Marlin_main.cpp | 17 +++++++++++++++++ 4 files changed, 57 insertions(+) create mode 100644 Marlin/BlinkM.cpp create mode 100644 Marlin/BlinkM.h diff --git a/Marlin/BlinkM.cpp b/Marlin/BlinkM.cpp new file mode 100644 index 0000000000..15a2527bbf --- /dev/null +++ b/Marlin/BlinkM.cpp @@ -0,0 +1,23 @@ +/* + BlinkM.cpp - Library for controlling a BlinkM over i2c + Created by Tim Koster, August 21 2013. +*/ +#if (ARDUINO >= 100) + # include "Arduino.h" +#else + # include "WProgram.h" +#endif +#include "BlinkM.h" + +void SendColors(byte red, byte grn, byte blu) +{ + Wire.begin(); + Wire.beginTransmission(0x09); + Wire.write('o'); //to disable ongoing script, only needs to be used once + Wire.write('n'); + Wire.write(red); + Wire.write(grn); + Wire.write(blu); + Wire.endTransmission(); +} + diff --git a/Marlin/BlinkM.h b/Marlin/BlinkM.h new file mode 100644 index 0000000000..5136828782 --- /dev/null +++ b/Marlin/BlinkM.h @@ -0,0 +1,14 @@ +/* + BlinkM.h + Library header file for BlinkM library + */ +#if (ARDUINO >= 100) + # include "Arduino.h" +#else + # include "WProgram.h" +#endif + +#include "Wire.h" + +void SendColors(byte red, byte grn, byte blu); + diff --git a/Marlin/Configuration.h b/Marlin/Configuration.h index 9ff27f5b00..67760abe3b 100644 --- a/Marlin/Configuration.h +++ b/Marlin/Configuration.h @@ -533,6 +533,9 @@ const bool Z_MAX_ENDSTOP_INVERTING = true; // set to true to invert the logic of # endif #endif +// define BlinkM Support +#define BlinkM + // Increase the FAN pwm frequency. Removes the PWM noise but increases heating in the FET/Arduino //#define FAST_PWM_FAN diff --git a/Marlin/Marlin_main.cpp b/Marlin/Marlin_main.cpp index 4609ce818e..26fbd41232 100644 --- a/Marlin/Marlin_main.cpp +++ b/Marlin/Marlin_main.cpp @@ -40,6 +40,9 @@ #include "language.h" #include "pins_arduino.h" +#include "BlinkM.h" +#include "Wire.h" + #if NUM_SERVOS > 0 #include "Servo.h" #endif @@ -109,6 +112,7 @@ // M128 - EtoP Open (BariCUDA EtoP = electricity to air pressure transducer by jmil) // M129 - EtoP Closed (BariCUDA EtoP = electricity to air pressure transducer by jmil) // M140 - Set bed target temp +// M150 - Set BlinkM Colour Output R: Red<0-255> U(!): Green<0-255> B: Blue<0-255> over i2c, G for green does not work. // M190 - Sxxx Wait for bed current temp to reach target temp. Waits only when heating // Rxxx Wait for bed current temp to reach target temp. Waits when heating and cooling // M200 - Set filament diameter @@ -1613,6 +1617,19 @@ void process_commands() #endif break; //TODO: update for all axis, use for loop + case 150: // M150 + { + byte red; + byte grn; + byte blu; + + if(code_seen('R')) red = code_value(); + if(code_seen('U')) grn = code_value(); + if(code_seen('B')) blu = code_value(); + + SendColors(red,grn,blu); + } + break; case 201: // M201 for(int8_t i=0; i < NUM_AXIS; i++) { From 7016cc951186d876e7812cbeb945f5d27b125fb7 Mon Sep 17 00:00:00 2001 From: Tim Koster Date: Tue, 10 Sep 2013 12:18:29 +0300 Subject: [PATCH 2/5] Added BlinkM support over i2c --- Marlin/BlinkM.cpp | 23 +++++++++++++++++++++++ Marlin/BlinkM.h | 14 ++++++++++++++ Marlin/Configuration.h | 3 +++ Marlin/Marlin_main.cpp | 17 +++++++++++++++++ 4 files changed, 57 insertions(+) create mode 100644 Marlin/BlinkM.cpp create mode 100644 Marlin/BlinkM.h diff --git a/Marlin/BlinkM.cpp b/Marlin/BlinkM.cpp new file mode 100644 index 0000000000..15a2527bbf --- /dev/null +++ b/Marlin/BlinkM.cpp @@ -0,0 +1,23 @@ +/* + BlinkM.cpp - Library for controlling a BlinkM over i2c + Created by Tim Koster, August 21 2013. +*/ +#if (ARDUINO >= 100) + # include "Arduino.h" +#else + # include "WProgram.h" +#endif +#include "BlinkM.h" + +void SendColors(byte red, byte grn, byte blu) +{ + Wire.begin(); + Wire.beginTransmission(0x09); + Wire.write('o'); //to disable ongoing script, only needs to be used once + Wire.write('n'); + Wire.write(red); + Wire.write(grn); + Wire.write(blu); + Wire.endTransmission(); +} + diff --git a/Marlin/BlinkM.h b/Marlin/BlinkM.h new file mode 100644 index 0000000000..5136828782 --- /dev/null +++ b/Marlin/BlinkM.h @@ -0,0 +1,14 @@ +/* + BlinkM.h + Library header file for BlinkM library + */ +#if (ARDUINO >= 100) + # include "Arduino.h" +#else + # include "WProgram.h" +#endif + +#include "Wire.h" + +void SendColors(byte red, byte grn, byte blu); + diff --git a/Marlin/Configuration.h b/Marlin/Configuration.h index 9ff27f5b00..195331252f 100644 --- a/Marlin/Configuration.h +++ b/Marlin/Configuration.h @@ -557,6 +557,9 @@ const bool Z_MAX_ENDSTOP_INVERTING = true; // set to true to invert the logic of // Support for the BariCUDA Paste Extruder. //#define BARICUDA +//define BlinkM/CyzRgb Support +//#define BlinkM + /*********************************************************************\ * R/C SERVO support * Sponsored by TrinityLabs, Reworked by codexmas diff --git a/Marlin/Marlin_main.cpp b/Marlin/Marlin_main.cpp index 4609ce818e..26fbd41232 100644 --- a/Marlin/Marlin_main.cpp +++ b/Marlin/Marlin_main.cpp @@ -40,6 +40,9 @@ #include "language.h" #include "pins_arduino.h" +#include "BlinkM.h" +#include "Wire.h" + #if NUM_SERVOS > 0 #include "Servo.h" #endif @@ -109,6 +112,7 @@ // M128 - EtoP Open (BariCUDA EtoP = electricity to air pressure transducer by jmil) // M129 - EtoP Closed (BariCUDA EtoP = electricity to air pressure transducer by jmil) // M140 - Set bed target temp +// M150 - Set BlinkM Colour Output R: Red<0-255> U(!): Green<0-255> B: Blue<0-255> over i2c, G for green does not work. // M190 - Sxxx Wait for bed current temp to reach target temp. Waits only when heating // Rxxx Wait for bed current temp to reach target temp. Waits when heating and cooling // M200 - Set filament diameter @@ -1613,6 +1617,19 @@ void process_commands() #endif break; //TODO: update for all axis, use for loop + case 150: // M150 + { + byte red; + byte grn; + byte blu; + + if(code_seen('R')) red = code_value(); + if(code_seen('U')) grn = code_value(); + if(code_seen('B')) blu = code_value(); + + SendColors(red,grn,blu); + } + break; case 201: // M201 for(int8_t i=0; i < NUM_AXIS; i++) { From 88dfeefca3c47158e634998c2ed96a21a6b04f50 Mon Sep 17 00:00:00 2001 From: Tim Koster Date: Tue, 10 Sep 2013 12:32:21 +0300 Subject: [PATCH 3/5] Define BlinkM default disabled --- Marlin/Configuration.h | 3 --- 1 file changed, 3 deletions(-) diff --git a/Marlin/Configuration.h b/Marlin/Configuration.h index 33b96f5b33..195331252f 100644 --- a/Marlin/Configuration.h +++ b/Marlin/Configuration.h @@ -533,9 +533,6 @@ const bool Z_MAX_ENDSTOP_INVERTING = true; // set to true to invert the logic of # endif #endif -// define BlinkM Support -#define BlinkM - // Increase the FAN pwm frequency. Removes the PWM noise but increases heating in the FET/Arduino //#define FAST_PWM_FAN From 61db046b3285c56dea66e658d9b8530debaf63a1 Mon Sep 17 00:00:00 2001 From: Tim Koster Date: Fri, 20 Sep 2013 10:57:42 +0300 Subject: [PATCH 4/5] Added #ifdef BLINKM around new code. Also refined BlinkM.h. --- Marlin/BlinkM.cpp | 1 + Marlin/BlinkM.h | 4 ++++ Marlin/Configuration.h | 2 +- Marlin/Marlin_main.cpp | 2 ++ 4 files changed, 8 insertions(+), 1 deletion(-) diff --git a/Marlin/BlinkM.cpp b/Marlin/BlinkM.cpp index 15a2527bbf..7b8a7867c2 100644 --- a/Marlin/BlinkM.cpp +++ b/Marlin/BlinkM.cpp @@ -7,6 +7,7 @@ #else # include "WProgram.h" #endif + #include "BlinkM.h" void SendColors(byte red, byte grn, byte blu) diff --git a/Marlin/BlinkM.h b/Marlin/BlinkM.h index 5136828782..fbb9399c23 100644 --- a/Marlin/BlinkM.h +++ b/Marlin/BlinkM.h @@ -8,7 +8,11 @@ # include "WProgram.h" #endif +#ifndef BLINKM +#define BLINKM + #include "Wire.h" void SendColors(byte red, byte grn, byte blu); +#endif diff --git a/Marlin/Configuration.h b/Marlin/Configuration.h index 195331252f..d3168b5450 100644 --- a/Marlin/Configuration.h +++ b/Marlin/Configuration.h @@ -558,7 +558,7 @@ const bool Z_MAX_ENDSTOP_INVERTING = true; // set to true to invert the logic of //#define BARICUDA //define BlinkM/CyzRgb Support -//#define BlinkM +//#define BLINKM /*********************************************************************\ * R/C SERVO support diff --git a/Marlin/Marlin_main.cpp b/Marlin/Marlin_main.cpp index 26fbd41232..7ecf6032c8 100644 --- a/Marlin/Marlin_main.cpp +++ b/Marlin/Marlin_main.cpp @@ -1617,6 +1617,7 @@ void process_commands() #endif break; //TODO: update for all axis, use for loop + #ifdef BLINKM case 150: // M150 { byte red; @@ -1630,6 +1631,7 @@ void process_commands() SendColors(red,grn,blu); } break; + #endif //BLINKM case 201: // M201 for(int8_t i=0; i < NUM_AXIS; i++) { From 97b0da0c2e33270ea56e7c801ce5c15b0c4d0a2f Mon Sep 17 00:00:00 2001 From: Tim Koster Date: Sun, 22 Sep 2013 10:43:27 +0300 Subject: [PATCH 5/5] Removed #ifndef BLINKM --- Marlin/BlinkM.h | 4 ---- 1 file changed, 4 deletions(-) diff --git a/Marlin/BlinkM.h b/Marlin/BlinkM.h index fbb9399c23..5136828782 100644 --- a/Marlin/BlinkM.h +++ b/Marlin/BlinkM.h @@ -8,11 +8,7 @@ # include "WProgram.h" #endif -#ifndef BLINKM -#define BLINKM - #include "Wire.h" void SendColors(byte red, byte grn, byte blu); -#endif