<commit_before>'''
Created on Aug 6, 2016

@author: pete
'''
import logging
import time
import uuid
import threading
from iote2epyclient.launch.clientutils import ClientUtils
from iote2epyclient.schema.iote2erequest import Iote2eRequest
from sense_hat import SenseHat

logger = logging.getLogger(__name__)


class ProcessLedGreen(object):
    '''
    classdocs
    '''

    def __init__(self, loginVo, sensorName):
        self.loginVo = loginVo
        self.sensorName = sensorName
        self.sense = SenseHat()
        self.sense.clear()
        
        
    def createIote2eRequest(self ):
        while True:
            event = self.sense.stick.wait_for_event()
            if 'middle' == event.direction:
                if 'pressed' == event.action:
                    btnPressed = '1'
                elif 'released' == event.action:
                    btnPressed = '0'
                else: 
                    continue
                logger.info( "ProcessSimLedGreen createIote2eRequest {}: {}".format(self.sensorName,btnPressed))
        
                pairs = { self.sensorName: str(btnPressed)}
                iote2eRequest = Iote2eRequest( login_name=self.loginVo.loginName,source_name=self.loginVo.sourceName, source_type='switch', 
                                               request_uuid=str(uuid.uuid4()), 
                                               request_timestamp=ClientUtils.nowIso8601(), 
                                               pairs=pairs, operation='SENSORS_VALUES')
                break
            
        return iote2eRequest


    def handleIote2eResult(self, iote2eResult ):
        # TODO: turn on/off actuator (fan) here
        logger.info('ProcessSimHumidityToMister handleIote2eResult: ' + str(iote2eResult))
        actuatorValue = iote2eResult.pairs['actuatorValue'];
        logger.info('actuatorValue {}'.format(actuatorValue))
        if 'off' == actuatorValue:
            self.sense.clear()
        elif 'green' == actuatorValue:
            self.sense.clear(0,255,0)

        <commit_msg>button<commit_after>'''
Created on Aug 6, 2016

@author: pete
'''
import logging
import time
import uuid
import threading
from iote2epyclient.launch.clientutils import ClientUtils
from iote2epyclient.schema.iote2erequest import Iote2eRequest
import piplates.DAQCplate as DAQC


logger = logging.getLogger(__name__)


class ProcessLedGreen(object):
    '''
    classdocs
    '''

    def __init__(self, loginVo, sensorName):
        self.loginVo = loginVo
        self.sensorName = sensorName
        self.btnPressed = '0'
        DAQC.clrLED(0,0)

        DAQC.setLED(0,0)
        if DAQC.getINTflags(0) == 256:
            break
        time.sleep(.25)
        if DAQC.getINTflags(0) == 256:
            break
        
        
        
    def createIote2eRequest(self ):
        swState = DAQC.getSWstate(0) 
        while True:
            if (self.btnPressed == '0' and swState == 1 ) or (self.btnPressed == '1' and swState == 0):
                self.btnPressed = str(swState)
                logger.info( "ProcessLedGreen createIote2eRequest {}: {}".format(self.sensorName,self.btnPressed))
        
                pairs = { self.sensorName: str(self.btnPressed)}
                iote2eRequest = Iote2eRequest( login_name=self.loginVo.loginName,source_name=self.loginVo.sourceName, source_type='switch', 
                                               request_uuid=str(uuid.uuid4()), 
                                               request_timestamp=ClientUtils.nowIso8601(), 
                                               pairs=pairs, operation='SENSORS_VALUES')
                break
            
        return iote2eRequest


    def handleIote2eResult(self, iote2eResult ):
        logger.info('ProcessSimHumidityToMister handleIote2eResult: ' + str(iote2eResult))
        actuatorValue = iote2eResult.pairs['actuatorValue'];
        logger.info('actuatorValue {}'.format(actuatorValue))
        if 'off' == actuatorValue:
            DAQC.clrLED(0,0)
        elif 'green' == actuatorValue:
            DAQC.setLED(0,1)

        
{'fraction_non_alphanumeric': 0.09556313993174062, 'fraction_numerical': 0.019258898098488544, 'mean_word_length': 1.9581831290555154, 'pattern_counts': {'":': 0, '<': 3, '<?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': 12, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3400985', 'n_tokens_mistral': 1254, 'n_tokens_neox': 1164, 'n_words': 217}