示例#1
0
def test_request_iop_conflict():
    """Test for the _IOP class and the method request_iop().
    
    Creates multiple IOP instances on the same fixed ID. Tests whether 
    request_iop() correctly raises a LookupError exception.
    This is a test for case 2 (for more information, please see request_iop).
    
    """
    fixed_id = 1
    request_iop(fixed_id,'pmod_adc.bin')
    pytest.raises(LookupError, request_iop, fixed_id, 'pmod_dac.bin')
    
    ol.reset()
示例#2
0
文件: pmod_pwm.py 项目: hexanoid/PYNQ
 def __init__(self, if_id, index): 
     """Return a new instance of an GROVE_PWM object. 
     
     Parameters
     ----------
     if_id : int
         The interface ID (1, 2) corresponding to (PMODA, PMODB).
     index : int
         The specific pin that runs PWM.
         
     """
     if not if_id in [PMODA, PMODB]:
         raise ValueError("No such IOP for Pmod device.")
     if not index in range(8):
         raise ValueError("Valid pin indexes are 0 - 7.")
         
     self.iop = request_iop(if_id, PMOD_PWM_PROGRAM)
     self.mmio = self.iop.mmio
     self.iop.start()
     
     # Write PWM pin config
     self.mmio.write(iop_const.MAILBOX_OFFSET, index)
     
     # Write configuration and wait for ACK
     self.mmio.write(iop_const.MAILBOX_OFFSET + \
                     iop_const.MAILBOX_PY2IOP_CMD_OFFSET, 0x1)
     while not (self.mmio.read(iop_const.MAILBOX_OFFSET + \
                               iop_const.MAILBOX_PY2IOP_CMD_OFFSET) == 0):
         pass
示例#3
0
 def __init__(self, if_id, index): 
     """Return a new instance of an GROVE_PWM object. 
     
     Parameters
     ----------
     if_id : int
         The interface ID (1, 2) corresponding to (PMODA, PMODB).
     index : int
         The specific pin that runs PWM.
         
     """
     if not if_id in [PMODA, PMODB]:
         raise ValueError("No such IOP for Pmod device.")
     if not index in range(8):
         raise ValueError("Valid pin indexes are 0 - 7.")
         
     self.iop = request_iop(if_id, PMOD_PWM_PROGRAM)
     self.mmio = self.iop.mmio
     self.iop.start()
     
     # Write PWM pin config
     self.mmio.write(iop_const.MAILBOX_OFFSET, index)
     
     # Write configuration and wait for ACK
     self.mmio.write(iop_const.MAILBOX_OFFSET +
                     iop_const.MAILBOX_PY2IOP_CMD_OFFSET, 0x1)
     while not (self.mmio.read(iop_const.MAILBOX_OFFSET +
                               iop_const.MAILBOX_PY2IOP_CMD_OFFSET) == 0):
         pass
示例#4
0
def test_request_iop():
    """Test for the _IOP class and the method request_iop().
    
    Test whether the request_iop() can return an object without errors. 
    This is a test for case 1 (for more information, please see request_iop).
    
    """
    fixed_id = 1
    exception_raised = False
    try:
        request_iop(fixed_id,'mailbox.bin')
    except LookupError:
        exception_raised = True
    assert not exception_raised, 'request_iop() should not raise exception.'
    
    ol.reset()
示例#5
0
 def __init__(self, if_id, index): 
     """Return a new instance of an Pmod_Timer object. 
     
     Parameters
     ----------
     if_id : int
         The interface ID (1, 2) corresponding to (PMODA, PMODB).
     index : int
         The specific pin that runs timer.
         
     """
     if not if_id in [PMODA, PMODB]:
         raise ValueError("No such IOP for Pmod device.")
         
     self.iop = request_iop(if_id, PMOD_TIMER_PROGRAM)
     self.mmio = self.iop.mmio
     self.clk = int(pow(10,9)/iop_const.IOP_FREQUENCY)
     self.iop.start()
     
     # Write PWM pin config
     self.mmio.write(iop_const.MAILBOX_OFFSET, index)
     
     # Write configuration and wait for ACK
     self.mmio.write(iop_const.MAILBOX_OFFSET + \
                     iop_const.MAILBOX_PY2IOP_CMD_OFFSET, 0x1)
     while not (self.mmio.read(iop_const.MAILBOX_OFFSET + \
                               iop_const.MAILBOX_PY2IOP_CMD_OFFSET) == 0):
         pass
