<commit_before>package main

import (
	"io/ioutil"
	"log"
	"os"
	"os/signal"
	"time"

	"github.com/stianeikeland/go-rpio"
	"gopkg.in/yaml.v2"
)

const bfSizeChLED = 4096

func main() {
	chSig := make(chan os.Signal, 1)
	signal.Notify(chSig, os.Interrupt, os.Kill)

	if len(os.Args) < 2 {
		os.Stderr.WriteString("A configuration YAML file path should specified as a command argument.\n")
		os.Exit(1)
	}

	path := os.Args[1]

	b, err := ioutil.ReadFile(path)
	if err != nil {
		log.Panic(err)
	}

	var cnf Config

	if err := yaml.Unmarshal(b, &cnf); err != nil {
		log.Panic(err)
	}

	if err := rpio.Open(); err != nil {
		log.Panic(err)
	}

	defer rpio.Close()

	chLED, chLEDDone := ledOn(cnf)

	defer func() {
		close(chLED)
		<-chLEDDone
		log.Println("Closed the LED channel")
	}()

	pin := rpio.Pin(cnf.MotionPinNo)
	pin.Input()

	log.Println("Ready")

	ticker := time.NewTicker(1 * time.Second)

	for {
		if pin.Read() == rpio.High {
			log.Println("Motion detected")
			chLED <- struct{}{}
		}

		select {
		case <-ticker.C:
		case sig := <-chSig:
			log.Println("Got signal:", sig)
			return
		}
	}
}

func ledOn(cnf Config) (chan<- struct{}, <-chan struct{}) {
	chLED := make(chan struct{}, bfSizeChLED)
	chLEDDone := make(chan struct{})

	go func() {
		pin := rpio.Pin(cnf.LEDPinNo)
		pin.Output()

		for _ = range chLED {
			log.Println("LED on")<commit_msg>Update main.go<commit_after>package main

import (
	"io/ioutil"
	"log"
	"os"
	"os/signal"
	"time"

	"github.com/stianeikeland/go-rpio"
	"gopkg.in/yaml.v2"
)

const bfSizeChLED = 4096

func main() {
	chSig := make(chan os.Signal, 1)
	signal.Notify(chSig, os.Interrupt, os.Kill)

	if len(os.Args) < 2 {
		os.Stderr.WriteString("A configuration YAML file path should specified as a command argument.\n")
		os.Exit(1)
	}

	path := os.Args[1]

	b, err := ioutil.ReadFile(path)
	if err != nil {
		log.Panic(err)
	}

	var cnf Config

	if err := yaml.Unmarshal(b, &cnf); err != nil {
		log.Panic(err)
	}

	if err := rpio.Open(); err != nil {
		log.Panic(err)
	}

	defer rpio.Close()

	chLED, chLEDDone := ledOn(cnf)

	defer func() {
		close(chLED)
		<-chLEDDone
	}()

	pin := rpio.Pin(cnf.MotionPinNo)
	pin.Input()

	log.Println("Ready")

	ticker := time.NewTicker(1 * time.Second)

	defer ticker.Stop()

	for {
		if pin.Read() == rpio.High {
			log.Println("Motion detected")
			chLED <- struct{}{}
		}

		select {
		case <-ticker.C:
		case sig := <-chSig:
			log.Println("Got signal:", sig)
			return
		}
	}
}

func ledOn(cnf Config) (chan<- struct{}, <-chan struct{}) {
	chLED := make(chan struct{}, bfSizeChLED)
	chLEDDone := make(chan struct{})

	go func() {
		pin := rpio.Pin(cnf.LEDPinNo)
		pin.Output()

		for _ = range chLED {
			log.Println("LED on")
{'fraction_non_alphanumeric': 0.17456817346563763, 'fraction_numerical': 0.00735023888276369, 'mean_word_length': 3.2464898595943836, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 3, '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': '838304', 'n_tokens_mistral': 1263, 'n_tokens_neox': 1139, 'n_words': 246}