Convert decoder limits to float instead of int, to allow more precision

The (about to be submitted) emonTx decoder really needs to be allowed to
specify a limit of 20.3µs, and neither '50 samples' (20µs) nor
'51 samples' (24µs) will suffice.
This commit is contained in:
David Woodhouse
2016-01-22 10:07:35 +00:00
parent 889f3adb50
commit a06fb730f9
3 changed files with 6 additions and 6 deletions

View File

@@ -63,9 +63,9 @@ struct protocol_state {
unsigned int modulation;
/* pwm limits */
int short_limit;
int long_limit;
int reset_limit;
float short_limit;
float long_limit;
float reset_limit;
char *name;
unsigned long demod_arg;
};

View File

@@ -242,7 +242,7 @@ int pulse_demod_manchester_zerobit(const pulse_data_t *pulses, struct protocol_s
for(unsigned n = 0; n < pulses->num_pulses; ++n) {
// Falling edge is on end of pulse
if(pulses->pulse[n] + time_since_last > (device->short_limit + (device->short_limit>>1))) {
if(pulses->pulse[n] + time_since_last > (device->short_limit * 1.5)) {
// Last bit was recorded more than short_limit*1.5 samples ago
// so this pulse start must be a data edge (falling data edge means bit = 1)
bitbuffer_add_bit(&bits, 1);
@@ -266,7 +266,7 @@ int pulse_demod_manchester_zerobit(const pulse_data_t *pulses, struct protocol_s
bitbuffer_add_bit(&bits, 0); // Prepare for new message with hardcoded 0
time_since_last = 0;
// Rising edge is on end of gap
} else if(pulses->gap[n] + time_since_last > (device->short_limit + (device->short_limit>>1))) {
} else if(pulses->gap[n] + time_since_last > (device->short_limit * 1.5)) {
// Last bit was recorded more than short_limit*1.5 samples ago
// so this pulse end is a data edge (rising data edge means bit = 0)
bitbuffer_add_bit(&bits, 0);

View File

@@ -502,7 +502,7 @@ void pulse_analyzer(pulse_data_t *data)
}
if(device.modulation) {
fprintf(stderr, "Attempting demodulation... short_limit: %u, long_limit: %u, reset_limit: %u, demod_arg: %lu\n",
fprintf(stderr, "Attempting demodulation... short_limit: %f, long_limit: %f, reset_limit: %f, demod_arg: %lu\n",
device.short_limit, device.long_limit, device.reset_limit, device.demod_arg);
data->gap[data->num_pulses-1] = device.reset_limit + 1; // Be sure to terminate package
switch(device.modulation) {