_id
stringlengths
2
7
title
stringlengths
1
88
partition
stringclasses
3 values
text
stringlengths
75
19.8k
language
stringclasses
1 value
meta_information
dict
q18800
PyMata3.i2c_config
train
def i2c_config(self, read_delay_time=0): """ This method configures Arduino i2c with an optional read delay time. :param read_delay_time: firmata i2c delay time :returns: No return value """ task = asyncio.ensure_future(self.core.i2c_config(read_delay_time)) self.loop.run_until_complete(task)
python
{ "resource": "" }
q18801
PyMata3.i2c_read_data
train
def i2c_read_data(self, address): """ Retrieve result of last data read from i2c device. i2c_read_request should be called before trying to retrieve data. It is intended for use by a polling application. :param address: i2c :returns: last data read or None if no data is present. """ task = asyncio.ensure_future(self.core.i2c_read_data(address)) value = self.loop.run_until_complete(task) return value
python
{ "resource": "" }
q18802
PyMata3.send_reset
train
def send_reset(self): """ Send a Firmata reset command :returns: No return value """ task = asyncio.ensure_future(self.core.send_reset()) self.loop.run_until_complete(task)
python
{ "resource": "" }
q18803
PyMata3.servo_config
train
def servo_config(self, pin, min_pulse=544, max_pulse=2400): """ This method configures the Arduino for servo operation. :param pin: Servo control pin :param min_pulse: Minimum pulse width :param max_pulse: Maximum pulse width :returns: No return value """ task = asyncio.ensure_future(self.core.servo_config(pin, min_pulse, max_pulse)) self.loop.run_until_complete(task)
python
{ "resource": "" }
q18804
PyMata3.set_analog_latch
train
def set_analog_latch(self, pin, threshold_type, threshold_value, cb=None, cb_type=None): """ This method "arms" an analog pin for its data to be latched and saved in the latching table. If a callback method is provided, when latching criteria is achieved, the callback function is called with latching data notification. :param pin: Analog pin number (value following an 'A' designator, i.e. A5 = 5 :param threshold_type: Constants.LATCH_GT | Constants.LATCH_LT | Constants.LATCH_GTE | Constants.LATCH_LTE :param threshold_value: numerical value - between 0 and 1023 :param cb: callback method :param cb_type: Constants.CB_TYPE_DIRECT = direct call or Constants.CB_TYPE_ASYNCIO = asyncio coroutine :returns: True if successful, False if parameter data is invalid """ task = asyncio.ensure_future(self.core.set_analog_latch(pin, threshold_type, threshold_value, cb, cb_type)) result = self.loop.run_until_complete(task) return result
python
{ "resource": "" }
q18805
PyMata3.set_pin_mode
train
def set_pin_mode(self, pin_number, pin_state, callback=None, cb_type=None): """ This method sets the pin mode for the specified pin. :param pin_number: Arduino Pin Number :param pin_state: INPUT/OUTPUT/ANALOG/PWM/PULLUP - for SERVO use servo_config() :param callback: Optional: A reference to a call back function to be called when pin data value changes :param cb_type: Constants.CB_TYPE_DIRECT = direct call or Constants.CB_TYPE_ASYNCIO = asyncio coroutine :returns: No return value """ task = asyncio.ensure_future(self.core.set_pin_mode(pin_number, pin_state, callback, cb_type)) self.loop.run_until_complete(task)
python
{ "resource": "" }
q18806
PyMata3.set_sampling_interval
train
def set_sampling_interval(self, interval): """ This method sets the sampling interval for the Firmata loop method :param interval: time in milliseconds :returns: No return value """ task = asyncio.ensure_future(self.core.set_sampling_interval(interval)) self.loop.run_until_complete(task)
python
{ "resource": "" }
q18807
PyMata3.shutdown
train
def shutdown(self): """ Shutdown the application and exit :returns: No return value """ task = asyncio.ensure_future(self.core.shutdown()) self.loop.run_until_complete(task)
python
{ "resource": "" }
q18808
PyMata3.pixy_init
train
def pixy_init(self, max_blocks=5, cb=None, cb_type=None): """ Initialize Pixy and will enable Pixy block reporting. This is a FirmataPlusRB feature. :param cb: callback function to report Pixy blocks :param cb_type: Constants.CB_TYPE_DIRECT = direct call or Constants.CB_TYPE_ASYNCIO = asyncio coroutine :param max_blocks: Maximum number of Pixy blocks to report when many signatures are found. :returns: No return value. """ task = asyncio.ensure_future(self.core.pixy_init(max_blocks, cb, cb_type)) self.loop.run_until_complete(task)
python
{ "resource": "" }
q18809
PymataSerial.write
train
async def write(self, data): """ This is an asyncio adapted version of pyserial write. It provides a non-blocking write and returns the number of bytes written upon completion :param data: Data to be written :return: Number of bytes written """ # the secret sauce - it is in your future future = asyncio.Future() result = None try: result = self.my_serial.write(bytes([ord(data)])) except serial.SerialException: # self.my_serial.close() # noinspection PyBroadException try: await self.close() future.cancel() if self.log_output: logging.exception('Write exception') else: print('Write exception') loop = asyncio.get_event_loop() for t in asyncio.Task.all_tasks(loop): t.cancel() loop.run_until_complete(asyncio.sleep(.1)) loop.stop() loop.close() self.my_serial.close() sys.exit(0) except: # swallow any additional exceptions during shutdown pass if result: future.set_result(result) while True: if not future.done(): # spin our asyncio wheels until future completes await asyncio.sleep(self.sleep_tune) else: return future.result()
python
{ "resource": "" }
q18810
PymataSerial.readline
train
async def readline(self): """ This is an asyncio adapted version of pyserial read. It provides a non-blocking read and returns a line of data read. :return: A line of data """ future = asyncio.Future() data_available = False while True: if not data_available: if not self.my_serial.inWaiting(): await asyncio.sleep(self.sleep_tune) else: data_available = True data = self.my_serial.readline() future.set_result(data) else: if not future.done(): await asyncio.sleep(self.sleep_tune) else: return future.result()
python
{ "resource": "" }
q18811
MMA8452Q3.check_who_am_i
train
def check_who_am_i(self): """ This method checks verifies the device ID. @return: True if valid, False if not """ register = self.MMA8452Q_Register['WHO_AM_I'] self.board.i2c_read_request(self.address, register, 1, Constants.I2C_READ | Constants.I2C_END_TX_MASK, self.data_val, Constants.CB_TYPE_DIRECT) reply = self.wait_for_read_result() if reply[self.data_start] == self.device_id: rval = True else: rval = False return rval
python
{ "resource": "" }
q18812
MMA8452Q3.standby
train
def standby(self): """ Put the device into standby mode so that the registers can be set. @return: No return value """ register = self.MMA8452Q_Register['CTRL_REG1'] self.board.i2c_read_request(self.address, register, 1, Constants.I2C_READ | Constants.I2C_END_TX_MASK, self.data_val, Constants.CB_TYPE_DIRECT) ctrl1 = self.wait_for_read_result() ctrl1 = (ctrl1[self.data_start]) & ~0x01 self.callback_data = [] self.board.i2c_write_request(self.address, [register, ctrl1])
python
{ "resource": "" }
q18813
MMA8452Q3.set_scale
train
def set_scale(self, scale): """ Set the device scale register. Device must be in standby before calling this function @param scale: scale factor @return: No return value """ register = self.MMA8452Q_Register['XYZ_DATA_CFG'] self.board.i2c_read_request(self.address, register, 1, Constants.I2C_READ | Constants.I2C_END_TX_MASK, self.data_val, Constants.CB_TYPE_DIRECT) config_reg = self.wait_for_read_result() config_reg = config_reg[self.data_start] config_reg &= 0xFC # Mask out scale bits config_reg |= (scale >> 2) self.board.i2c_write_request(self.address, [register, config_reg])
python
{ "resource": "" }
q18814
MMA8452Q3.set_output_data_rate
train
def set_output_data_rate(self, output_data_rate): """ Set the device output data rate. Device must be in standby before calling this function @param output_data_rate: Desired data rate @return: No return value. """ # self.standby() register = self.MMA8452Q_Register['CTRL_REG1'] self.board.i2c_read_request(self.address, register, 1, Constants.I2C_READ | Constants.I2C_END_TX_MASK, self.data_val, Constants.CB_TYPE_DIRECT) control_reg = self.wait_for_read_result() control_reg = control_reg[self.data_start] control_reg &= 0xC7 # Mask out data rate bits control_reg |= (output_data_rate << 3) self.board.i2c_write_request(self.address, [register, control_reg])
python
{ "resource": "" }
q18815
MMA8452Q3.available
train
def available(self): """ This method checks to see if new xyz data is available @return: Returns 0 if not available. 1 if it is available """ register = self.MMA8452Q_Register['STATUS'] self.board.i2c_read_request(self.address, register, 1, Constants.I2C_READ | Constants.I2C_END_TX_MASK, self.data_val, Constants.CB_TYPE_DIRECT) avail = self.wait_for_read_result() avail = (avail[self.data_start] & 0x08) >> 3 return avail
python
{ "resource": "" }
q18816
blink
train
async def blink(my_board): """ Blink LED 13 @return: No Return Value """ # set the pin mode await my_board.set_pin_mode(13, Constants.OUTPUT) for i in range(0, 5): await my_board.digital_write(13, 1) await asyncio.sleep(1) await my_board.digital_write(13, 0) await asyncio.sleep(1)
python
{ "resource": "" }
q18817
turn_right
train
def turn_right(): """turns RedBot to the Right""" motors.left_motor(-150) # spin CCW motors.right_motor(-150) # spin CCW board.sleep(0.5) motors.brake(); board.sleep(0.1)
python
{ "resource": "" }
q18818
turn_left
train
def turn_left(): """turns RedBot to the Left""" motors.left_motor(150) # spin CCW motors.right_motor(150) # spin CCW board.sleep(0.5) motors.brake(); board.sleep(0.1)
python
{ "resource": "" }
q18819
PymataCore.analog_write
train
async def analog_write(self, pin, value): """ Set the selected pin to the specified value. :param pin: PWM pin number :param value: Pin value (0 - 0x4000) :returns: No return value """ if PrivateConstants.ANALOG_MESSAGE + pin < 0xf0: command = [PrivateConstants.ANALOG_MESSAGE + pin, value & 0x7f, (value >> 7) & 0x7f] await self._send_command(command) else: await self.extended_analog(pin, value)
python
{ "resource": "" }
q18820
PymataCore.digital_pin_write
train
async def digital_pin_write(self, pin, value): """ Set the specified pin to the specified value directly without port manipulation. :param pin: pin number :param value: pin value :returns: No return value """ command = (PrivateConstants.SET_DIGITAL_PIN_VALUE, pin, value) await self._send_command(command)
python
{ "resource": "" }
q18821
PymataCore.digital_write
train
async def digital_write(self, pin, value): """ Set the specified pin to the specified value. :param pin: pin number :param value: pin value :returns: No return value """ # The command value is not a fixed value, but needs to be calculated # using the pin's port number port = pin // 8 calculated_command = PrivateConstants.DIGITAL_MESSAGE + port mask = 1 << (pin % 8) # Calculate the value for the pin's position in the port mask if value == 1: PrivateConstants.DIGITAL_OUTPUT_PORT_PINS[port] |= mask else: PrivateConstants.DIGITAL_OUTPUT_PORT_PINS[port] &= ~mask # Assemble the command command = (calculated_command, PrivateConstants.DIGITAL_OUTPUT_PORT_PINS[port] & 0x7f, (PrivateConstants.DIGITAL_OUTPUT_PORT_PINS[port] >> 7) & 0x7f) await self._send_command(command)
python
{ "resource": "" }
q18822
PymataCore.disable_analog_reporting
train
async def disable_analog_reporting(self, pin): """ Disables analog reporting for a single analog pin. :param pin: Analog pin number. For example for A0, the number is 0. :returns: No return value """ command = [PrivateConstants.REPORT_ANALOG + pin, PrivateConstants.REPORTING_DISABLE] await self._send_command(command)
python
{ "resource": "" }
q18823
PymataCore.disable_digital_reporting
train
async def disable_digital_reporting(self, pin): """ Disables digital reporting. By turning reporting off for this pin, Reporting is disabled for all 8 bits in the "port" :param pin: Pin and all pins for this port :returns: No return value """ port = pin // 8 command = [PrivateConstants.REPORT_DIGITAL + port, PrivateConstants.REPORTING_DISABLE] await self._send_command(command)
python
{ "resource": "" }
q18824
PymataCore.encoder_config
train
async def encoder_config(self, pin_a, pin_b, cb=None, cb_type=None, hall_encoder=False): """ This command enables the rotary encoder support and will enable encoder reporting. This command is not part of StandardFirmata. For 2 pin + ground encoders, FirmataPlus is required to be used for 2 pin rotary encoder, and for hell effect wheel encoder support, FirmataPlusRB is required. Encoder data is retrieved by performing a digital_read from pin a (encoder pin_a). When using 2 hall effect sensors (e.g. 2 wheel robot) specify pin_a for 1st encoder and pin_b for 2nd encoder. :param pin_a: Encoder pin 1. :param pin_b: Encoder pin 2. :param cb: callback function to report encoder changes :param cb_type: Constants.CB_TYPE_DIRECT = direct call or Constants.CB_TYPE_ASYNCIO = asyncio coroutine :param hall_encoder: wheel hall_encoder - set to True to select hall encoder support support. :returns: No return value """ # checked when encoder data is returned self.hall_encoder = hall_encoder data = [pin_a, pin_b] if cb: self.digital_pins[pin_a].cb = cb if cb_type: self.digital_pins[pin_a].cb_type = cb_type await self._send_sysex(PrivateConstants.ENCODER_CONFIG, data)
python
{ "resource": "" }
q18825
PymataCore.enable_analog_reporting
train
async def enable_analog_reporting(self, pin): """ Enables analog reporting. By turning reporting on for a single pin, :param pin: Analog pin number. For example for A0, the number is 0. :returns: No return value """ command = [PrivateConstants.REPORT_ANALOG + pin, PrivateConstants.REPORTING_ENABLE] await self._send_command(command)
python
{ "resource": "" }
q18826
PymataCore.enable_digital_reporting
train
async def enable_digital_reporting(self, pin): """ Enables digital reporting. By turning reporting on for all 8 bits in the "port" - this is part of Firmata's protocol specification. :param pin: Pin and all pins for this port :returns: No return value """ port = pin // 8 command = [PrivateConstants.REPORT_DIGITAL + port, PrivateConstants.REPORTING_ENABLE] await self._send_command(command)
python
{ "resource": "" }
q18827
PymataCore.extended_analog
train
async def extended_analog(self, pin, data): """ This method will send an extended-data analog write command to the selected pin. :param pin: 0 - 127 :param data: 0 - 0xfffff :returns: No return value """ analog_data = [pin, data & 0x7f, (data >> 7) & 0x7f, (data >> 14) & 0x7f] await self._send_sysex(PrivateConstants.EXTENDED_ANALOG, analog_data)
python
{ "resource": "" }
q18828
PymataCore.get_analog_map
train
async def get_analog_map(self): """ This method requests a Firmata analog map query and returns the results. :returns: An analog map response or None if a timeout occurs """ # get the current time to make sure a report is retrieved current_time = time.time() # if we do not have existing report results, send a Firmata # message to request one if self.query_reply_data.get( PrivateConstants.ANALOG_MAPPING_RESPONSE) is None: await self._send_sysex(PrivateConstants.ANALOG_MAPPING_QUERY) # wait for the report results to return for 2 seconds # if the timer expires, shutdown while self.query_reply_data.get( PrivateConstants.ANALOG_MAPPING_RESPONSE) is None: elapsed_time = time.time() if elapsed_time - current_time > 4: return None await asyncio.sleep(self.sleep_tune) return self.query_reply_data.get( PrivateConstants.ANALOG_MAPPING_RESPONSE)
python
{ "resource": "" }
q18829
PymataCore.get_capability_report
train
async def get_capability_report(self): """ This method requests and returns a Firmata capability query report :returns: A capability report in the form of a list """ if self.query_reply_data.get( PrivateConstants.CAPABILITY_RESPONSE) is None: await self._send_sysex(PrivateConstants.CAPABILITY_QUERY) while self.query_reply_data.get( PrivateConstants.CAPABILITY_RESPONSE) is None: await asyncio.sleep(self.sleep_tune) return self.query_reply_data.get(PrivateConstants.CAPABILITY_RESPONSE)
python
{ "resource": "" }
q18830
PymataCore.get_protocol_version
train
async def get_protocol_version(self): """ This method returns the major and minor values for the protocol version, i.e. 2.4 :returns: Firmata protocol version """ if self.query_reply_data.get(PrivateConstants.REPORT_VERSION) == '': await self._send_command([PrivateConstants.REPORT_VERSION]) while self.query_reply_data.get( PrivateConstants.REPORT_VERSION) == '': await asyncio.sleep(self.sleep_tune) return self.query_reply_data.get(PrivateConstants.REPORT_VERSION)
python
{ "resource": "" }
q18831
PymataCore.i2c_read_data
train
async def i2c_read_data(self, address): """ This method retrieves cached i2c data to support a polling mode. :param address: I2C device address :returns: Last cached value read """ if address in self.i2c_map: map_entry = self.i2c_map.get(address) data = map_entry.get('value') return data else: return None
python
{ "resource": "" }
q18832
PymataCore.set_analog_latch
train
async def set_analog_latch(self, pin, threshold_type, threshold_value, cb=None, cb_type=None): """ This method "arms" an analog pin for its data to be latched and saved in the latching table If a callback method is provided, when latching criteria is achieved, the callback function is called with latching data notification. Data returned in the callback list has the pin number as the first element, :param pin: Analog pin number (value following an 'A' designator, i.e. A5 = 5 :param threshold_type: ANALOG_LATCH_GT | ANALOG_LATCH_LT | ANALOG_LATCH_GTE | ANALOG_LATCH_LTE :param threshold_value: numerical value - between 0 and 1023 :param cb: callback method :param cb_type: Constants.CB_TYPE_DIRECT = direct call or Constants.CB_TYPE_ASYNCIO = asyncio coroutine :returns: True if successful, False if parameter data is invalid """ if Constants.LATCH_GT <= threshold_type <= Constants.LATCH_LTE: key = 'A' + str(pin) if 0 <= threshold_value <= 1023: self.latch_map[key] = [Constants.LATCH_ARMED, threshold_type, threshold_value, 0, 0, cb, cb_type] return True else: return False
python
{ "resource": "" }
q18833
PymataCore.set_digital_latch
train
async def set_digital_latch(self, pin, threshold_value, cb=None, cb_type=None): """ This method "arms" a digital pin for its data to be latched and saved in the latching table If a callback method is provided, when latching criteria is achieved, the callback function is called with latching data notification. Data returned in the callback list has the pin number as the first element, :param pin: Digital pin number :param threshold_value: 0 or 1 :param cb: callback function :param cb_type: Constants.CB_TYPE_DIRECT = direct call or Constants.CB_TYPE_ASYNCIO = asyncio coroutine :returns: True if successful, False if parameter data is invalid """ if 0 <= threshold_value <= 1: key = 'D' + str(pin) self.latch_map[key] = [Constants.LATCH_ARMED, Constants.LATCH_EQ, threshold_value, 0, 0, cb, cb_type] return True else: return False
python
{ "resource": "" }
q18834
PymataCore.shutdown
train
async def shutdown(self): """ This method attempts an orderly shutdown If any exceptions are thrown, just ignore them. :returns: No return value """ if self.log_output: logging.info('Shutting down ...') else: print('Shutting down ...') await self.send_reset() try: self.loop.stop() except: pass try: self.loop.close() except: pass sys.exit(0)
python
{ "resource": "" }
q18835
PymataCore.sleep
train
async def sleep(self, sleep_time): """ This method is a proxy method for asyncio.sleep :param sleep_time: Sleep interval in seconds :returns: No return value. """ try: await asyncio.sleep(sleep_time) except RuntimeError: if self.log_output: logging.info('sleep exception') else: print('sleep exception') await self.shutdown()
python
{ "resource": "" }
q18836
PymataCore.pixy_init
train
async def pixy_init(self, max_blocks=5, cb=None, cb_type=None): """ Initialize Pixy and enable Pixy block reporting. This is a FirmataPlusRB feature. :param cb: callback function to report Pixy blocks :param cb_type: Constants.CB_TYPE_DIRECT = direct call or Constants.CB_TYPE_ASYNCIO = asyncio coroutine :param max_blocks: Maximum number of Pixy blocks to report when many signatures are found. :returns: No return value. """ if cb: self.digital_pins[PrivateConstants.PIN_PIXY_MOSI].cb = cb # Pixy uses SPI. Pin 11 is MOSI. if cb_type: self.digital_pins[PrivateConstants.PIN_PIXY_MOSI].cb_type = cb_type data = [PrivateConstants.PIXY_INIT, max_blocks & 0x7f] await self._send_sysex(PrivateConstants.PIXY_CONFIG, data)
python
{ "resource": "" }
q18837
PymataCore._command_dispatcher
train
async def _command_dispatcher(self): """ This is a private method. It continually accepts and interprets data coming from Firmata,and then dispatches the correct handler to process the data. :returns: This method never returns """ # sysex commands are assembled into this list for processing sysex = [] while True: try: next_command_byte = await self.read() # if this is a SYSEX command, then assemble the entire # command process it if next_command_byte == PrivateConstants.START_SYSEX: while next_command_byte != PrivateConstants.END_SYSEX: await asyncio.sleep(self.sleep_tune) next_command_byte = await self.read() sysex.append(next_command_byte) await self.command_dictionary[sysex[0]](sysex) sysex = [] await asyncio.sleep(self.sleep_tune) # if this is an analog message, process it. elif 0xE0 <= next_command_byte <= 0xEF: # analog message # assemble the entire analog message in command command = [] # get the pin number for the message pin = next_command_byte & 0x0f command.append(pin) # get the next 2 bytes for the command command = await self._wait_for_data(command, 2) # process the analog message await self._analog_message(command) # handle the digital message elif 0x90 <= next_command_byte <= 0x9F: command = [] port = next_command_byte & 0x0f command.append(port) command = await self._wait_for_data(command, 2) await self._digital_message(command) # handle all other messages by looking them up in the # command dictionary elif next_command_byte in self.command_dictionary: await self.command_dictionary[next_command_byte]() await asyncio.sleep(self.sleep_tune) else: # we need to yield back to the loop await asyncio.sleep(self.sleep_tune) continue except Exception as ex: # A error occurred while transmitting the Firmata message, message arrived invalid. if self.log_output: logging.exception(ex) else: print(ex) await self.shutdown() await self.serial_port.close() print("An exception occurred on the asyncio event loop while receiving data. Invalid message.") loop = self.loop for t in asyncio.Task.all_tasks(loop): t.cancel() loop.run_until_complete(asyncio.sleep(.1)) loop.close() loop.stop() sys.exit(0)
python
{ "resource": "" }
q18838
PymataCore._analog_message
train
async def _analog_message(self, data): """ This is a private message handler method. It is a message handler for analog messages. :param data: message data :returns: None - but saves the data in the pins structure """ pin = data[0] value = (data[PrivateConstants.MSB] << 7) + data[PrivateConstants.LSB] # if self.analog_pins[pin].current_value != value: self.analog_pins[pin].current_value = value # append pin number, pin value, and pin type to return value and return as a list message = [pin, value, Constants.ANALOG] if self.analog_pins[pin].cb: if self.analog_pins[pin].cb_type: await self.analog_pins[pin].cb(message) else: loop = self.loop loop.call_soon(self.analog_pins[pin].cb, message) # is there a latch entry for this pin? key = 'A' + str(pin) if key in self.latch_map: await self._check_latch_data(key, message[1])
python
{ "resource": "" }
q18839
PymataCore._digital_message
train
async def _digital_message(self, data): """ This is a private message handler method. It is a message handler for Digital Messages. :param data: digital message :returns: None - but update is saved in pins structure """ port = data[0] port_data = (data[PrivateConstants.MSB] << 7) + \ data[PrivateConstants.LSB] pin = port * 8 for pin in range(pin, min(pin + 8, len(self.digital_pins))): # get pin value value = port_data & 0x01 # set the current value in the pin structure self.digital_pins[pin].current_value = value # append pin number, pin value, and pin type to return value and return as a list message = [pin, value, Constants.INPUT] if self.digital_pins[pin].cb: if self.digital_pins[pin].cb_type: await self.digital_pins[pin].cb(message) else: # self.digital_pins[pin].cb(data) loop = self.loop loop.call_soon(self.digital_pins[pin].cb, message) # is there a latch entry for this pin? key = 'D' + str(pin) if key in self.latch_map: await self._check_latch_data(key, port_data & 0x01) port_data >>= 1
python
{ "resource": "" }
q18840
PymataCore._encoder_data
train
async def _encoder_data(self, data): """ This is a private message handler method. It handles encoder data messages. :param data: encoder data :returns: None - but update is saved in the digital pins structure """ # strip off sysex start and end data = data[1:-1] pin = data[0] if not self.hall_encoder: val = int((data[PrivateConstants.MSB] << 7) + data[PrivateConstants.LSB]) # set value so that it shows positive and negative values if val > 8192: val -= 16384 # if this value is different that is what is already in the # table store it and check for callback if val != self.digital_pins[pin].current_value: self.digital_pins[pin].current_value = val if self.digital_pins[pin].cb: # self.digital_pins[pin].cb([pin, val]) if self.digital_pins[pin].cb_type: await self.digital_pins[pin].cb(val) else: # self.digital_pins[pin].cb(data) loop = self.loop loop.call_soon(self.digital_pins[pin].cb, val) else: hall_data = [int((data[2] << 7) + data[1]), int((data[5] << 7) + data[4])] if self.digital_pins[pin].cb_type: await self.digital_pins[pin].cb(hall_data) else: # self.digital_pins[pin].cb(data) loop = self.loop loop.call_soon(self.digital_pins[pin].cb, hall_data)
python
{ "resource": "" }
q18841
PymataCore._pixy_data
train
async def _pixy_data(self, data): """ This is a private message handler method. It handles pixy data messages. :param data: pixy data :returns: None - but update is saved in the digital pins structure """ if len(self.digital_pins) < PrivateConstants.PIN_PIXY_MOSI: # Pixy data sent before board finished pin discovery. # print("Pixy data sent before board finished pin discovery.") return # strip off sysex start and end data = data[1:-1] num_blocks = data[0] # First byte is the number of blocks. # Prepare the new blocks list and then used it to overwrite the pixy_blocks. blocks = [] # noinspection PyDictCreation for i in range(num_blocks): block = {} block["signature"] = int((data[i * 12 + 2] << 7) + data[i * 12 + 1]) block["x"] = int((data[i * 12 + 4] << 7) + data[i * 12 + 3]) block["y"] = int((data[i * 12 + 6] << 7) + data[i * 12 + 5]) block["width"] = int((data[i * 12 + 8] << 7) + data[i * 12 + 7]) block["height"] = int((data[i * 12 + 10] << 7) + data[i * 12 + 9]) block["angle"] = int((data[i * 12 + 12] << 7) + data[i * 12 + 11]) blocks.append(block) self.pixy_blocks = blocks if self.digital_pins[PrivateConstants.PIN_PIXY_MOSI].cb: if self.digital_pins[PrivateConstants.PIN_PIXY_MOSI].cb_type: await self.digital_pins[PrivateConstants.PIN_PIXY_MOSI].cb(blocks) else: loop = self.loop loop.call_soon(self.digital_pins[PrivateConstants.PIN_PIXY_MOSI].cb, blocks)
python
{ "resource": "" }
q18842
PymataCore._sonar_data
train
async def _sonar_data(self, data): """ This method handles the incoming sonar data message and stores the data in the response table. :param data: Message data from Firmata :returns: No return value. """ # strip off sysex start and end data = data[1:-1] pin_number = data[0] val = int((data[PrivateConstants.MSB] << 7) + data[PrivateConstants.LSB]) reply_data = [] sonar_pin_entry = self.active_sonar_map[pin_number] if sonar_pin_entry[0] is not None: # check if value changed since last reading if sonar_pin_entry[2] != val: sonar_pin_entry[2] = val self.active_sonar_map[pin_number] = sonar_pin_entry # Do a callback if one is specified in the table if sonar_pin_entry[0]: # if this is an asyncio callback type reply_data.append(pin_number) reply_data.append(val) if sonar_pin_entry[1]: await sonar_pin_entry[0](reply_data) else: # sonar_pin_entry[0]([pin_number, val]) loop = self.loop loop.call_soon(sonar_pin_entry[0], reply_data) # update the data in the table with latest value else: sonar_pin_entry[1] = val self.active_sonar_map[pin_number] = sonar_pin_entry await asyncio.sleep(self.sleep_tune)
python
{ "resource": "" }
q18843
PymataCore._check_latch_data
train
async def _check_latch_data(self, key, data): """ This is a private utility method. When a data change message is received this method checks to see if latching needs to be processed :param key: encoded pin number :param data: data change :returns: None """ process = False latching_entry = self.latch_map.get(key) if latching_entry[Constants.LATCH_STATE] == Constants.LATCH_ARMED: # Has the latching criteria been met if latching_entry[Constants.LATCHED_THRESHOLD_TYPE] == \ Constants.LATCH_EQ: if data == latching_entry[Constants.LATCH_DATA_TARGET]: process = True elif latching_entry[Constants.LATCHED_THRESHOLD_TYPE] == \ Constants.LATCH_GT: if data > latching_entry[Constants.LATCH_DATA_TARGET]: process = True elif latching_entry[Constants.LATCHED_THRESHOLD_TYPE] == \ Constants.LATCH_GTE: if data >= latching_entry[Constants.LATCH_DATA_TARGET]: process = True elif latching_entry[Constants.LATCHED_THRESHOLD_TYPE] == \ Constants.LATCH_LT: if data < latching_entry[Constants.LATCH_DATA_TARGET]: process = True elif latching_entry[Constants.LATCHED_THRESHOLD_TYPE] == \ Constants.LATCH_LTE: if data <= latching_entry[Constants.LATCH_DATA_TARGET]: process = True if process: latching_entry[Constants.LATCHED_DATA] = data await self._process_latching(key, latching_entry)
python
{ "resource": "" }
q18844
PymataCore._discover_port
train
def _discover_port(self): """ This is a private utility method. This method attempts to discover the com port that the arduino is connected to. :returns: Detected Comport """ # if MAC get list of ports if sys.platform.startswith('darwin'): locations = glob.glob('/dev/tty.[usb*]*') locations = glob.glob('/dev/tty.[wchusb*]*') + locations locations.append('end') # for everyone else, here is a list of possible ports else: locations = ['/dev/ttyACM0', '/dev/ttyACM1', '/dev/ttyACM2', '/dev/ttyACM3', '/dev/ttyACM4', '/dev/ttyACM5', '/dev/ttyUSB0', '/dev/ttyUSB1', '/dev/ttyUSB2', '/dev/ttyUSB3', '/dev/ttyUSB4', '/dev/ttyUSB5', '/dev/ttyUSB6', '/dev/ttyUSB7', '/dev/ttyUSB8', '/dev/ttyUSB9', '/dev/ttyUSB10', '/dev/ttyS0', '/dev/ttyS1', '/dev/ttyS2', '/dev/tty.usbserial', '/dev/tty.usbmodem', 'com2', 'com3', 'com4', 'com5', 'com6', 'com7', 'com8', 'com9', 'com10', 'com11', 'com12', 'com13', 'com14', 'com15', 'com16', 'com17', 'com18', 'com19', 'com20', 'com21', 'com1', 'end' ] detected = None for device in locations: try: serialport = serial.Serial(device, 57600, timeout=0) detected = device serialport.close() break except serial.SerialException: if device == 'end': if self.log_output: logging.exception( 'Unable to find Serial Port, Please plug in ' 'cable or check cable connections.') else: print('Unable to find Serial Port, Please plug in ' 'cable or check cable connections.') sys.exit() if self.log_output: log_string = 'Using COM Port: ' + detected logging.info(log_string) else: print('{}{}\n'.format('Using COM Port:', detected)) return detected
python
{ "resource": "" }
q18845
PymataCore._format_capability_report
train
def _format_capability_report(self, data): """ This is a private utility method. This method formats a capability report if the user wishes to send it to the console. If log_output = True, no output is generated :param data: Capability report :returns: None """ if self.log_output: return else: pin_modes = {0: 'Digital_Input', 1: 'Digital_Output', 2: 'Analog', 3: 'PWM', 4: 'Servo', 5: 'Shift', 6: 'I2C', 7: 'One Wire', 8: 'Stepper', 9: 'Encoder'} x = 0 pin = 0 print('\nCapability Report') print('-----------------\n') while x < len(data): # get index of next end marker print('{} {}{}'.format('Pin', str(pin), ':')) while data[x] != 127: mode_str = "" pin_mode = pin_modes.get(data[x]) mode_str += str(pin_mode) x += 1 bits = data[x] print('{:>5}{}{} {}'.format(' ', mode_str, ':', bits)) x += 1 x += 1 pin += 1
python
{ "resource": "" }
q18846
PymataCore._process_latching
train
async def _process_latching(self, key, latching_entry): """ This is a private utility method. This method process latching events and either returns them via callback or stores them in the latch map :param key: Encoded pin :param latching_entry: a latch table entry :returns: Callback or store data in latch map """ if latching_entry[Constants.LATCH_CALLBACK]: # auto clear entry and execute the callback if latching_entry[Constants.LATCH_CALLBACK_TYPE]: await latching_entry[Constants.LATCH_CALLBACK] \ ([key, latching_entry[Constants.LATCHED_DATA], time.time()]) # noinspection PyPep8 else: latching_entry[Constants.LATCH_CALLBACK] \ ([key, latching_entry[Constants.LATCHED_DATA], time.time()]) self.latch_map[key] = [0, 0, 0, 0, 0, None] else: updated_latch_entry = latching_entry updated_latch_entry[Constants.LATCH_STATE] = \ Constants.LATCH_LATCHED updated_latch_entry[Constants.LATCHED_DATA] = \ latching_entry[Constants.LATCHED_DATA] # time stamp it updated_latch_entry[Constants.LATCHED_TIME_STAMP] = time.time() self.latch_map[key] = updated_latch_entry
python
{ "resource": "" }
q18847
PymataCore._send_command
train
async def _send_command(self, command): """ This is a private utility method. The method sends a non-sysex command to Firmata. :param command: command data :returns: length of data sent """ send_message = "" for i in command: send_message += chr(i) result = None for data in send_message: try: result = await self.write(data) except(): if self.log_output: logging.exception('cannot send command') else: print('cannot send command') return result
python
{ "resource": "" }
q18848
PymataCore._send_sysex
train
async def _send_sysex(self, sysex_command, sysex_data=None): """ This is a private utility method. This method sends a sysex command to Firmata. :param sysex_command: sysex command :param sysex_data: data for command :returns : No return value. """ if not sysex_data: sysex_data = [] # convert the message command and data to characters sysex_message = chr(PrivateConstants.START_SYSEX) sysex_message += chr(sysex_command) if len(sysex_data): for d in sysex_data: sysex_message += chr(d) sysex_message += chr(PrivateConstants.END_SYSEX) for data in sysex_message: await self.write(data)
python
{ "resource": "" }
q18849
PymataCore._wait_for_data
train
async def _wait_for_data(self, current_command, number_of_bytes): """ This is a private utility method. This method accumulates the requested number of bytes and then returns the full command :param current_command: command id :param number_of_bytes: how many bytes to wait for :returns: command """ while number_of_bytes: next_command_byte = await self.read() current_command.append(next_command_byte) number_of_bytes -= 1 return current_command
python
{ "resource": "" }
q18850
PymataIOT.analog_write
train
async def analog_write(self, command): """ This method writes a value to an analog pin. It is used to set the output of a PWM pin or the angle of a Servo. :param command: {"method": "analog_write", "params": [PIN, WRITE_VALUE]} :returns: No return message. """ pin = int(command[0]) value = int(command[1]) await self.core.analog_write(pin, value)
python
{ "resource": "" }
q18851
PymataIOT.digital_write
train
async def digital_write(self, command): """ This method writes a zero or one to a digital pin. :param command: {"method": "digital_write", "params": [PIN, DIGITAL_DATA_VALUE]} :returns: No return message.. """ pin = int(command[0]) value = int(command[1]) await self.core.digital_write(pin, value)
python
{ "resource": "" }
q18852
PymataIOT.disable_analog_reporting
train
async def disable_analog_reporting(self, command): """ Disable Firmata reporting for an analog pin. :param command: {"method": "disable_analog_reporting", "params": [PIN]} :returns: No return message.. """ pin = int(command[0]) await self.core.disable_analog_reporting(pin)
python
{ "resource": "" }
q18853
PymataIOT.disable_digital_reporting
train
async def disable_digital_reporting(self, command): """ Disable Firmata reporting for a digital pin. :param command: {"method": "disable_digital_reporting", "params": [PIN]} :returns: No return message. """ pin = int(command[0]) await self.core.disable_digital_reporting(pin)
python
{ "resource": "" }
q18854
PymataIOT.enable_analog_reporting
train
async def enable_analog_reporting(self, command): """ Enable Firmata reporting for an analog pin. :param command: {"method": "enable_analog_reporting", "params": [PIN]} :returns: {"method": "analog_message_reply", "params": [PIN, ANALOG_DATA_VALUE]} """ pin = int(command[0]) await self.core.enable_analog_reporting(pin)
python
{ "resource": "" }
q18855
PymataIOT.enable_digital_reporting
train
async def enable_digital_reporting(self, command): """ Enable Firmata reporting for a digital pin. :param command: {"method": "enable_digital_reporting", "params": [PIN]} :returns: {"method": "digital_message_reply", "params": [PIN, DIGITAL_DATA_VALUE]} """ pin = int(command[0]) await self.core.enable_digital_reporting(pin)
python
{ "resource": "" }
q18856
PymataIOT.encoder_config
train
async def encoder_config(self, command): """ Configure 2 pins for FirmataPlus encoder operation. :param command: {"method": "encoder_config", "params": [PIN_A, PIN_B]} :returns: {"method": "encoder_data_reply", "params": [ENCODER_DATA]} """ pin_a = int(command[0]) pin_b = int(command[1]) await self.core.encoder_config(pin_a, pin_b, self.encoder_callback)
python
{ "resource": "" }
q18857
PymataIOT.encoder_read
train
async def encoder_read(self, command): """ This is a polling method to read the last cached FirmataPlus encoder value. Normally not used. See encoder config for the asynchronous report message format. :param command: {"method": "encoder_read", "params": [PIN_A]} :returns: {"method": "encoder_read_reply", "params": [PIN_A, ENCODER_VALUE]} """ pin = int(command[0]) val = await self.core.encoder_read(pin) reply = json.dumps({"method": "encoder_read_reply", "params": [pin, val]}) await self.websocket.send(reply)
python
{ "resource": "" }
q18858
PymataIOT.get_capability_report
train
async def get_capability_report(self): """ This method retrieves the Firmata capability report. Refer to http://firmata.org/wiki/Protocol#Capability_Query The command format is: {"method":"get_capability_report","params":["null"]} :returns: {"method": "capability_report_reply", "params": [RAW_CAPABILITY_REPORT]} """ value = await self.core.get_capability_report() await asyncio.sleep(.1) if value: reply = json.dumps({"method": "capability_report_reply", "params": value}) else: reply = json.dumps({"method": "capability_report_reply", "params": "None"}) await self.websocket.send(reply)
python
{ "resource": "" }
q18859
PymataIOT.get_pinstate_report
train
async def get_pinstate_report(self, command): """ This method retrieves a Firmata pin_state report for a pin.. See: http://firmata.org/wiki/Protocol#Pin_State_Query :param command: {"method": "get_pin_state", "params": [PIN]} :returns: {"method": "get_pin_state_reply", "params": [PIN_NUMBER, PIN_MODE, PIN_STATE]} """ pin = int(command[0]) value = await self.core.get_pin_state(pin) if value: reply = json.dumps({"method": "pin_state_reply", "params": value}) else: reply = json.dumps({"method": "pin_state_reply", "params": "Unknown"}) await self.websocket.send(reply)
python
{ "resource": "" }
q18860
PymataIOT.get_protocol_version
train
async def get_protocol_version(self): """ This method retrieves the Firmata protocol version. JSON command: {"method": "get_protocol_version", "params": ["null"]} :returns: {"method": "protocol_version_reply", "params": [PROTOCOL_VERSION]} """ value = await self.core.get_protocol_version() if value: reply = json.dumps({"method": "protocol_version_reply", "params": value}) else: reply = json.dumps({"method": "protocol_version_reply", "params": "Unknown"}) await self.websocket.send(reply)
python
{ "resource": "" }
q18861
signal_handler
train
def signal_handler(sig, frame): """Helper method to shutdown the RedBot if Ctrl-c is pressed""" print('\nYou pressed Ctrl+C') if board is not None: board.send_reset() board.shutdown() sys.exit(0)
python
{ "resource": "" }
q18862
_Tags.find_by_id
train
def find_by_id(self, tag, params={}, **options): """Returns the complete tag record for a single tag. Parameters ---------- tag : {Id} The tag to get. [params] : {Object} Parameters for the request """ path = "/tags/%s" % (tag) return self.client.get(path, params, **options)
python
{ "resource": "" }
q18863
_Tags.update
train
def update(self, tag, params={}, **options): """Updates the properties of a tag. Only the fields provided in the `data` block will be updated; any unspecified fields will remain unchanged. When using this method, it is best to specify only those fields you wish to change, or else you may overwrite changes made by another user since you last retrieved the task. Returns the complete updated tag record. Parameters ---------- tag : {Id} The tag to update. [data] : {Object} Data for the request """ path = "/tags/%s" % (tag) return self.client.put(path, params, **options)
python
{ "resource": "" }
q18864
_Tags.delete
train
def delete(self, tag, params={}, **options): """A specific, existing tag can be deleted by making a DELETE request on the URL for that tag. Returns an empty data record. Parameters ---------- tag : {Id} The tag to delete. """ path = "/tags/%s" % (tag) return self.client.delete(path, params, **options)
python
{ "resource": "" }
q18865
_Tags.find_by_workspace
train
def find_by_workspace(self, workspace, params={}, **options): """Returns the compact tag records for all tags in the workspace. Parameters ---------- workspace : {Id} The workspace or organization to find tags in. [params] : {Object} Parameters for the request """ path = "/workspaces/%s/tags" % (workspace) return self.client.get_collection(path, params, **options)
python
{ "resource": "" }
q18866
_Tags.get_tasks_with_tag
train
def get_tasks_with_tag(self, tag, params={}, **options): """Returns the compact task records for all tasks with the given tag. Tasks can have more than one tag at a time. Parameters ---------- tag : {Id} The tag to fetch tasks from. [params] : {Object} Parameters for the request """ path = "/tags/%s/tasks" % (tag) return self.client.get_collection(path, params, **options)
python
{ "resource": "" }
q18867
_OrganizationExports.find_by_id
train
def find_by_id(self, organization_export, params={}, **options): """Returns details of a previously-requested Organization export. Parameters ---------- organization_export : {Id} Globally unique identifier for the Organization export. [params] : {Object} Parameters for the request """ path = "/organization_exports/%s" % (organization_export) return self.client.get(path, params, **options)
python
{ "resource": "" }
q18868
_CustomFields.find_by_id
train
def find_by_id(self, custom_field, params={}, **options): """Returns the complete definition of a custom field's metadata. Parameters ---------- custom_field : {Id} Globally unique identifier for the custom field. [params] : {Object} Parameters for the request """ path = "/custom_fields/%s" % (custom_field) return self.client.get(path, params, **options)
python
{ "resource": "" }
q18869
_CustomFields.update
train
def update(self, custom_field, params={}, **options): """A specific, existing custom field can be updated by making a PUT request on the URL for that custom field. Only the fields provided in the `data` block will be updated; any unspecified fields will remain unchanged When using this method, it is best to specify only those fields you wish to change, or else you may overwrite changes made by another user since you last retrieved the custom field. A custom field's `type` cannot be updated. An enum custom field's `enum_options` cannot be updated with this endpoint. Instead see "Work With Enum Options" for information on how to update `enum_options`. Returns the complete updated custom field record. Parameters ---------- custom_field : {Id} Globally unique identifier for the custom field. [data] : {Object} Data for the request """ path = "/custom_fields/%s" % (custom_field) return self.client.put(path, params, **options)
python
{ "resource": "" }
q18870
_CustomFields.delete
train
def delete(self, custom_field, params={}, **options): """A specific, existing custom field can be deleted by making a DELETE request on the URL for that custom field. Returns an empty data record. Parameters ---------- custom_field : {Id} Globally unique identifier for the custom field. """ path = "/custom_fields/%s" % (custom_field) return self.client.delete(path, params, **options)
python
{ "resource": "" }
q18871
_CustomFields.update_enum_option
train
def update_enum_option(self, enum_option, params={}, **options): """Updates an existing enum option. Enum custom fields require at least one enabled enum option. Returns the full record of the updated enum option. Parameters ---------- enum_option : {Id} Globally unique identifier for the enum option. [data] : {Object} Data for the request - name : {String} The name of the enum option. - [color] : {String} The color of the enum option. Defaults to 'none'. - [enabled] : {Boolean} Whether or not the enum option is a selectable value for the custom field. """ path = "/enum_options/%s" % (enum_option) return self.client.put(path, params, **options)
python
{ "resource": "" }
q18872
_CustomFields.insert_enum_option
train
def insert_enum_option(self, custom_field, params={}, **options): """Moves a particular enum option to be either before or after another specified enum option in the custom field. Parameters ---------- custom_field : {Id} Globally unique identifier for the custom field. [data] : {Object} Data for the request - enum_option : {Id} The ID of the enum option to relocate. - name : {String} The name of the enum option. - [color] : {String} The color of the enum option. Defaults to 'none'. - [before_enum_option] : {Id} An existing enum option within this custom field before which the new enum option should be inserted. Cannot be provided together with after_enum_option. - [after_enum_option] : {Id} An existing enum option within this custom field after which the new enum option should be inserted. Cannot be provided together with before_enum_option. """ path = "/custom_fields/%s/enum_options/insert" % (custom_field) return self.client.post(path, params, **options)
python
{ "resource": "" }
q18873
_ProjectMemberships.find_by_project
train
def find_by_project(self, project, params={}, **options): """Returns the compact project membership records for the project. Parameters ---------- project : {Id} The project for which to fetch memberships. [params] : {Object} Parameters for the request - [user] : {String} If present, the user to filter the memberships to. """ path = "/projects/%s/project_memberships" % (project) return self.client.get_collection(path, params, **options)
python
{ "resource": "" }
q18874
_ProjectMemberships.find_by_id
train
def find_by_id(self, project_membership, params={}, **options): """Returns the project membership record. Parameters ---------- project_membership : {Id} Globally unique identifier for the project membership. [params] : {Object} Parameters for the request """ path = "/project_memberships/%s" % (project_membership) return self.client.get(path, params, **options)
python
{ "resource": "" }
q18875
_Workspaces.find_by_id
train
def find_by_id(self, workspace, params={}, **options): """Returns the full workspace record for a single workspace. Parameters ---------- workspace : {Id} Globally unique identifier for the workspace or organization. [params] : {Object} Parameters for the request """ path = "/workspaces/%s" % (workspace) return self.client.get(path, params, **options)
python
{ "resource": "" }
q18876
_Workspaces.update
train
def update(self, workspace, params={}, **options): """A specific, existing workspace can be updated by making a PUT request on the URL for that workspace. Only the fields provided in the data block will be updated; any unspecified fields will remain unchanged. Currently the only field that can be modified for a workspace is its `name`. Returns the complete, updated workspace record. Parameters ---------- workspace : {Id} The workspace to update. [data] : {Object} Data for the request """ path = "/workspaces/%s" % (workspace) return self.client.put(path, params, **options)
python
{ "resource": "" }
q18877
_Workspaces.add_user
train
def add_user(self, workspace, params={}, **options): """The user can be referenced by their globally unique user ID or their email address. Returns the full user record for the invited user. Parameters ---------- workspace : {Id} The workspace or organization to invite the user to. [data] : {Object} Data for the request - user : {String} An identifier for the user. Can be one of an email address, the globally unique identifier for the user, or the keyword `me` to indicate the current user making the request. """ path = "/workspaces/%s/addUser" % (workspace) return self.client.post(path, params, **options)
python
{ "resource": "" }
q18878
_Workspaces.remove_user
train
def remove_user(self, workspace, params={}, **options): """The user making this call must be an admin in the workspace. Returns an empty data record. Parameters ---------- workspace : {Id} The workspace or organization to invite the user to. [data] : {Object} Data for the request - user : {String} An identifier for the user. Can be one of an email address, the globally unique identifier for the user, or the keyword `me` to indicate the current user making the request. """ path = "/workspaces/%s/removeUser" % (workspace) return self.client.post(path, params, **options)
python
{ "resource": "" }
q18879
_Attachments.find_by_id
train
def find_by_id(self, attachment, params={}, **options): """Returns the full record for a single attachment. Parameters ---------- attachment : {Id} Globally unique identifier for the attachment. [params] : {Object} Parameters for the request """ path = "/attachments/%s" % (attachment) return self.client.get(path, params, **options)
python
{ "resource": "" }
q18880
_Attachments.find_by_task
train
def find_by_task(self, task, params={}, **options): """Returns the compact records for all attachments on the task. Parameters ---------- task : {Id} Globally unique identifier for the task. [params] : {Object} Parameters for the request """ path = "/tasks/%s/attachments" % (task) return self.client.get_collection(path, params, **options)
python
{ "resource": "" }
q18881
Attachments.create_on_task
train
def create_on_task(self, task_id, file_content, file_name, file_content_type=None, **options): """Upload an attachment for a task. Accepts a file object or string, file name, and optional file Content-Type""" path = '/tasks/%d/attachments' % (task_id) return self.client.request('post', path, files=[('file', (file_name, file_content, file_content_type))], **options)
python
{ "resource": "" }
q18882
_Teams.find_by_id
train
def find_by_id(self, team, params={}, **options): """Returns the full record for a single team. Parameters ---------- team : {Id} Globally unique identifier for the team. [params] : {Object} Parameters for the request """ path = "/teams/%s" % (team) return self.client.get(path, params, **options)
python
{ "resource": "" }
q18883
_Teams.find_by_organization
train
def find_by_organization(self, organization, params={}, **options): """Returns the compact records for all teams in the organization visible to the authorized user. Parameters ---------- organization : {Id} Globally unique identifier for the workspace or organization. [params] : {Object} Parameters for the request """ path = "/organizations/%s/teams" % (organization) return self.client.get_collection(path, params, **options)
python
{ "resource": "" }
q18884
_Teams.find_by_user
train
def find_by_user(self, user, params={}, **options): """Returns the compact records for all teams to which user is assigned. Parameters ---------- user : {String} An identifier for the user. Can be one of an email address, the globally unique identifier for the user, or the keyword `me` to indicate the current user making the request. [params] : {Object} Parameters for the request - [organization] : {Id} The workspace or organization to filter teams on. """ path = "/users/%s/teams" % (user) return self.client.get_collection(path, params, **options)
python
{ "resource": "" }
q18885
_Teams.users
train
def users(self, team, params={}, **options): """Returns the compact records for all users that are members of the team. Parameters ---------- team : {Id} Globally unique identifier for the team. [params] : {Object} Parameters for the request """ path = "/teams/%s/users" % (team) return self.client.get_collection(path, params, **options)
python
{ "resource": "" }
q18886
_Teams.add_user
train
def add_user(self, team, params={}, **options): """The user making this call must be a member of the team in order to add others. The user to add must exist in the same organization as the team in order to be added. The user to add can be referenced by their globally unique user ID or their email address. Returns the full user record for the added user. Parameters ---------- team : {Id} Globally unique identifier for the team. [data] : {Object} Data for the request - user : {String} An identifier for the user. Can be one of an email address, the globally unique identifier for the user, or the keyword `me` to indicate the current user making the request. """ path = "/teams/%s/addUser" % (team) return self.client.post(path, params, **options)
python
{ "resource": "" }
q18887
_Teams.remove_user
train
def remove_user(self, team, params={}, **options): """The user to remove can be referenced by their globally unique user ID or their email address. Removes the user from the specified team. Returns an empty data record. Parameters ---------- team : {Id} Globally unique identifier for the team. [data] : {Object} Data for the request - user : {String} An identifier for the user. Can be one of an email address, the globally unique identifier for the user, or the keyword `me` to indicate the current user making the request. """ path = "/teams/%s/removeUser" % (team) return self.client.post(path, params, **options)
python
{ "resource": "" }
q18888
Tasks.set_parent
train
def set_parent(self, task_id, params={}, **options): """Changes the parent of a task. Each task may only be a subtask of a single parent, or no parent task at all. Returns an empty data block. Parameters ---------- task : {Id} Globally unique identifier for the task. [data] : {Object} Data for the request - parent : {Id} The new parent of the task, or `null` for no parent. """ path = '/tasks/%s/setParent' % (task_id) return self.client.post(path, params, **options)
python
{ "resource": "" }
q18889
_Sections.create_in_project
train
def create_in_project(self, project, params={}, **options): """Creates a new section in a project. Returns the full record of the newly created section. Parameters ---------- project : {Id} The project to create the section in [data] : {Object} Data for the request - name : {String} The text to be displayed as the section name. This cannot be an empty string. """ path = "/projects/%s/sections" % (project) return self.client.post(path, params, **options)
python
{ "resource": "" }
q18890
_Sections.find_by_project
train
def find_by_project(self, project, params={}, **options): """Returns the compact records for all sections in the specified project. Parameters ---------- project : {Id} The project to get sections from. [params] : {Object} Parameters for the request """ path = "/projects/%s/sections" % (project) return self.client.get(path, params, **options)
python
{ "resource": "" }
q18891
_Sections.find_by_id
train
def find_by_id(self, section, params={}, **options): """Returns the complete record for a single section. Parameters ---------- section : {Id} The section to get. [params] : {Object} Parameters for the request """ path = "/sections/%s" % (section) return self.client.get(path, params, **options)
python
{ "resource": "" }
q18892
_Sections.delete
train
def delete(self, section, params={}, **options): """A specific, existing section can be deleted by making a DELETE request on the URL for that section. Note that sections must be empty to be deleted. The last remaining section in a board view cannot be deleted. Returns an empty data block. Parameters ---------- section : {Id} The section to delete. """ path = "/sections/%s" % (section) return self.client.delete(path, params, **options)
python
{ "resource": "" }
q18893
_Sections.insert_in_project
train
def insert_in_project(self, project, params={}, **options): """Move sections relative to each other in a board view. One of `before_section` or `after_section` is required. Sections cannot be moved between projects. At this point in time, moving sections is not supported in list views, only board views. Returns an empty data block. Parameters ---------- project : {Id} The project in which to reorder the given section [data] : {Object} Data for the request - section : {Id} The section to reorder - [before_section] : {Id} Insert the given section immediately before the section specified by this parameter. - [after_section] : {Id} Insert the given section immediately after the section specified by this parameter. """ path = "/projects/%s/sections/insert" % (project) return self.client.post(path, params, **options)
python
{ "resource": "" }
q18894
_Stories.find_by_id
train
def find_by_id(self, story, params={}, **options): """Returns the full record for a single story. Parameters ---------- story : {Id} Globally unique identifier for the story. [params] : {Object} Parameters for the request """ path = "/stories/%s" % (story) return self.client.get(path, params, **options)
python
{ "resource": "" }
q18895
_Stories.update
train
def update(self, story, params={}, **options): """Updates the story and returns the full record for the updated story. Only comment stories can have their text updated, and only comment stories and attachment stories can be pinned. Only one of `text` and `html_text` can be specified. Parameters ---------- story : {Id} Globally unique identifier for the story. [data] : {Object} Data for the request - [text] : {String} The plain text with which to update the comment. - [html_text] : {String} The rich text with which to update the comment. - [is_pinned] : {Boolean} Whether the story should be pinned on the resource. """ path = "/stories/%s" % (story) return self.client.put(path, params, **options)
python
{ "resource": "" }
q18896
_Stories.delete
train
def delete(self, story, params={}, **options): """Deletes a story. A user can only delete stories they have created. Returns an empty data record. Parameters ---------- story : {Id} Globally unique identifier for the story. """ path = "/stories/%s" % (story) return self.client.delete(path, params, **options)
python
{ "resource": "" }
q18897
_Tasks.find_by_id
train
def find_by_id(self, task, params={}, **options): """Returns the complete task record for a single task. Parameters ---------- task : {Id} The task to get. [params] : {Object} Parameters for the request """ path = "/tasks/%s" % (task) return self.client.get(path, params, **options)
python
{ "resource": "" }
q18898
_Tasks.update
train
def update(self, task, params={}, **options): """A specific, existing task can be updated by making a PUT request on the URL for that task. Only the fields provided in the `data` block will be updated; any unspecified fields will remain unchanged. When using this method, it is best to specify only those fields you wish to change, or else you may overwrite changes made by another user since you last retrieved the task. Returns the complete updated task record. Parameters ---------- task : {Id} The task to update. [data] : {Object} Data for the request """ path = "/tasks/%s" % (task) return self.client.put(path, params, **options)
python
{ "resource": "" }
q18899
_Tasks.delete
train
def delete(self, task, params={}, **options): """A specific, existing task can be deleted by making a DELETE request on the URL for that task. Deleted tasks go into the "trash" of the user making the delete request. Tasks can be recovered from the trash within a period of 30 days; afterward they are completely removed from the system. Returns an empty data record. Parameters ---------- task : {Id} The task to delete. """ path = "/tasks/%s" % (task) return self.client.delete(path, params, **options)
python
{ "resource": "" }