<commit_before>"""Hardware abstraction for ADS7830 ADC"""

import time
import smbus as bus

from i2c_device.i2c_device import I2CDevice

import bbb.pwm as pwm_mod
import bot.lib.lib as lib



class ADC(object):
    def __init__(self):
            """Initialized I2C device"""
            self.logger = lib.get_logger()
            self.bot_config = lib.get_config()
            
            # Default value of command byte. 
            # Refer to ADS_7830 for more information
            
            # Handle off-bone runs
            if self.bot_config["test_mode"]["ADC"]:
                self.logger.debug("Running in test mode")
            else:
                self.logger.debug("Running in non-test mode")

                # Setup I2C
                addr = self.bot_config
                I2CDevice.__init__(self, 1, 0x48,
                                config='adc_ads7830_i2c.yaml')

    @lib.api_call
    def read_channel(self, channel_num, SD=0b0,
                    internal_ref=0b0, AD_converter=0b0):
        # Append bits to form command byte.
        command_byte = (SD << 7) | (channel_num << 4) \
                       (internal_ref << 3) | (AD_converter << 2) \
                       | (0b00)
        bus.write_byte(self.addr, command_byte)
        return bus.read_byte(self.addr)
        
    @lib.api_call
    def read_all(self)
        return read_channel(0), read_channel(1), read_channel(2), \
               read_channel(3), read_channel(4), read_channel(5), \
               read_channel(6), read_channel(7)
    

        

        

if __name__ == "__main__":
    read_loop()<commit_msg>added read_all, print_all, and read_loop debugging functions<commit_after>"""Hardware abstraction for ADS7830 ADC"""

import time
import smbus as bus

from i2c_device.i2c_device import I2CDevice

import bbb.pwm as pwm_mod
import bot.lib.lib as lib



class ADC(object):
    def __init__(self):
            """Initialized I2C device"""
            self.logger = lib.get_logger()
            self.bot_config = lib.get_config()
            
            # Default value of command byte. 
            # Refer to ADS_7830 for more information
            
            # Handle off-bone runs
            if self.bot_config["test_mode"]["ADC"]:
                self.logger.debug("Running in test mode")
            else:
                self.logger.debug("Running in non-test mode")

                # Setup I2C
                addr = self.bot_config
                I2CDevice.__init__(self, 1, 0x48,
                                config='adc_ads7830_i2c.yaml')

    @lib.api_call
    def read_channel(self, channel_num, SD=0b0,
                    internal_ref=0b0, AD_converter=0b0):
        # Append bits to form command byte.
        command_byte = (SD << 7) | (channel_num << 4) \
                       (internal_ref << 3) | (AD_converter << 2) \
                       | (0b00)
        bus.write_byte(self.addr, command_byte)
        return bus.read_byte(self.addr)

    @lib.api_call
    def read_all(self)
        return read_channel(0), read_channel(1), read_channel(2), \
               read_channel(3), read_channel(4), read_channel(5), \
               read_channel(6), read_channel(7)

    @lib.api_call
    def print_all(self)
        print "0:{} 1:{} 2:{} 3:{} 4:{} 5:{} 6:{} 7:{}".format(
                                            self.read_all)
                                            
    @lib.api_call
    def read_loop(self)
        t0 = time.time()
        while True:
            try:
                print "[{:8.3f}] ".format(time.time()-t0),
                self.print_all()
            except KeyboardInterrupt:
                break
        print "Done."
{'fraction_non_alphanumeric': 0.10315960032406157, 'fraction_numerical': 0.027005130974885227, 'mean_word_length': 1.6232294617563738, 'pattern_counts': {'":': 1, '<': 19, '<?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': 3, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2314033', 'n_tokens_mistral': 1176, 'n_tokens_neox': 1109, 'n_words': 251}