Bladeren bron

cosmetic whitespace cleanup and comments added/updated

Steffen Vogel 10 jaren geleden
bovenliggende
commit
538231edfd
1 gewijzigde bestanden met toevoegingen van 22 en 25 verwijderingen
  1. 22
    25
      Marlin/scripts/createTemperatureLookupMarlin.py

+ 22
- 25
Marlin/scripts/createTemperatureLookupMarlin.py Bestand weergeven

@@ -1,12 +1,8 @@
1 1
 #!/usr/bin/python
2
-#
3
-# Creates a C code lookup table for doing ADC to temperature conversion
4
-# on a microcontroller
5
-# based on: http://hydraraptor.blogspot.com/2007/10/measuring-temperature-easy-way.html
6 2
 """Thermistor Value Lookup Table Generator
7 3
 
8 4
 Generates lookup to temperature values for use in a microcontroller in C format based on: 
9
-http://hydraraptor.blogspot.com/2007/10/measuring-temperature-easy-way.html
5
+http://en.wikipedia.org/wiki/Steinhart-Hart_equation
10 6
 
11 7
 The main use is for Arduino programs that read data from the circuit board described here:
12 8
 http://make.rrrf.org/ts-1.0
@@ -19,7 +15,7 @@ Options:
19 15
   --t1=ttt:rrr      low temperature temperature:resistance point (around 25C)
20 16
   --t2=ttt:rrr      middle temperature temperature:resistance point (around 150C)
21 17
   --t3=ttt:rrr      high temperature temperature:resistance point (around 250C)
22
-  --num-temps=...   the number of temperature points to calculate (default: 20)
18
+  --num-temps=...   the number of temperature points to calculate (default: 36)
23 19
 """
24 20
 
25 21
 from math import *
@@ -86,15 +82,15 @@ class Thermistor:
86 82
         return (r / (self.rp + r)) * (1024)
87 83
 
88 84
 def main(argv):
89
-
90
-    rp = 4700;
91
-    t1 = 25;
92
-    r1 = 100000;
93
-    t2 = 150;
94
-    r2 = 1641.9;
95
-    t3 = 250;
96
-    r3 = 226.15;
97
-    num_temps = int(36);
85
+    "Default values"
86
+    t1 = 25                                 # low temperature in Kelvin (25 degC)
87
+    r1 = 100000                             # resistance at low temperature (10 kOhm)
88
+    t2 = 150                                # middle temperature in Kelvin (150 degC)
89
+    r2 = 1641.9                             # resistance at middle temperature (1.6 KOhm)
90
+    t3 = 250                                # high temperature in Kelvin (250 degC)
91
+    r3 = 226.15                             # resistance at high temperature (226.15 Ohm)
92
+    rp = 4700;                              # pull-up resistor (4.7 kOhm)
93
+    num_temps = int(36);                    # number of entries for look-up table
98 94
     
99 95
     try:
100 96
         opts, args = getopt.getopt(argv, "h", ["help", "rp=", "t1=", "t2=", "t3=", "num-temps="])
@@ -102,7 +98,7 @@ def main(argv):
102 98
         print  str(err)
103 99
         usage()
104 100
         sys.exit(2)
105
-        
101
+
106 102
     for opt, arg in opts:
107 103
         if opt in ("-h", "--help"):
108 104
             usage()
@@ -111,16 +107,16 @@ def main(argv):
111 107
             rp = int(arg)
112 108
         elif opt == "--t1":
113 109
             arg =  arg.split(':')
114
-            t1 = float( arg[0])
115
-            r1 = float( arg[1])
110
+            t1 = float(arg[0])
111
+            r1 = float(arg[1])
116 112
         elif opt == "--t2":
117 113
             arg =  arg.split(':')
118
-            t2 = float( arg[0])
119
-            r2 = float( arg[1])
114
+            t2 = float(arg[0])
115
+            r2 = float(arg[1])
120 116
         elif opt == "--t3":
121 117
             arg =  arg.split(':')
122
-            t3 = float( arg[0])
123
-            r3 = float( arg[1])
118
+            t3 = float(arg[0])
119
+            r3 = float(arg[1])
124 120
         elif opt == "--num-temps":
125 121
             num_temps =  int(arg)
126 122
 
@@ -136,8 +132,9 @@ def main(argv):
136 132
 
137 133
     print "// Thermistor lookup table for Marlin"
138 134
     print "// ./createTemperatureLookupMarlin.py --rp=%s --t1=%s:%s --t2=%s:%s --t3=%s:%s --num-temps=%s" % (rp, t1, r1, t2, r2, t3, r3, num_temps)
139
-    print "// Steinhart-Hart Coefficients: %.15g, %.15g,  %.15g " % (t.c1, t.c2, t.c3)
140
-    print "//#define NUMTEMPS %s" % (len(temps))
135
+    print "// Steinhart-Hart Coefficients: a=%.15g, b=%.15g, c=%.15g " % (t.c1, t.c2, t.c3)
136
+    print
137
+    print "#define NUMTEMPS %s" % (len(temps))
141 138
     print "const short temptable[NUMTEMPS][2] PROGMEM = {"
142 139
 
143 140
     counter = 0
@@ -148,7 +145,7 @@ def main(argv):
148 145
         else:
149 146
             print "   {(short)(%.2f*OVERSAMPLENR), %s}, // v=%s r=%s res=%s C/count" % ((t.adc(temp)), temp, t.v(t.adc(temp)), t.r(t.adc(temp)),t.res(t.adc(temp)))
150 147
     print "};"
151
-    
148
+
152 149
 def usage():
153 150
     print __doc__
154 151
 

Laden…
Annuleren
Opslaan