示例#6
0
    def __init__(self, if_id, value=None):
        """Return a new instance of a DAC object.
    
        Note
        ----
        The floating point number to be written should be in the range 
        of [0.00, 2.00]. 
        
        Parameters
        ----------
        if_id : int
            The interface ID (1, 2) corresponding to (PMODA, PMODB).
        value: float
            The value to be written to the DAC Pmod.
            
        """
        if not if_id in [PMODA, PMODB]:
            raise ValueError("No such IOP for Pmod device.")

        self.iop = request_iop(if_id, PMOD_DAC_PROGRAM)
        self.mmio = self.iop.mmio

        self.iop.start()

        if value:
            self.write(value)
示例#7
0
文件: pmod_timer.py 项目: fejat/SPARK
    def __init__(self, if_id, index):
        """Return a new instance of an Pmod_Timer object. 
        
        Parameters
        ----------
        if_id : int
            The interface ID (1, 2) corresponding to (PMODA, PMODB).
        index : int
            The specific pin that runs timer.
            
        """
        if not if_id in [PMODA, PMODB]:
            raise ValueError("No such IOP for Pmod device.")

        self.iop = request_iop(if_id, PMOD_TIMER_PROGRAM)
        self.mmio = self.iop.mmio
        self.clk = int(pow(10, 9) / iop_const.IOP_FREQUENCY)
        self.iop.start()

        # Write PWM pin config
        self.mmio.write(iop_const.MAILBOX_OFFSET, index)

        # Write configuration and wait for ACK
        self.mmio.write(
            iop_const.MAILBOX_OFFSET + iop_const.MAILBOX_PY2IOP_CMD_OFFSET,
            0x1)
        while not (self.mmio.read(iop_const.MAILBOX_OFFSET +
                                  iop_const.MAILBOX_PY2IOP_CMD_OFFSET) == 0):
            pass
示例#8
0
    def __init__(self, if_id):
        if not if_id in [ARDUINO]:
            raise ValueError("No such IOP for Arduino device.")

        self.iop = request_iop(if_id, ARDUINO_IKS01A1_PROGRAM)
        self.mmio = self.iop.mmio
        self.log_interval_ms = 1000
        self.iop.start()
    def __init__(self, if_id):
        if not if_id in [PMODA, PMODB]:
            raise ValueError("No such IOP for Pmod device.")

        self.iop = request_iop(if_id, PMOD_ACL_PROGRAM)
        self.mmio = self.iop.mmio
        self.log_interval_ms = 1000
        self.iop.start()
示例#10
0
def test_request_iop_same():
    """Test for the _IOP class and the method request_iop().
    
    The request_iop() should not raise any exception since the previous IOP 
    runs the same program.
    This is a test for case 1 (for more information, please see request_iop).
    
    """
    fixed_id = 1
    exception_raised = False
    request_iop(fixed_id,'mailbox.bin')
    try:
        request_iop(fixed_id,'mailbox.bin')
    except LookupError:
        exception_raised = True
    assert not exception_raised, 'request_iop() should not raise exception.'
    
    ol.reset()
