Sim: add --report-temptables option
Teach simulator to calculate temperatures for all possible ADC
values using the compiled-in temperature tables and report the
resulting conversion. Do no other run-time simulation; exit
after reporting the conversion results. Output is suitable for
gnuplot for example like this:
gnuplot --persist -e "plot '< ./sim -T0' u 1:2 with lines,
'< ./sim -T1' u 1:2 with lines"
This commit is contained in:
parent
ab55b86472
commit
47e62f572c
|
|
@ -142,6 +142,7 @@ void sim_error(const char msg[]);
|
|||
void sim_assert(bool cond, const char msg[]);
|
||||
void sim_gcode_ch(char ch);
|
||||
void sim_gcode(const char msg[]);
|
||||
void sim_report_temptables(int sensor) ;
|
||||
|
||||
/**
|
||||
* Initialize simulator timer and set time scale.
|
||||
|
|
|
|||
|
|
@ -1,15 +1,41 @@
|
|||
#include "temp.h"
|
||||
#include "analog.h"
|
||||
#include "simulator.h"
|
||||
#include <stdio.h>
|
||||
|
||||
static bool analog_initialised = false;
|
||||
|
||||
void analog_init(void) {
|
||||
sim_info("analog_init: not implemented in simulator");
|
||||
analog_initialised = true;
|
||||
}
|
||||
|
||||
static uint16_t analog_read_value = 0;
|
||||
uint16_t analog_read(uint8_t channel) {
|
||||
sim_assert(analog_initialised, "analog_init() was not called before analog_read()");
|
||||
sim_assert(sim_interrupts, "interrupts disabled");
|
||||
return 0;
|
||||
return analog_read_value;
|
||||
}
|
||||
|
||||
void sim_report_temptables(int sensor) {
|
||||
int i ;
|
||||
temp_sensor_t s, first = sensor, last = sensor+1 ;
|
||||
|
||||
// sensor is a specific sensor or -1 for "all sensors"
|
||||
if (sensor == -1) {
|
||||
first = 0;
|
||||
last = NUM_TEMP_SENSORS;
|
||||
}
|
||||
|
||||
sei();
|
||||
analog_init();
|
||||
printf("; Temperature sensor test %d\n", sensor);
|
||||
for (s = first; s < last; s++ ) {
|
||||
printf("; Sensor %d\n", s);
|
||||
for (i = 0 ; i < 1024 ; i++ ) {
|
||||
analog_read_value = i ;
|
||||
temp_sensor_tick() ;
|
||||
uint16_t temp = temp_get(s);
|
||||
printf("%d %.2f\n", i, ((float)temp)/4 ) ;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -45,7 +45,7 @@ int verbose = 1; ///< 0=quiet, 1=normal, 2=noisy, 3=debug, etc.
|
|||
int trace_gcode = 0; ///< show gcode on the console
|
||||
int trace_pos = 0; ///< show print head position on the console
|
||||
|
||||
const char * shortopts = "qgpvt:o::";
|
||||
const char * shortopts = "qgpvt:o::T::";
|
||||
struct option opts[] = {
|
||||
{ "quiet", no_argument, &verbose , 0 },
|
||||
{ "verbose", no_argument, NULL, 'v' },
|
||||
|
|
@ -53,6 +53,7 @@ struct option opts[] = {
|
|||
{ "pos", no_argument, NULL, 'p' },
|
||||
{ "time-scale", required_argument, NULL, 't' },
|
||||
{ "tracefile", optional_argument, NULL, 'o' },
|
||||
{ "report-temptable", optional_argument, NULL, 'T' },
|
||||
{ 0, 0, 0, 0 }
|
||||
};
|
||||
|
||||
|
|
@ -65,6 +66,7 @@ static void usage(const char *name) {
|
|||
printf(" -p || --pos show head position on console\n");
|
||||
printf(" -t || --time-scale=n set time-scale; 0=warp-speed, 1=real-time, 2=half-time, etc.\n");
|
||||
printf(" -o || --tracefile[=filename] write simulator pin trace to 'outfile' (default filename=datalog.out)\n");
|
||||
printf(" -T || --report-temptable=n Report calculated temperatures for all ADC values and exit\n");
|
||||
printf("\n");
|
||||
exit(1);
|
||||
}
|
||||
|
|
@ -96,6 +98,9 @@ void sim_start(int argc, char** argv) {
|
|||
case 'o':
|
||||
recorder_init(optarg ? optarg : "datalog.out");
|
||||
break;
|
||||
case 'T':
|
||||
sim_report_temptables(optarg ? atoi(optarg) : -1);
|
||||
exit(0);
|
||||
default:
|
||||
exit(1);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue