Exemple #1
0
 def enter_key(self, key):
     if not self.armed:
         reload_config()
         self.armed = config['ALARM_ON']
     if self.armed:
         self.code = self.code + key
         length = len(self.code)
         self.lcd.text('*' * length, 2)
Exemple #2
0
def run():
    """Load and train model
    Create a model object and run the training using the provided config.
    """
    config = get_image_config()
    # To reload a saved model
    config = reload_config(config.FLAGS)

    # Add timestamp to log path
    config.log_dir = os.path.join(config.log_dir, '%s' % config.run_name)

    # Add model name to log path
    config.log_dir = config.log_dir + '_kvae'

    # Create log path
    if not os.path.isdir(config.log_dir):
        os.makedirs(config.log_dir)

    # Save hyperparameters
    with open(config.log_dir + '/config.json', 'w') as f:
        json.dump(config.__flags, f)

    # Set GPU
    os.environ['CUDA_VISIBLE_DEVICES'] = config.gpu

    with tf.Session() as session:
        trainer = KVAETrainer(session, config)
        trainer.train()
        trainer.imputation_plot()
Exemple #3
0
def reload_command(update, context):
    message = update.message
    chat = message.chat
    user = message.from_user
    if user.id not in get_chat_admins(
            context.bot, chat.id,
            context.bot_data.get("config").get("SUPER_ADMIN")):
        logger.info(f"Reload: User {user.id} is unauthorized, blocking")
        message.reply_text(
            context.bot_data.get("config").get("START_UNAUTHORIZED_PRIVATE"))
        return
    message.reply_text(reload_config(context))
Exemple #4
0
def save_private(context, callback_query):
    save_config(context.bot_data.get("config"),
                context.bot_data.get("config").get("filename"))
    context.chat_data.clear()
    keyboard = [
        [
            InlineKeyboardButton(context.bot_data.get("config").get("BACK"),
                                 callback_data="back")
        ],
    ]
    markup = InlineKeyboardMarkup(keyboard)
    callback_query.edit_message_text(
        reload_config(context),
        reply_markup=markup,
    )
    logger.info(f"Private: Saved config")
    logger.debug(context.bot_data.get("config"))
Exemple #5
0
async def from_streams(base_reader):
    '''
    Asyncio coroutine task to read from all streams &
    detect and then execute the command based on the confirmation tap
    '''
    try:
        # Wait for half a second before processing the events
        await asyncio.sleep(0.5)
        # Grab the touchpad to draw gesture until this coroutine is cancelled
        base_reader.grab()
        # Init all the readers
        x_movement_reader = Reader(base_reader)
        y_movement_reader = Reader(base_reader)
        tap_detector_reader = Reader(base_reader)

        # Reload gesture command map
        reload_config()

        # Store the received coordinates
        coordinates_set = []
        start_time = end_time = 0

        # Zip the X and Y axis events for clarity.
        # It is processed separtely though when sanitizing the input
        zip_xy = ziplatest(y_movement(x_movement_reader),
                           x_movement(y_movement_reader))
        # Read the tap events as well to indicate
        # the start and end of gesture drawing
        merge_tap_xy = merge(zip_xy,
                             tap_detector(tap_detector_reader))

        async with merge_tap_xy.stream() as merged:
            async for event in merged:
                # The zip_xy events are in the form of tuples
                # while the tap events are evdev event objects
                if not isinstance(event, tuple):
                    if event.value == 1:
                        start_time = event.timestamp()
                    elif event.value == 0:
                        end_time = event.timestamp()
                        # If the draw is too short, ignore and reset
                        # cause it's not meaningful
                        if (end_time - start_time) < 0.3:
                            coordinates_set = []
                            continue

                        detected_gesture = sanitize_and_notify(coordinates_set)
                        # print(f'Detected gesture :- {detected_gesture}')

                        coordinates_set = []
                        if detected_gesture is None:
                            continue
                        # If gesture detected then wait for a confirmation tap
                        tapped, event = await confirmation_tap(base_reader)

                        if tapped:
                            notify(f"Confirmed. Running- {detected_gesture}")
                            execute_command(detected_gesture)
                        else:
                            notify("Clearing gestures")
                else:
                    coordinates_set.append(event)

    except asyncio.CancelledError:
        # Exit all readers from the base_reader once they are done
        x_movement_reader.exit()
        y_movement_reader.exit()
        tap_detector_reader.exit()
        # Ungrab and yield control of touchpad to the user
        base_reader.ungrab()
Exemple #6
0
from utils import reload_config
from generators import detect_key_hold, detect_key_tap

touchpad_path = '/dev/input/event5'
gesture_command_map_file = 'gesture_map.yml'


def handle_exception(loop, context):
    # msg = context.get("exception", context["message"])
    # print(msg)
    # print(context)
    pass  
    # This gets called when from_streams() task is cancelled
    # because the Futures are trying to write but the coroutine
    # is no longer running but it doesn't really matter so
    # we just silently ignore it


reload_config(gesture_command_map_file)
tasks = asyncio.gather(detect_key_hold(touchpad_path))
# detect_key_tap(touchpad_path))

loop = asyncio.get_event_loop()
loop.set_exception_handler(handle_exception)
try:
    loop.run_until_complete(tasks)
except KeyboardInterrupt:
    tasks.cancel()
    loop.close()