示例#11
0
    def __init__(self, if_id, gr_pin):
        """Return a new instance of an Grove LEDbar object. 
        
        Note
        ----
        Valid StickIt group ID is currently only 1.
        
        Parameters
        ----------
        if_id : int
            IOP ID (1, 2, 3) corresponding to (PMODA, PMODB, ARDUINO).
        gr_pin: list
            A group of pins on stickit connector or arduino shield.
            
        """
        if if_id in [PMODA, PMODB]:
            if not gr_pin in [PMOD_GROVE_G1, \
                              PMOD_GROVE_G2, \
                              PMOD_GROVE_G3, \
                              PMOD_GROVE_G4]:
                raise ValueError("LEDbar group number can only be G1 - G4.")
            GROVE_LEDBAR_PROGRAM = PMOD_GROVE_LEDBAR_PROGRAM
        elif if_id in [ARDUINO]:
            if not gr_pin in [ARDUINO_GROVE_G1, \
                              ARDUINO_GROVE_G2, \
                              ARDUINO_GROVE_G3, \
                              ARDUINO_GROVE_G4, \
                              ARDUINO_GROVE_G5, \
                              ARDUINO_GROVE_G6, \
                              ARDUINO_GROVE_G7]:
                raise ValueError("LEDbar group number can only be G1 - G7.")
            GROVE_LEDBAR_PROGRAM = ARDUINO_GROVE_LEDBAR_PROGRAM
        else:
            raise ValueError("No such IOP for grove device.")

        self.iop = request_iop(if_id, GROVE_LEDBAR_PROGRAM)
        self.mmio = self.iop.mmio
        self.iop.start()

        # Write GPIO pin config
        self.mmio.write(iop_const.MAILBOX_OFFSET, gr_pin[0])
        self.mmio.write(iop_const.MAILBOX_OFFSET + 4, gr_pin[1])

        # Write configuration and wait for ACK
        self.mmio.write(iop_const.MAILBOX_OFFSET + \
                        iop_const.MAILBOX_PY2IOP_CMD_OFFSET, 1)
        while not (self.mmio.read(iop_const.MAILBOX_OFFSET + \
                              iop_const.MAILBOX_PY2IOP_CMD_OFFSET) == 0):
            pass
示例#12
0
 def __init__(self, if_id, gr_pin): 
     """Return a new instance of an Grove LEDbar object. 
     
     Note
     ----
     Valid StickIt group ID is currently only 1.
     
     Parameters
     ----------
     if_id : int
         IOP ID (1, 2, 3) corresponding to (PMODA, PMODB, ARDUINO).
     gr_pin: list
         A group of pins on stickit connector or arduino shield.
         
     """
     if if_id in [PMODA, PMODB]:
         if not gr_pin in [PMOD_GROVE_G1, \
                           PMOD_GROVE_G2, \
                           PMOD_GROVE_G3, \
                           PMOD_GROVE_G4]:
             raise ValueError("LEDbar group number can only be G1 - G4.")
         GROVE_LEDBAR_PROGRAM = PMOD_GROVE_LEDBAR_PROGRAM
     elif if_id in [ARDUINO]:
         if not gr_pin in [ARDUINO_GROVE_G1, \
                           ARDUINO_GROVE_G2, \
                           ARDUINO_GROVE_G3, \
                           ARDUINO_GROVE_G4, \
                           ARDUINO_GROVE_G5, \
                           ARDUINO_GROVE_G6, \
                           ARDUINO_GROVE_G7]:
             raise ValueError("LEDbar group number can only be G1 - G7.")
         GROVE_LEDBAR_PROGRAM = ARDUINO_GROVE_LEDBAR_PROGRAM
     else:
         raise ValueError("No such IOP for grove device.")
         
     self.iop = request_iop(if_id, GROVE_LEDBAR_PROGRAM)
     self.mmio = self.iop.mmio
     self.iop.start()
     
     # Write GPIO pin config
     self.mmio.write(iop_const.MAILBOX_OFFSET, gr_pin[0])
     self.mmio.write(iop_const.MAILBOX_OFFSET+4, gr_pin[1])
         
     # Write configuration and wait for ACK
     self.mmio.write(iop_const.MAILBOX_OFFSET + \
                     iop_const.MAILBOX_PY2IOP_CMD_OFFSET, 1)
     while not (self.mmio.read(iop_const.MAILBOX_OFFSET + \
                           iop_const.MAILBOX_PY2IOP_CMD_OFFSET) == 0):
         pass
示例#13
0
文件: pmod_dpot.py 项目: fejat/SPARK
    def __init__(self, if_id):
        """Return a new instance of a DPOT object. 
        
        Parameters
        ----------
        if_id : int
            The interface ID (1, 2) corresponding to (PMODA, PMODB).
            
        """
        if not if_id in [PMODA, PMODB]:
            raise ValueError("No such IOP for Pmod device.")

        self.iop = request_iop(if_id, PMOD_DPOT_PROGRAM)
        self.mmio = self.iop.mmio

        self.iop.start()
