예제 #1
0
from flask import Flask, request
import rivalcfg as rc

import json
app = Flask(__name__)

device = rc.get_first_mouse()


@app.route("/", methods=['GET', 'POST'])
def main():
    if request.method != 'POST':
        return ('done')
    req = request.get_json(silent=True)
    resp = {'fulfillmentText': "Welcome!"}
    try:
        color = req['queryResult']['parameters']['color']
        device.set_color(color)

        resp = {"fulfillmentText": "Done!"}
    except:
        pass

    return json.dumps(resp)
예제 #2
0
config = [
  (5, (0, 0, 255)),
  (5, (0, 255, 255)),
  (5, (0, 255, 0)),
  (5, (255, 255, 0)),
  (5, (255, 255, 255)),
  (5, (255, 0, 255)),
]

def interpolate(t, a, b):
  if t > 1: t = 1
  if t < 0: t = 0
  return tuple( int((1 - t) * x + t * y) for (x, y) in zip(a, b))

while True:
  mouse = rivalcfg.get_first_mouse()
  if mouse is None:
    time.sleep(1)
  else:
    try:      
      prev = (0, 0, 0)
      for (total_time, color) in cycle(config):
         t = 0
         while t < total_time:
           c = interpolate(t / total_time, prev, color)
           mouse.set_color(*c)
           t += delta
           time.sleep(delta)
         prev = color
    except Exception as e:
      print("Could not talk to mouse: " + str(e))
예제 #3
0
 def test_supported_mouse(self, monkeypatch):
     monkeypatch.setattr("rivalcfg.debug.DEBUG", True)
     monkeypatch.setattr("rivalcfg.debug.DRY", True)
     monkeypatch.setenv("RIVALCFG_PROFILE", "1038:1710")
     assert rivalcfg.get_first_mouse()