<commit_before>#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Radiation Watch Pocket Geiger Type 5 library for Raspberry Pi.

Documentation and usage at: https://github.com/MonsieurV/PiPocketGeiger

Released under MIT License. See LICENSE file.

Contributed by:
- Radiation-watch.org <http://www.radiation-watch.org/>
- <NAME> <<EMAIL>>
"""
import RPi.GPIO as GPIO

class RadiationWatch:
    def __init__(self, radiationPin, noisePin, numbering=GPIO.BCM):
        """Initialize the Radiation Watch library, specifying the pin numbers
        for the radiation and noise pin.
        You can also specify the pin numbering mode (BCM numbering by default)."""
        GPIO.setmode(numbering)
        self.radiationPin = radiationPin
        self.noisePin = noisePin

    def __enter__(self):
        # Init the GPIO context.
        GPIO.setup(self.radiationPin, GPIO.IN, pull_up_down=GPIO.PUD_UP)
        GPIO.setup(self.noisePin, GPIO.IN, pull_up_down=GPIO.PUD_UP)
        # Register local callbacks.
        GPIO.add_event_detect(self.radiationPin, GPIO.FALLING,
            callback=self._onRadiation)
        GPIO.add_event_detect(self.noisePin, GPIO.FALLING,
            callback=self._onNoise)
        return self

    def __exit__(self, exc_type, exc_value, traceback):
        GPIO.cleanup()

    def _onRadiation(self, channel):
        print("Ray appeared!")

    def _onNoise(self, channel):
        print("Vibration! Stop moving!")

if __name__ == "__main__":
    with RadiationWatch(24, 23) as radiationWatch:
        while 1:
            pass<commit_msg>Allow to use the class with a setup()-close() model in addition to the with clause (which is the recommended usage)<commit_after>#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Radiation Watch Pocket Geiger Type 5 library for Raspberry Pi.

Documentation and usage at: https://github.com/MonsieurV/PiPocketGeiger

Released under MIT License. See LICENSE file.

Contributed by:
- Radiation-watch.org <http://www.radiation-watch.org/>
- <NAME> <<EMAIL>>
"""
import RPi.GPIO as GPIO

class RadiationWatch:
    def __init__(self, radiationPin, noisePin, numbering=GPIO.BCM):
        """Initialize the Radiation Watch library, specifying the pin numbers
        for the radiation and noise pin.
        You can also specify the pin numbering mode (BCM numbering by default)."""
        GPIO.setmode(numbering)
        self.radiationPin = radiationPin
        self.noisePin = noisePin

    def __enter__(self):
        return self.setup()

    def __exit__(self, exc_type, exc_value, traceback):
        self.close()

    def setup(self):
        # Init the GPIO context.
        GPIO.setup(self.radiationPin, GPIO.IN, pull_up_down=GPIO.PUD_UP)
        GPIO.setup(self.noisePin, GPIO.IN, pull_up_down=GPIO.PUD_UP)
        # Register local callbacks.
        GPIO.add_event_detect(self.radiationPin, GPIO.FALLING,
            callback=self._onRadiation)
        GPIO.add_event_detect(self.noisePin, GPIO.FALLING,
            callback=self._onNoise)
        return self

    def close(self):
        GPIO.cleanup()

    def _onRadiation(self, channel):
        print("Ray appeared!")

    def _onNoise(self, channel):
        print("Vibration! Stop moving!")

if __name__ == "__main__":
    with RadiationWatch(24, 23) as radiationWatch:
        while 1:
            pass
{'fraction_non_alphanumeric': 0.10284857571214392, 'fraction_numerical': 0.004197901049475262, 'mean_word_length': 2.9526066350710902, 'pattern_counts': {'":': 2, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, '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': '2803537', 'n_tokens_mistral': 1037, 'n_tokens_neox': 1003, 'n_words': 277}