示例#14
0
 def __init__(self, if_id):
     """Return a new instance of a DPOT object. 
     
     Parameters
     ----------
     if_id : int
         The interface ID (1, 2) corresponding to (PMODA, PMODB).
         
     """
     if not if_id in [PMODA, PMODB]:
         raise ValueError("No such IOP for Pmod device.")
         
     self.iop = request_iop(if_id, PMOD_DPOT_PROGRAM)
     self.mmio = self.iop.mmio
     
     self.iop.start()
示例#15
0
    def __init__(self, if_id):
        """Return a new instance of an Arduino_LCD18 object.
        
        Parameters
        ----------
        if_id : int
            The interface ID (3) corresponding to (ARDUINO).
            
        """
        if not if_id in [ARDUINO]:
            raise ValueError("No such IOP for Arduino LCD device.")

        self.iop = request_iop(if_id, ARDUINO_LCD18_PROGRAM)
        self.mmio = self.iop.mmio
        self.buf_manager = Xlnk()
        self.iop.start()
示例#16
0
    def __init__(self, if_id, gr_pin): 
        """Return a new instance of an Grove_EarHR object. 
                
        Parameters
        ----------
        if_id : int
            IOP ID (1, 2, 3) corresponding to (PMODA, PMODB, ARDUINO).
        gr_pin: list
            A group of pins on stickit connector or arduino shield.
            
        """
        if if_id in [PMODA, PMODB]:
            if not gr_pin in [PMOD_GROVE_G1, \
                              PMOD_GROVE_G2, \
                              PMOD_GROVE_G3, \
                              PMOD_GROVE_G4]:
                raise ValueError("EarHR group number can only be G1 - G4.")
            GROVE_EAR_HR_PROGRAM = PMOD_GROVE_EAR_HR_PROGRAM

        elif if_id in [ARDUINO]:
            if not gr_pin in [ARDUINO_GROVE_G1, \
                              ARDUINO_GROVE_G2, \
                              ARDUINO_GROVE_G3, \
                              ARDUINO_GROVE_G4, \
                              ARDUINO_GROVE_G5, \
                              ARDUINO_GROVE_G6, \
                              ARDUINO_GROVE_G7]:
                raise ValueError("EarHR group number can only be G1 - G7.")
            GROVE_EAR_HR_PROGRAM = ARDUINO_GROVE_EAR_HR_PROGRAM

        else:
            raise ValueError("No such IOP for grove device.")

        self.iop = request_iop(if_id, GROVE_EAR_HR_PROGRAM)
        self.mmio = self.iop.mmio
        self.iop.start()
        
        #: Write signal pinconfig
        signal_pin = gr_pin[0]
        self.mmio.write(iop_const.MAILBOX_OFFSET, signal_pin)
        
        #: Write configuration and wait for ACK
        self.mmio.write(iop_const.MAILBOX_OFFSET+\
                        iop_const.MAILBOX_PY2IOP_CMD_OFFSET, 1)
        while (self.mmio.read(iop_const.MAILBOX_OFFSET+\
                              iop_const.MAILBOX_PY2IOP_CMD_OFFSET) == 1):
            pass
