Skip to content

Commit

Permalink
Charge delay for continuous recipes
Browse files Browse the repository at this point in the history
If charge delay is defined then put the recipe to sleep for the duration of charge delay.
This prevents things like mouse scroll from triggering hundreds of times per second.
  • Loading branch information
Timo Aho committed Nov 6, 2015
1 parent bf87b73 commit cf25dea
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 10 deletions.
2 changes: 2 additions & 0 deletions client/etc/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,8 @@ recipes:
signs:
- 'pinchRing'
action: 'mouse2Click'
continuous: true
chargeDelay: 500
# compoundRecipe:
# signs:
# - 'pinchRing'
Expand Down
36 changes: 26 additions & 10 deletions client/src/ActionController.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -146,16 +146,32 @@ class ActionController
recipe = @recipes[recipeName]
#console.log "recipe data:", recipe
actionName = recipe.action
if(recipe.continuous)
#console.log "activate continuous recipe: ", recipeName
@executeAction(actionName)
return true
else if(@recipeState[recipeName].status == 'inactive')
if(!@recipeState[recipeName].timerID)
console.log "Activate recipe #{recipeName}"
@recipeState[recipeName].status = 'active'
@executeAction(actionName)
return true

# Skip activation if charging
if(!@recipeState[recipeName].timerID)
if(recipe.continuous)
if(@recipeState[recipeName].status != 'sleeping')
if(recipe.chargeDelay)
chargeDelay = recipe.chargeDelay
#console.log "Recipe #{recipeName} sleeping for #{chargeDelay}"
callback = () =>
#console.log "Recipe #{recipeName} is awake!"
@recipeState[recipeName].status = 'inactive'
@recipeState[recipeName].timerID = null
@recipeState[recipeName].status = 'sleeping'
@recipeState[recipeName].timerID = setTimeout callback, chargeDelay
#console.log "activate continuous recipe: ", recipeName
@executeAction(actionName)
return true
else
#console.log "Recipe #{recipeName} is sleeping..."
return false
else if(@recipeState[recipeName].status == 'inactive')
if(!@recipeState[recipeName].timerID)
#console.log "Activate recipe #{recipeName}"
@recipeState[recipeName].status = 'active'
@executeAction(actionName)
return true
return false

tearDownRecipe: (recipeName) =>
Expand Down

0 comments on commit cf25dea

Please sign in to comment.