diff --git a/simulator.h b/simulator.h index 1491a51..6392706 100644 --- a/simulator.h +++ b/simulator.h @@ -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. diff --git a/simulator/analog_sim.c b/simulator/analog_sim.c index 7cef911..eea4d84 100644 --- a/simulator/analog_sim.c +++ b/simulator/analog_sim.c @@ -1,15 +1,41 @@ +#include "temp.h" #include "analog.h" #include "simulator.h" +#include 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 ) ; + } + } } diff --git a/simulator/simulator.c b/simulator/simulator.c index 96ee137..b157b47 100644 --- a/simulator/simulator.c +++ b/simulator/simulator.c @@ -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); }