示例#17
0
 def __init__(self, if_id, gr_pin): 
     """Return a new instance of an Grove OLED object. 
     
     Note
     ----
     The parameter `gr_pin` is a list organized as [scl_pin, sda_pin].
     
     Parameters
     ----------
     if_id : int
         IOP ID (1, 2, 3) corresponding to (PMODA, PMODB, ARDUINO).
     gr_pin: list
         A group of pins on stickit connector or arduino shield.
         
     """
     if if_id in [PMODA, PMODB]:
         if not gr_pin in [PMOD_GROVE_G3, \
                           PMOD_GROVE_G4]:
             raise ValueError("OLED group number can only be G3 - G4.")
         GROVE_OLED_PROGRAM = PMOD_GROVE_OLED_PROGRAM
     elif if_id in [ARDUINO]:
         if not gr_pin in [ARDUINO_GROVE_I2C]:
             raise ValueError("OLED group number can only be I2C.")
         GROVE_OLED_PROGRAM = ARDUINO_GROVE_OLED_PROGRAM
     else:
         raise ValueError("No such IOP for grove device.")
         
     self.iop = request_iop(if_id, GROVE_OLED_PROGRAM)
     self.mmio = self.iop.mmio
     self.iop.start()
     
     if if_id in [PMODA, PMODB]:
         # Write SCL and SDA pin config
         self.mmio.write(iop_const.MAILBOX_OFFSET, gr_pin[0])
         self.mmio.write(iop_const.MAILBOX_OFFSET+4, gr_pin[1])
     
         # Write configuration and wait for ACK
         self.mmio.write(iop_const.MAILBOX_OFFSET + \
                         iop_const.MAILBOX_PY2IOP_CMD_OFFSET, 1)
         while (self.mmio.read(iop_const.MAILBOX_OFFSET + \
                               iop_const.MAILBOX_PY2IOP_CMD_OFFSET) == 1):
             pass
         
     # Use the default of horizontal mode
     self.set_horizontal_mode()
     self.clear()
示例#18
0
    def __init__(self, if_id, gr_pin):
        """Return a new instance of an Arduino_Analog object. 
        
        Note
        ----
        The parameter `gr_pin` is a list of analog pins enabled.
        
        Parameters
        ----------
        if_id : int
            The interface ID (3) corresponding to (ARDUINO).
        gr_pin: list
            A group of pins for arduino analog pins.
            
        """
        if if_id in [ARDUINO]:
            for pin in gr_pin:
                if not pin in range(6):
                    raise ValueError("Analog pin number can only be 0 - 5.")
        else:
            raise ValueError("No such IOP for analog device.")

        self.iop = request_iop(if_id, ARDUINO_ANALOG_PROGRAM)
        self.mmio = self.iop.mmio
        self.log_interval_ms = 1000
        self.log_running = 0
        self.gr_pin = gr_pin
        self.num_channels = len(gr_pin)
        self.iop.start()

        # Enable all the analog pins
        self.mmio.write(iop_const.MAILBOX_OFFSET, 0)
        self.mmio.write(iop_const.MAILBOX_OFFSET + 0x04, 0)
        self.mmio.write(iop_const.MAILBOX_OFFSET + 0x08, 0)
        self.mmio.write(iop_const.MAILBOX_OFFSET + 0x0C, 0)
        self.mmio.write(iop_const.MAILBOX_OFFSET + 0x10, 0)
        self.mmio.write(iop_const.MAILBOX_OFFSET + 0x14, 0)

        # Write configuration and wait for ACK
        self.mmio.write(
            iop_const.MAILBOX_OFFSET + iop_const.MAILBOX_PY2IOP_CMD_OFFSET,
            0x1)
        while (self.mmio.read(iop_const.MAILBOX_OFFSET +
                              iop_const.MAILBOX_PY2IOP_CMD_OFFSET) == 0x1):
            pass
示例#19
0
 def __init__(self, if_id, gr_pin): 
     """Return a new instance of an Arduino_Analog object. 
     
     Note
     ----
     The parameter `gr_pin` is a list of analog pins enabled.
     
     Parameters
     ----------
     if_id : int
         The interface ID (3) corresponding to (ARDUINO).
     gr_pin: list
         A group of pins for arduino analog pins.
         
     """
     if if_id in [ARDUINO]:
         for pin in gr_pin:
             if not pin in range(6):
                 raise ValueError("Analog pin number can only be 0 - 5.")
     else:
         raise ValueError("No such IOP for analog device.")
         
     self.iop = request_iop(if_id, ARDUINO_ANALOG_PROGRAM)
     self.mmio = self.iop.mmio
     self.log_interval_ms = 1000
     self.log_running  = 0
     self.gr_pin = gr_pin
     self.num_channels = len(gr_pin)
     self.iop.start()
     
     # Enable all the analog pins
     self.mmio.write(iop_const.MAILBOX_OFFSET, 0)
     self.mmio.write(iop_const.MAILBOX_OFFSET+0x04, 0)
     self.mmio.write(iop_const.MAILBOX_OFFSET+0x08, 0)
     self.mmio.write(iop_const.MAILBOX_OFFSET+0x0C, 0)
     self.mmio.write(iop_const.MAILBOX_OFFSET+0x10, 0)
     self.mmio.write(iop_const.MAILBOX_OFFSET+0x14, 0)
     
     # Write configuration and wait for ACK
     self.mmio.write(iop_const.MAILBOX_OFFSET + \
                     iop_const.MAILBOX_PY2IOP_CMD_OFFSET, 0x1)
     while (self.mmio.read(iop_const.MAILBOX_OFFSET + \
                           iop_const.MAILBOX_PY2IOP_CMD_OFFSET) == 0x1):
         pass
