Browse Source

Added M42, M80 and M81

Erik van der Zalm 13 years ago
parent
commit
d7c4f0780b
2 changed files with 41 additions and 1 deletions
  1. 37
    1
      Marlin/Marlin.pde
  2. 4
    0
      Marlin/pins.h

+ 37
- 1
Marlin/Marlin.pde View File

69
 // M114 - Display current position
69
 // M114 - Display current position
70
 
70
 
71
 //Custom M Codes
71
 //Custom M Codes
72
-// M80  - Turn on Power Supply
73
 // M20  - List SD card
72
 // M20  - List SD card
74
 // M21  - Init SD card
73
 // M21  - Init SD card
75
 // M22  - Release SD card
74
 // M22  - Release SD card
80
 // M27  - Report SD print status
79
 // M27  - Report SD print status
81
 // M28  - Start SD write (M28 filename.g)
80
 // M28  - Start SD write (M28 filename.g)
82
 // M29  - Stop SD write
81
 // M29  - Stop SD write
82
+// M42  - Change pin status via gcode
83
+// M80  - Turn on Power Supply
83
 // M81  - Turn off Power Supply
84
 // M81  - Turn off Power Supply
84
 // M82  - Set E codes absolute (default)
85
 // M82  - Set E codes absolute (default)
85
 // M83  - Set E codes relative while in Absolute Coordinates (G90) mode
86
 // M83  - Set E codes relative while in Absolute Coordinates (G90) mode
142
 
143
 
143
 #include "EEPROM.h"
144
 #include "EEPROM.h"
144
 
145
 
146
+const int sensitive_pins[] = SENSITIVE_PINS; // Sensitive pin list for M42
147
+
145
 float tt = 0, bt = 0;
148
 float tt = 0, bt = 0;
146
 #ifdef WATCHPERIOD
149
 #ifdef WATCHPERIOD
147
 int watch_raw = -1000;
150
 int watch_raw = -1000;
772
 		}
775
 		}
773
 				break;
776
 				break;
774
 #endif //SDSUPPORT
777
 #endif //SDSUPPORT
778
+      case 42: //M42 -Change pin status via gcode
779
+        if (code_seen('S'))
780
+        {
781
+          int pin_status = code_value();
782
+          if (code_seen('P') && pin_status >= 0 && pin_status <= 255)
783
+          {
784
+            int pin_number = code_value();
785
+            for(int i = 0; i < sizeof(sensitive_pins); i++)
786
+            {
787
+              if (sensitive_pins[i] == pin_number)
788
+              {
789
+                pin_number = -1;
790
+                break;
791
+              }
792
+            }
793
+            
794
+            if (pin_number > -1)
795
+            {              
796
+              pinMode(pin_number, OUTPUT);
797
+              digitalWrite(pin_number, pin_status);
798
+              analogWrite(pin_number, pin_status);
799
+            }
800
+          }
801
+        }
802
+        break;
775
       case 104: // M104
803
       case 104: // M104
776
                 if (code_seen('S')) target_raw[0] = temp2analog(code_value());
804
                 if (code_seen('S')) target_raw[0] = temp2analog(code_value());
777
 #ifdef PIDTEMP
805
 #ifdef PIDTEMP
908
         analogWrite(FAN_PIN, 0);
936
         analogWrite(FAN_PIN, 0);
909
         break;
937
         break;
910
 #endif
938
 #endif
939
+#if (PS_ON_PIN > -1)
940
+      case 80: // M80 - ATX Power On
941
+        SET_OUTPUT(PS_ON_PIN); //GND
942
+        break;
943
+      case 81: // M81 - ATX Power Off
944
+        SET_INPUT(PS_ON_PIN); //Floating
945
+        break;
946
+#endif
911
     case 82:
947
     case 82:
912
       axis_relative_modes[3] = false;
948
       axis_relative_modes[3] = false;
913
       break;
949
       break;

+ 4
- 0
Marlin/pins.h View File

563
 #ifndef KNOWN_BOARD
563
 #ifndef KNOWN_BOARD
564
 #error Unknown MOTHERBOARD value in configuration.h
564
 #error Unknown MOTHERBOARD value in configuration.h
565
 #endif
565
 #endif
566
+
567
+//List of pins which to ignore when asked to change by gcode, 0 and 1 are RX and TX, do not mess with those!
568
+#define SENSITIVE_PINS {0, 1, X_STEP_PIN, X_DIR_PIN, X_ENABLE_PIN, X_MIN_PIN, X_MAX_PIN, Y_STEP_PIN, Y_DIR_PIN, Y_ENABLE_PIN, Y_MIN_PIN, Y_MAX_PIN, Z_STEP_PIN, Z_DIR_PIN, Z_ENABLE_PIN, Z_MIN_PIN, Z_MAX_PIN, E_STEP_PIN, E_DIR_PIN, E_ENABLE_PIN, LED_PIN, PS_ON_PIN, HEATER_0_PIN, HEATER_1_PIN, HEATER_2_PIN, FAN_PIN, TEMP_0_PIN, TEMP_1_PIN, TEMP_2_PIN}
569
+
566
 #endif
570
 #endif

Loading…
Cancel
Save