AHF_LickDetector

LickDetector is only implemented for the MPR121 Capacitive Touch Sensor, in AHF_LickDetector_MPR.

AHF_LickDetector.AHF_LickDetector module

class AHF_LickDetector.AHF_LickDetector(taskP, settingsDictP)

Bases: AHF_Base.AHF_Base

Base class for lick detetctor. Some kind of touch sensor on water port, capacitive or electrical. Should only report touches of the lick port, not un-touches. May have multiple channels. Must be able to count licks in an independent thread or via a threaded callback

abstract getLickCount()
abstract getTouches()

returns number(bit-wise per channel lick detetctor has multiple channels) of which channels are currently touched

abstract resumeLickCount()
abstract startLickCount()

Zeros the array that stores lick counts for each channel, and makes sure callback is filling the array for requested channels

abstract startLickTiming()

Zeros the array that stores lick counts for each channel, and makes sure callback is filling the array for requested channels

abstract startLogging()

Starts the datalogger logging licks to the shell, and to a file if one was provided

abstract stopLickCount()

takes a tuple of channels and returns a list where each member is the number of licks for that channel in the global array call zeroLickCount, wait a while for some licks, then call getLickCount

abstract stopLickTiming()

takes a tuple of channels and returns a list where each member is the number of licks for that channel in the global array call zeroLickCount, wait a while for some licks, then call getLickCount

abstract stopLogging()

Stops the datalogger logging licks to the shell and file

abstract waitForLick(timeOut_secs, startFromZero=False)

Waits for a lick on any channel. Returns channel that was touched, or 0 if timeout expires with no touch, or -1 if startFromZero was True and the detector was touched for entire time

AHF_LickDetector.AHF_LickDetector_MPR module

class AHF_LickDetector_MPR.AHF_LickDetector_MPR(taskP, settingsDictP)

Bases: AHF_LickDetector.AHF_LickDetector

Lick detector for Auto Head Fix based on MPR121 capacitive touch sensor

static about()

Returns a brief message describing your sub-class, used when asking user to pick a sub-class of this class

clearResultsDict(resultsDict)

Clears values in the results dictionary, for daily totals of licks on all channels. Could be extended to per channel data

static config_user_get(starterDict={})

static method that querries user for settings, with default responses from starterDict, and returns starterDict with settings as edited by the user.

defaultAddress = 90
defaultIRQ = 26
defaultTouchChannels = (0, 1, 2, 3)
defaultTouchThresh = 8
defaultUntouchThresh = 4
getLickCount()

Get the number of licks for each channel in the global array without stopping the count.

getTouches()

gets touches from mpr121

hardwareTest()

Tests functionality, gives user a chance to change settings. :Returns: bool – True if any settings have changed

static logTouchCallback(touchedChannel)

custom callback using global task reference from AHF_Task

newResultsDict(starterDict={})

Returns a dictionary with fields, initialized to 0,

resetDetector()

Calls MPR121 reset function. Should rarely need to do this? This could be of use in resetting baseline untouched values.

resumeLickCount()

Continue the lick counting without zeroing the channels

setdown()

oppposite of setup. Releases any hardware resouces. can be run before editing settings so GPIO pins can be reused, for example. This strategy should be used in hardwareTest method.

setup()

does hardware initialization with(possibly updated) info in self.settingsDict Run by __init__, or can be run separately after editing the settingsDict

Returns

code

bool whether setup completed without errors

startLickCount()

Zeros the selected list of channels in the global array of licks per channel that the callback function updates. Use it to count licks, by zeroing selected channels, then checking the values in the array

startLickTiming()

Zeros the array that stores lick counts for each channel, and makes sure callback is filling the array for requested channels

startLogging()

tells the AHF_LickDetectorCallback to log touches in shell and file(if present)

stopLickCount(chanList)

takes a list of channels and returns a list where each member is the number of licks for that channel in the global array call zeroLickCount, wait a while for some licks, then call getLickCount

stopLickTiming()

takes a tuple of channels and returns a list where each member is the number of licks for that channel in the global array call zeroLickCount, wait a while for some licks, then call getLickCount

stopLogging()

tells the AHF_LickDetectorCallback to stop logging touches in shell and file(if present) but the callback is still running

waitForLick(timeOut_secs, startFromZero=False)

Waits for a lick on any channel. Returns channel that was touched, or 0 if timeout expires with no touch, or -1 if startFromZero was True and the detector was touched for entire time