示例#20
0
 def __init__(self, if_id, switch_config):
     """Return a new instance of a DevMode object.
     
     Parameters
     ----------
     if_id : int
         The interface ID (1,2,3) corresponding to (PMODA,PMODB,ARDUINO).
     switch_config : list
         IO Processor switch configuration (8 or 19 integers).
         
     """
     if not if_id in [PMODA, PMODB, ARDUINO]:
         raise ValueError("No such IOP for DevMode.")
         
     self.if_id = if_id
     self.iop = request_iop(if_id, iop_const.MAILBOX_PROGRAM)
     self.iop_switch_config = list(switch_config)
     self.mmio = MMIO(self.iop.mmio.base_addr + iop_const.MAILBOX_OFFSET, \
                      iop_const.MAILBOX_SIZE)
示例#21
0
    def __init__(self, pmod_id, gr_id): 
        """Return a new instance of an Grove_FingerHR object. 
        
        Parameters
        ----------
        if_id : int
            IOP ID (1, 2, 3) corresponding to (PMODA, PMODB, ARDUINO).
        gr_pin: list
            A group of pins on stickit connector or arduino shield.
            
        """
        if if_id in [PMODA, PMODB]:
            if not gr_pin in [PMOD_GROVE_G3, \
                              PMOD_GROVE_G4]:
                raise ValueError("FingerHR group number can only be G3 - G4.")
            GROVE_FINGER_HR_PROGRAM = PMOD_GROVE_FINGER_HR_PROGRAM

        elif if_id in [ARDUINO]:
            if not gr_pin in [ARDUINO_GROVE_I2C]:
                raise ValueError("FingerHR group number can only be I2C.")
            GROVE_EAR_HR_PROGRAM = ARDUINO_GROVE_EAR_HR_PROGRAM

        else:
            raise ValueError("No such IOP for grove device.")

        self.iop = request_iop(if_id, GROVE_FINGER_HR_PROGRAM)
        self.mmio = self.iop.mmio
        self.log_interval_ms = 1000
        self.log_running  = 0
        self.iop.start()

        if if_id in [PMODA, PMODB]:
            #: Write SCL and SDA Pin Config
            self.mmio.write(iop_const.MAILBOX_OFFSET, gr_pin[0])
            self.mmio.write(iop_const.MAILBOX_OFFSET+4, gr_pin[1])
            
        # Write configuration and wait for ACK
        self.mmio.write(iop_const.MAILBOX_OFFSET + \
                        iop_const.MAILBOX_PY2IOP_CMD_OFFSET, 1)
        while (self.mmio.read(iop_const.MAILBOX_OFFSET + \
                              iop_const.MAILBOX_PY2IOP_CMD_OFFSET) == 1):
            pass  
