<commit_before>package RaspberryPi::Backend::BCM2835;

use parent(RaspberryPi::Backend::Base);

sub is_available{
	my $verbose = shift;
	eval{ require Device::BCM2835; };
	if ($@) {
		print "Unable to load module Device::BCM2835\n" . $@ if $verbose;
		return 0;
	}
	unless ($<) {
		print "Should be executed by superuser\n" if $verbose;
	}
	return 1;
}

1;
<commit_msg>Add init and set_output methods for BCM2835 backend.<commit_after>package RaspberryPi::Backend::BCM2835;

use parent(RaspberryPi::Backend::Base);

sub is_available{
	my $verbose = shift;
	eval{ require Device::BCM2835; };
	if ($@) {
		print "Unable to load module Device::BCM2835\n" . $@ if $verbose;
		return 0;
	}
	unless ($<) {
		print "Should be executed by superuser\n" if $verbose;
	}
	return 1;
}

sub init{
	my $self = shift;

	require Device::BCM2835;
	Device::BCM2835::init() || die "Could not init library";

	#Device::BCM2835::set_debug(1) if $debug_hardware;

	# hardware pins that can be used for reading/writing
	$self->{Pins} = {
		12 => &Device::BCM2835::RPI_GPIO_P1_12,
		16 => &Device::BCM2835::RPI_GPIO_P1_16,
		18 => &Device::BCM2835::RPI_GPIO_P1_18,
		19 => &Device::BCM2835::RPI_GPIO_P1_19,
		21 => &Device::BCM2835::RPI_GPIO_P1_21,
		22 => &Device::BCM2835::RPI_GPIO_P1_22,
		23 => &Device::BCM2835::RPI_GPIO_P1_23,
		24 => &Device::BCM2835::RPI_GPIO_P1_24,
		26 => &Device::BCM2835::RPI_GPIO_P1_26,
	};
	# set all controls as outputs
	foreach my $pin (keys %{$self->{Pins}}){
		Device::BCM2835::gpio_fsel($self->{Pins}->{$pin}, &Device::BCM2835::BCM2835_GPIO_FSEL_OUTP);
	}
	# set all outputs as 0
	$self->set_output();
}

sub set_output{
	my $self = shift;

	my %values = map {$_ => 0} keys %{$self->{Pins}};
	map {$values{$_} = 1 if exists $values{$_}} @_;
	foreach (@_) {
		# set controls pins grabbed from input to high state, binary format
		if (exists $values{$_}) {
			$values{$_} = 1;
		}
	}

	foreach my $pin (sort keys %values) {
		#debug("Set output pin $pin with value $values{$pin}");
		Device::BCM2835::gpio_write($self->{Pins}->{$pin}, $values{$pin} ? 1 : 0);
	}
}

1;

{'fraction_non_alphanumeric': 0.1751684311838306, 'fraction_numerical': 0.07218479307025986, 'mean_word_length': 4.839887640449438, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 21, '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': '1439214', 'n_tokens_mistral': 956, 'n_tokens_neox': 847, 'n_words': 189}