def draw(self): for i in self.__shapeListSS.values(): # I will break camera class coupling with the shape class # It may not be efficent I am thinking on it. i.setDrawStyle(self.__drawStyle) i = self.__activeCam.view(i) i.draw() Light.lightsON(self.__lightsStatus) for light in self.__lights: if (light.getLightStatus()): light = self.__activeCam.view(light) light.draw()
def light_status(secret): """Makes it check the status of the lights""" if not access(request.url, secret, "Sjekket status"): return "No." Light.refresh() target_light = request.args.get("target_light") light = Light.find_light(target_light) if light: # hvis vi kommer hit, så vet vi at vi har funnet lyset if light.on: return "Lyset er på. :-)" return "Lyset er av." return "Fant ikke lyset."
def scene_texcylinder2(): def test(face, u, v): if face == 0: return (0.1, 1.0, 0.1), 0.3, 0.2, 6 u = u - 0.5 v = v - 0.5 b = u / (math.sqrt(u * u + v * v)) if 0.0 < v: c = math.degrees(math.asin(b)) else: c = 360 - math.degrees(math.asin(b)) c = c + 180.8 c = c / 30.0 c = math.floor(c) c = evaluator.modi(c, 2) if c == 1: return (1.0, 0.1, 0.1), 0.3, 0.2, 6 else: return (0.1, 0.1, 1.0), 0.3, 0.2, 6 l = [Light((1.0, -1.0, 1.0), (1.0, 1.0, 1.0))] c = Cylinder(test) c.translate(0.0, -0.5, 0.0) c.rotatex(60.0) c.rotatey(20.0) c.rotatez(40.0) return c, l
def scene_viewhole(): def blue(face, u, v): return (0.1, 0.1, 1.0), 0.3, 0.2, 6 def red(face, u, v): return (1.0, 0.1, 0.1), 0.3, 0.2, 6 def green(face, u, v): return (0.1, 1.0, 0.1), 0.3, 0.2, 6 def yellow(face, u, v): return (0.1, 1.0, 1.0), 0.3, 0.2, 6 def cyan(face, u, v): return (1.0, 1.0, 0.1), 0.3, 0.2, 6 def magenta(face, u, v): return (1.0, 0.1, 1.0), 0.3, 0.2, 6 def white(face, u, v): return (1.0, 1.0, 1.0), 0.3, 0.2, 6 def apex(rot): p1 = Plane(white) p1.rotatex(90) p2 = Plane(red) p2.rotatex(-90) p2.rotatey(30) i = Intersect(p1, p2) i.rotatey(rot) return i l = [Light((1.0, -1.0, 1.0), (1.0, 1.0, 1.0))] cyl3 = Cylinder(red) cyl3.scale(0.9999, 0.9999, 0.999) cyl3.translate(0.0, 3.0, 0.0) cyl4 = Cylinder(blue) cyl4.scale(0.7, 4.0, 0.7) a1 = apex(15) a2 = apex(75) a3 = apex(135) a4 = apex(195) a5 = apex(255) a6 = apex(315) u3 = Union(Union(Union(Union(Union(a1, a2), a3), a4), a5), a6) cyl5 = Cylinder(magenta) i2 = Intersect(u3, cyl5) u4 = Union(cyl4, i2) u4.translate(0.0, 3.5, 0.0) d = Difference(cyl3, u4) d.translate(0.0, -4.0, 2.0) d.uscale(4.0) d.rotatex(-50) return d, l d1 = Difference(u2, u4) #d1.uscale(0.4) d1.translate(0.0, -3.0, 2.0) d1.rotatex(-50) return d1, l
def scene_sphere(): def blue(face, u, v): return (0.1, 0.1, 1.0), 0.3, 0.2, 6 l = [Light((1.0, -1.0, 1.0), (1.0, 1.0, 1.0))] s = Sphere(blue) return s, l
def scene_plane(): def yellow(face, u, v): return (0.1, 1.0, 1.0), 0.3, 0.2, 6 l = [Light((1.0, -1.0, 1.0), (1.0, 1.0, 1.0))] p = Plane(yellow) p.translate(0.0, -4.0, 0.0) return p, l
def index(secret): """Makes a list of the lights on the page, and excludes my space heater""" if not access(request.url, secret, "Besøkte siden"): return "No." lights = Light.get_lights() sophie_lights = [] for light in lights: if 'Sophie' in light.name and not 'Panel' in light.name: sophie_lights.append(light) return render_template("index.html", lights=sophie_lights, prefix=secret)
def scene_cone(): def green(face, u, v): return (0.1, 1.0, 0.1), 0.3, 0.2, 6 l = [Light((1.0, -1.0, 1.0), (1.0, 1.0, 1.0))] c = Cone(green) c.translate(0.0, -0.5, 0.0) c.scale(2.0, 4.0, 2.0) #c.rotatex(90.0) return c, l
def scene_cylinder(): def green(face, u, v): return (0.1, 1.0, 0.1), 0.3, 0.2, 6 l = [Light((1.0, -1.0, 1.0), (1.0, 1.0, 1.0))] c = Cylinder(green) c.translate(0.0, -0.5, 0.0) c.rotatex(60.0) c.rotatey(20.0) c.rotatez(40.0) return c, l
def scene_cube(): def red(face, u, v): return (1.0, 0.1, 0.1), 0.3, 0.2, 6 l = [Light((1.0, -1.0, 1.0), (1.0, 1.0, 1.0))] c = Cube(red) c.translate(-0.5, -0.5, -0.5) c.rotatex(10.0) c.rotatey(20.0) c.rotatez(30.0) return c, l
def light_set(secret): """Turn on or off a specific light""" if not access(request.url, secret): return "No." Light.refresh() user = access(request.url, secret) if not user: return "No." tell_sophie(f"{user} så status på lys") target_light = request.args.get("target_light") target_status = str( request.args.get("target_status")).lower() in ["on", "true"] light = Light.find_light(target_light) if light: tell_sophie(f"{user}: satt {target_light} til {target_status}") light.set_state(target_status) return "Skrudde lyset på" if target_status else "Skrudde lyset av" return "Fant ikke lyset."
def scene_intersect(): def blue(face, u, v): return (0.1, 0.1, 1.0), 0.3, 0.2, 6 def red(face, u, v): return (1.0, 0.1, 0.1), 0.3, 0.2, 6 l = [Light((1.0, -1.0, 1.0), (1.0, 1.0, 1.0))] s1 = Sphere(blue) s1.translate(-0.6, 0.0, 0.0) s2 = Sphere(red) s2.translate(0.6, 0.0, 0.0) i = Intersect(s1, s2) return i, l
def scene_union(): def blue(face, u, v): return (0.1, 0.1, 1.0), 0.3, 0.2, 6 def red(face, u, v): return (1.0, 0.1, 0.1), 0.3, 0.2, 6 l = [Light((1.0, -1.0, 1.0), (1.0, 1.0, 1.0))] s1 = Sphere(blue) s1.translate(-0.6, 0.0, 0.0) s2 = Sphere(red) s2.translate(0.6, 0.0, 0.0) u = Union(s1, s2) return u, l
def scene_texsphere(): def pattern(face, u, v): up = int(u * 24) % 2 vp = int(v * 12) % 2 r, g, b = 0.0, 0.1, 0.0 if up == 0: r = u if vp == 0: b = v return (r, g, b), 0.3, 0.2, 6 l = [Light((1.0, -1.0, 1.0), (1.0, 1.0, 1.0))] s = Sphere(pattern) return s, l
def scene_texplane(): def pattern(face, u, v): up = int(u * 6) % 2 vp = int(v * 6) % 2 r, g, b = 0.0, 0.1, 0.0 if up == 0: r = (u % 1.0) if vp == 0: b = (v % 1.0) return (r, g, b), 0.3, 0.2, 6 l = [Light((1.0, -1.0, 1.0), (1.0, 1.0, 1.0))] p = Plane(pattern) p.translate(0.0, -4.0, 0.0) return p, l
def __init__(self, args, HOST = '', PORT = 57000, LIGHT_IP ='192.168.0.87'): vc_logging.init_logger(level = args.log_level, verbose = args.verbose) self.log = logging.getLogger("vc_logger") self.HOST = HOST self.PORT = PORT self.args = args self.color = { 'red' : 0, 'yellow' : 14000, 'green' : 25500, 'white' : 35000, 'blue' : 47000, 'pink' : 56100 } self.lights = [Light(i,LIGHT_IP) for i in range(1,4)]
def scene_difference2(): def blue(face, u, v): return (0.1, 0.1, 1.0), 0.3, 0.2, 6 def red(face, u, v): return (1.0, 0.1, 0.1), 0.3, 0.2, 6 l = [Light((1.0, -1.0, 1.0), (1.0, 1.0, 1.0))] c1 = Sphere(blue) c2 = Cylinder(red) c2.translate(0.0, -0.5, 0.0) c2.scale(0.4, 2.0, 0.4) d = Difference(c1, c2) d.rotatex(85.0) d.rotatey(20.0) d.rotatez(40.0) return d, l
def scene_texcone(): def pattern(face, u, v): up = int(u * 24) % 2 vp = int(v * 12) % 2 r, g, b = 0.0, 0.1, 0.0 if up == 0: r = u if vp == 0: b = v return (r, g, b), 0.3, 0.2, 6 l = [Light((1.0, -1.0, 1.0), (1.0, 1.0, 1.0))] c = Cone(pattern) c.translate(0.0, -0.5, 0.0) c.scale(2.0, 4.0, 2.0) #c.rotatex(90.0) return c, l
def scene_texcube(): def pattern(face, u, v): up = int(u * 6) % 2 vp = int(v * 6) % 2 r, g, b = 0.0, 0.1, 0.0 if up == 0: r = (u % 1.0) if vp == 0: b = (v % 1.0) return (r, g, b), 0.3, 0.2, 6 l = [Light((1.0, -1.0, 1.0), (1.0, 1.0, 1.0))] c = Cube(pattern) c.translate(-0.5, -0.5, -0.5) c.rotatex(10.0) c.rotatey(20.0) c.rotatez(30.0) return c, l
def scene_texcylinder(): def pattern(face, u, v): up = int(u * 24) % 2 vp = int(v * 12) % 2 r, g, b = 0.0, 0.1, 0.0 if up == 0: r = u if vp == 0: b = v return (r, g, b), 0.3, 0.2, 6 l = [Light((1.0, -1.0, 1.0), (1.0, 1.0, 1.0))] c = Cylinder(pattern) c.translate(0.0, -0.5, 0.0) c.rotatex(60.0) c.rotatey(20.0) c.rotatez(40.0) return c, l
def scene_difference3(): def blue(face, u, v): return (0.1, 0.1, 1.0), 0.3, 0.2, 6 def red(face, u, v): return (1.0, 0.1, 0.1), 0.3, 0.2, 6 l = [Light((1.0, -1.0, 1.0), (1.0, 1.0, 1.0))] c1 = Cone(blue) c1.translate(0.0, -0.5, 0.0) c1.scale(1.0, 3.0, 1.0) c2 = Cube(red) c2.translate(-0.5, 1.0, -0.5) c3 = Cube(red) c3.translate(-0.5, -1.5, -0.5) u = Union(c2, c3) d = Difference(c1, u) d.rotatex(85.0) d.rotatey(20.0) d.rotatez(40.0) return d, l
def __init__(self): self.light = Light() self._get_shadow_client()
import time import os from colors import CIE from colors.animations import ColorAnimation from colors.frames import ColorFrame from lights import Light logging.basicConfig() log = logging.getLogger(__name__) log.setLevel(logging.DEBUG) KEY = os.environ.get('KEY') IP = os.environ.get('IP') lights = [Light(id=9), Light(id=10), Light(id=11), Light(id=21)] fire_profile = ColorAnimation(rate_s=0.8, frames=[ ColorFrame(color=CIE(x=0.70, y=0.29), light=lights[0]), ColorFrame(color=CIE(x=0.65, y=0.35), light=lights[1]), ColorFrame(color=CIE(x=0.62, y=0.30), light=lights[2]), ColorFrame(color=CIE(x=0.60, y=0.35), light=lights[3]), ColorFrame(color=CIE(x=0.70, y=0.29), light=lights[1]), ColorFrame(color=CIE(x=0.65, y=0.35), light=lights[2]), ColorFrame(color=CIE(x=0.62, y=0.30),
import asyncio import functools from lights import Light from datetime import datetime import os from poll_events import poll_event tv = Light(12) lamp = Light(1) async def periodic(loop, period): prev_time = datetime.now() while True: print('running periodic @', datetime.now()) # loop.create_task(tv.party(seconds = 5, count = 8)) # loop.create_task(lamp.party(seconds = 2, count = 8)) loop.create_task(poll_event(loop, prev_time)) prev_time = datetime.now() await asyncio.sleep(period) async def exit(): loop = asyncio.get_event_loop() print("Stop") loop.stop()
from time import sleep from datetime import datetime, timedelta from people import Person import os datasource = f'{os.environ["GOOGLE_SHEET_KEY"]}' # dictionary to store current status person_status = {'Zaks-iPhone': None, 'Louise’s iPhone': None} sheet = Sheet(datasource) lights = LightSet() for i in range(1, 13): lights.add_light(i, Light(i)) # louise = Person('Louise') # zak = Person('Zak') previous_index = None async def poll_event(loop, prev_datetime): global previous_index records_since = sheet.get_records_since_index(previous_index) if (len(records_since) == 0): return
class MyPaintingMQTTClient(): """ Client to maintain a connection between the Raspberry Pi and the IoT Shadow. Updates LED lights through a Light object. """ def __init__(self): self.light = Light() self._get_shadow_client() def _get_shadow_client(self): """ Creates, configures, and sets AWSIoTMQTTClient to communicate with AWS IoT Thing. Args: None Returns: AWSIoTMQTTClient """ self.shadowClient = AWSIoTMQTTClient(clientId) self.shadowClient.configureEndpoint(host, port) self.shadowClient.configureCredentials(rootCAPath, privateKeyPath, certificatePath) self.shadowClient.configureAutoReconnectBackoffTime(1, 32, 20) self.shadowClient.configureConnectDisconnectTimeout(10) self.shadowClient.configureMQTTOperationTimeout(1) return self.shadowClient def _subscribe_update_callback(self, client, userdata, message): """ Callback after subscribe to update documents topic. Retrieves the payload from the MQTTMessage and checks if Light object needs to be updated. If Lights object needs to be updated, updates the lights and sends an update to the IoT shadow. Will except ValueError and exceptions and log if payload is missing. Client and Userdata may be deprecated in the future. Args: client: string userdata: string message: MQTTMessage instance """ logger.info('Message recieved from {} topic'.format(message.topic)) payload = message.payload try: payload_dict = json.loads(payload) light_data = payload_dict['current']['state']['desired'] if self.light.needs_updating(light_data): self.light.update_lights(light_data) reported_payload = { 'state': { 'reported': self.light.current_settings() } } JSON_payload = json.dumps(reported_payload) self.shadowClient.publish(update_topic, JSON_payload, 0) except ValueError: logger.error('Value error') logger.info(payload) except Exception as e: logger.error(e.message) def run_app(self, set_desired_state=False): """ Connects to IoT Shadow through MQTT connection. Updates state of shadow with current light settings to update topic. Subscribes to update/documents topic of thing shadow from update/documents topic and handles callback with _subscribe_update_callback. Args: set_desired: boolean to send update to desired state """ self.shadowClient.connect() start_payload = { 'state': { 'reported': self.light.current_settings(), 'desired': self.light.current_settings() } } JSON_payload = json.dumps(start_payload) self.shadowClient.publish(update_topic, JSON_payload, 0) self.shadowClient.subscribe(update_docs_topic, 1, self._subscribe_update_callback) while True: pass