<commit_before>/*
Copyright (c) 2013 <NAME>. All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
   notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
   notice, this list of conditions and the following disclaimer in the
   documentation and/or other materials provided with the distribution.

THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE.
*/

#include <stdio.h>
#include <unistd.h>
#include "input.h"

int
main(int argc, char **argv)
{
	int i, p, act;
	struct hardware hw;

	if (set_mode(0, NULL, NULL)) {
		cleanup();
		return 0;
	}

	(void)read_hardware_parameters(ETCDIR"/hardware.txt", &hw);
	/* get our own copy, error handling in set_mode() */

	printf("%i\n", (int)(hw.freq * hw.min_len / 100));
	for (i = act = 0;; i++) {
		p = get_pulse();
		if (p & GETBIT_IO) {
			printf("IO error!\n");
			break;
		}
		act += p;
		printf("%c", p == 1 ? '+' : ' ');
		if (i == (int)(hw.freq * hw.min_len / 100)) {
			printf(" %lu\n", act*hw.freq/hw.min_len);
			i = act = 0;
		}
		(void)usleep(1000000.0 / hw.freq);
	}
	cleanup();
	return 0;
}<commit_msg>Overhaul readpin.c with the following changes: - limit the pulse length both ways by using the new 'hw.max_len' field - use correct value for 'count' - limit the range in which a second may end (either [minlimit..maxlimit]   or [minlimit*2..maxlimit*2]) to prevent false EOM markers during e.g.   thunderstorms - deal with the initial partial second<commit_after>/*
Copyright (c) 2013 <NAME>. All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
   notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
   notice, this list of conditions and the following disclaimer in the
   documentation and/or other materials provided with the distribution.

THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE.
*/

#include <stdio.h>
#include <unistd.h>
#include "input.h"

int
main(int argc, char **argv)
{
	int i, p, p0, act, pas, minlimit, maxlimit, count, sec, init;
	struct hardware hw;

	if (set_mode(0, NULL, NULL)) {
		cleanup();
		return 0;
	}

	(void)read_hardware_parameters(ETCDIR"/hardware.txt", &hw);
	/* get our own copy, error handling in set_mode() */

	p0 = -1;
	minlimit = hw.freq * hw.min_len / 100;
	maxlimit = hw.freq * hw.max_len / 100;
	init = 1;
	printf("limit=[%i..%i]\n", minlimit, maxlimit);

	for (i = act = pas = 0;; i++) {
		p = get_pulse();
		if (p & GETBIT_IO) {
			printf("IO error!\n");
			break;
		}
		if (p == 0) {
			pas++;
			//printf("-");
		} else { /* p == 1 */
			act++;
			if (p0 == 0) {
				count = act * 100/i;
				if (i > minlimit * 2 && i < maxlimit * 2)
					count *= 2;
				printf(" (%i %i %i) %i ", act, pas, i, count);
				if (i > minlimit && (init || i < maxlimit)) {
					i = act = pas = 0;
					init = 0;
				} else if (i > minlimit * 2 && (init || i < maxlimit * 2)) {
					i = act = pas = 0;
					init = 0;
				}
			}
			//printf("+");
		}
		p0 = p;
		(void)usleep(1000000.0 / hw.freq);
	}
	cleanup();
	return 0;
}
{'fraction_non_alphanumeric': 0.10974593919200333, 'fraction_numerical': 0.015201999167013744, 'mean_word_length': 3.7042115572967678, 'pattern_counts': {'":': 0, '<': 12, '<?xml version=': 0, '>': 12, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '552977', 'n_tokens_mistral': 1704, 'n_tokens_neox': 1462, 'n_words': 643}