<commit_before>//  How to access GPIO registers from C-code on the Raspberry-Pi
//  Example program
//  15-January-2012
//  <NAME>
//  Example extended to continually output to
//  YAML files for parsing by other programs
//  brianb Oct 2013


// Access from ARM Running Linux


#define BCM2708_PERI_BASE        0x20000000
#define GPIO_BASE                (BCM2708_PERI_BASE + 0x200000) /* GPIO controller */

// want time n such?
// #define __USE_POSIX 1

#include <unistd.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdarg.h>
#include <dirent.h>
#include <fcntl.h>
#include <assert.h>
#include <unistd.h>
#include <sys/mman.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/time.h>
#include <time.h>
#include <bcm2835.h>

#define MAXTIMINGS 100

//#define DEBUG 1

#define DHT11 11
#define DHT22 22
#define AM2302 22

// hard code the sensor type, can turn it back to a parameter if you like
#define SENSOR_TYPE DHT22

void log_err(char *fmt, ... ) {

  // get current time - "canonical" (not-exactly-iso8601?)
  time_t now_time = time(NULL);
  struct tm now_tm = {0};
  localtime_r(&now_time, &now_tm);
  char now_str[40];
  strftime(now_str, sizeof now_str, "%FT%T%Z", &now_tm);
  fputs(now_str,stderr);

	va_list args;
	va_start(args, fmt);
	vfprintf(stderr, fmt, args);
	va_end(args);
}

void log_debug(char *fmt, ... ) {
  // get current time - "canonical" (not-exactly-iso8601?)
  time_t now_time = time(NULL);
  struct tm now_tm = {0};
  localtime_r(&now_time, &now_tm);
  char now_str[40];
  strftime(now_str, sizeof now_str, "%FT%T%Z", &now_tm);
  fputs(now_str,stdout);

	va_list args;
	va_start(args, fmt);
	vfprintf(stdout, fmt, args);
	va_end(args);
}


// read only globals set from command line
//
int     g_pin;
char    *g_sensor_name;
char    *g_dir_name;
char    g_delay;
char    g_history_fn[255];
char    g_stats_fn[255];


int sample_sensor(void) {

  int counter = 0;
  int laststate = HIGH;
  int j=0;

#ifdef DEBUG
  log_debug( "sampling sensor %s at pin %d\n",g_sensor_name,g_pin);
#endif

  // Set GPIO pin to output
  bcm2835_gpio_fsel(g_pin, BCM2835_GPIO_FSEL_OUTP);

  bcm2835_gpio_write(g_pin, HIGH);
  usleep(500000);
  bcm2835_gpio_write(g_pin, LOW);
  usleep(20000);<commit_msg>Updated the logging a little more<commit_after>//  How to access GPIO registers from C-code on the Raspberry-Pi
//  Example program
//  15-January-2012
//  <NAME>
//  Example extended to continually output to
//  YAML files for parsing by other programs
//  brianb Oct 2013


// Access from ARM Running Linux


#define BCM2708_PERI_BASE        0x20000000
#define GPIO_BASE                (BCM2708_PERI_BASE + 0x200000) /* GPIO controller */

// want time n such?
// #define __USE_POSIX 1

#include <unistd.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdarg.h>
#include <dirent.h>
#include <fcntl.h>
#include <assert.h>
#include <unistd.h>
#include <sys/mman.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/time.h>
#include <time.h>
#include <bcm2835.h>

#define MAXTIMINGS 100

//#define DEBUG 1

#define DHT11 11
#define DHT22 22
#define AM2302 22

// hard code the sensor type, can turn it back to a parameter if you like
#define SENSOR_TYPE DHT22

void log_err(char *fmt, ... ) {

  // get current time - "canonical" (not-exactly-iso8601?)
  time_t now_time = time(NULL);
  struct tm now_tm = {0};
  localtime_r(&now_time, &now_tm);
  char now_str[40];
  strftime(now_str, sizeof now_str, "%FT%T%Z ", &now_tm);
  fputs(now_str,stderr);

	va_list args;
	va_start(args, fmt);
	vfprintf(stderr, fmt, args);
	va_end(args);
	fflush(stderr);
}

void log_debug(char *fmt, ... ) {
  // get current time - "canonical" (not-exactly-iso8601?)
  time_t now_time = time(NULL);
  struct tm now_tm = {0};
  localtime_r(&now_time, &now_tm);
  char now_str[40];
  strftime(now_str, sizeof now_str, "%FT%T%Z ", &now_tm);
  fputs(now_str,stdout);

	va_list args;
	va_start(args, fmt);
	vfprintf(stdout, fmt, args);
	va_end(args);
	fflush(stdout);
}


// read only globals set from command line
//
int     g_pin;
char    *g_sensor_name;
char    *g_dir_name;
char    g_delay;
char    g_history_fn[255];
char    g_stats_fn[255];


int sample_sensor(void) {

  int counter = 0;
  int laststate = HIGH;
  int j=0;

#ifdef DEBUG
  log_debug( "sampling sensor %s at pin %d\n",g_sensor_name,g_pin);
#endif

  // Set GPIO pin to output
  bcm2835_gpio_fsel(g_pin, BCM2835_GPIO_FSEL_OUTP);

  bcm2835_gpio_write(g_pin, HIGH);
  usleep(500000);
  bcm2835_gpio_write(g_pin, LOW);
  usleep(20000);
{'fraction_non_alphanumeric': 0.13371328364752302, 'fraction_numerical': 0.04734765453748356, 'mean_word_length': 3.8336864406779663, 'pattern_counts': {'":': 0, '<': 35, '<?xml version=': 0, '>': 35, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 2, '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': '5581493', 'n_tokens_mistral': 1994, 'n_tokens_neox': 1817, 'n_words': 472}