示例#22
0
    def __init__(self, if_id, gr_pin): 
        """Return a new instance of an Grove_Color object.  
        
        Parameters
        ----------
        if_id : int
            IOP ID (1, 2, 3) corresponding to (PMODA, PMODB, ARDUINO).
        gr_pin: list
            A group of pins on stickit connector or arduino shield.
            
        """
        if if_id in [PMODA, PMODB]:
            if not gr_pin in [PMOD_GROVE_G3, \
                              PMOD_GROVE_G4]:
                raise ValueError("Color group number can only be G3 - G4.")
            GROVE_COLOR_PROGRAM = PMOD_GROVE_COLOR_PROGRAM

        elif if_id in [ARDUINO]:
            if not gr_pin in [ARDUINO_GROVE_I2C]:
                raise ValueError("Color group number can only be I2C.")
            GROVE_COLOR_PROGRAM = ARDUINO_GROVE_COLOR_PROGRAM

        else:
            raise ValueError("No such IOP for grove device.")

        self.iop = request_iop(if_id, GROVE_COLOR_PROGRAM)
        self.mmio = self.iop.mmio
        self.log_interval_ms = 1000
        self.log_running  = 0
        self.iop.start()
        
        if if_id in [PMODA, PMODB]:        
            #: Write SCL and SDA Pin Config
            self.mmio.write(iop_const.MAILBOX_OFFSET, gr_pin[0])
            self.mmio.write(iop_const.MAILBOX_OFFSET+4, gr_pin[1])
            
        # Write configuration and wait for ACK
        self.mmio.write(iop_const.MAILBOX_OFFSET + \
                        iop_const.MAILBOX_PY2IOP_CMD_OFFSET, 1)
        while (self.mmio.read(iop_const.MAILBOX_OFFSET + \
                              iop_const.MAILBOX_PY2IOP_CMD_OFFSET) == 1):
            pass
示例#23
0
    def __init__(self, if_id, gr_pin):
        """Return a new instance of an GROVE_Buzzer object. 
        
        Parameters
        ----------
        if_id : int
            IOP ID (1, 2, 3) corresponding to (PMODA, PMODB, arduino).
        gr_pin: list
            A group of pins on stickit connector or arduino shield.
            
        """
        if if_id in [PMODA, PMODB]:
            if not gr_pin in [
                    PMOD_GROVE_G1, PMOD_GROVE_G2, PMOD_GROVE_G3, PMOD_GROVE_G4
            ]:
                raise ValueError("Buzzer group number can only be G1 - G4.")
            GROVE_BUZZER_PROGRAM = PMOD_GROVE_BUZZER_PROGRAM
        elif if_id in [ARDUINO]:
            if not gr_pin in [
                    ARDUINO_GROVE_G1, ARDUINO_GROVE_G2, ARDUINO_GROVE_G3,
                    ARDUINO_GROVE_G4, ARDUINO_GROVE_G5, ARDUINO_GROVE_G6,
                    ARDUINO_GROVE_G7
            ]:
                raise ValueError("Buzzer group number can only be G1 - G7.")
            GROVE_BUZZER_PROGRAM = ARDUINO_GROVE_BUZZER_PROGRAM
        else:
            raise ValueError("No such IOP for grove device.")

        self.iop = request_iop(if_id, GROVE_BUZZER_PROGRAM)
        self.mmio = self.iop.mmio
        self.iop.start()

        # Write SCL and SDA pin config
        self.mmio.write(iop_const.MAILBOX_OFFSET, gr_pin[0])
        self.mmio.write(iop_const.MAILBOX_OFFSET + 4, gr_pin[1])

        # Write configuration and wait for ACK
        self.mmio.write(
            iop_const.MAILBOX_OFFSET + iop_const.MAILBOX_PY2IOP_CMD_OFFSET, 1)
        while (self.mmio.read(iop_const.MAILBOX_OFFSET +
                              iop_const.MAILBOX_PY2IOP_CMD_OFFSET) == 1):
            pass
示例#24
0
 def __init__(self, if_id, text=None):
     """Return a new instance of an OLED object. 
     
     Parameters
     ----------
     if_id : int
         The interface ID (1, 2) corresponding to (PMODA, PMODB).
     text: str
         The text to be displayed after initialization.
         
     """
     if not if_id in [PMODA, PMODB]:
         raise ValueError("No such IOP for Pmod device.")
         
     self.iop = request_iop(if_id, PMOD_OLED_PROGRAM)
     self.mmio = self.iop.mmio
     
     self.iop.start()
     self.clear()
     
     if text:
         self.write(text)
示例#25
0
 def __init__(self):
     self.iop = request_iop(1, MATH_IP_PROGRAM)
     self.mmio = self.iop.mmio
     self.iop.start()
示例#26
0
 def __init__(self):
     self.iop = request_iop(ARDUINO_IF_ID, CAN_BUS_BIN)
     self.mmio = self.iop.mmio
     self.mmio.debug = False
     self.iop.start()