Ejemplo n.º 1
0
def projector(request, id):
	projector = get_object_or_404(Projector, pk=id)
	controller = PJLinkController(projector.pjlink_host, projector.pjlink_port, projector.pjlink_password)
	try:
		if request.method == 'POST':
			new_event_form = ProjectorEventForm(request.POST)
			if request.POST.get('power', None) == PJLinkProtocol.POWER_ON_STATUS:
				controller.power_on()
				new_event_form = ProjectorEventForm(initial={ 'device':projector.id })
			elif request.POST.get('power', None) == PJLinkProtocol.POWER_OFF_STATUS:
				controller.power_off()
				new_event_form = ProjectorEventForm(initial={ 'device':projector.id })
			elif request.POST.get('action', None) == 'delete' and request.POST.get('event_id', None):
				event = ProjectorEvent.objects.get(pk=int(request.POST.get('event_id', None)))
				event.delete()
				new_event_form = ProjectorEventForm(initial={ 'device':projector.id })
			elif new_event_form.is_valid():
				new_event_form.save()
				new_event_form = ProjectorEventForm(initial={ 'device':projector.id })
		else:
			new_event_form = ProjectorEventForm(initial={ 'device':projector.id })
			
		audio_mute, video_mute = controller.query_mute()
		info = ProjectorInfo(controller.query_power(), controller.query_name(), controller.query_manufacture_name(), controller.query_product_name(), controller.query_other_info(), audio_mute, video_mute)
		for lamp in controller.query_lamps(): info.lamps.append(LampInfo(lamp[0], lamp[1]))
	except:
		logging.exception('Could not communicate with the projector')
		info = None

	return render_to_response('lighting/projector.html', { 'events':ProjectorEvent.objects.filter(device=projector), 'new_event_form':new_event_form, 'projector':projector, 'projector_info':info }, context_instance=RequestContext(request))
Ejemplo n.º 2
0
    def execute(self):
        print 'running ', self
        try:
            controller = PJLinkController(host=self.device.pjlink_host,
                                          port=self.device.pjlink_port,
                                          password=self.device.pjlink_password)
            if self.command == 'on':
                controller.power_on()
            elif self.command == 'off':
                controller.power_off()
            else:
                self.tries = self.tries + 1
                self.save()
                return False
            print 'ran command', self.command
        except:
            traceback.print_exc()
            self.tries = self.tries + 1
            self.save()
            return False

        self.last_run = datetime.datetime.now()
        self.tries = 1
        self.save()
        return True
Ejemplo n.º 3
0
def projector_info(request, id):
	projector = get_object_or_404(Projector, pk=id)
	controller = PJLinkController(projector.pjlink_host, projector.pjlink_port, projector.pjlink_password)
	try:
		if request.REQUEST.get('power', None) == PJLinkProtocol.POWER_ON_STATUS:
			controller.power_on()
		elif request.REQUEST.get('power', None) == PJLinkProtocol.POWER_OFF_STATUS:
			controller.power_off()

		if request.REQUEST.get('mute', None) == PJLinkProtocol.ON:
			controller.set_mute(PJLinkProtocol.VIDEO_MUTE_ON)
		elif request.REQUEST.get('mute', None) == PJLinkProtocol.OFF:
			controller.set_mute(PJLinkProtocol.VIDEO_MUTE_OFF)
	except:
		logging.exception('Could not control the projector')
	audio_mute, video_mute = controller.query_mute()
	info = ProjectorInfo(controller.query_power(), controller.query_name(), controller.query_manufacture_name(), controller.query_product_name(), controller.query_other_info(), audio_mute, video_mute)
	for lamp in controller.query_lamps():
		info.lamps.append(LampInfo(lamp[0], lamp[1]))
	return HttpResponse(dehydrate_to_xml(info), content_type="text/xml")
Ejemplo n.º 4
0
def projector_info(request, id):
    projector = get_object_or_404(Projector, pk=id)
    controller = PJLinkController(projector.pjlink_host, projector.pjlink_port,
                                  projector.pjlink_password)
    try:
        if request.REQUEST.get('power',
                               None) == PJLinkProtocol.POWER_ON_STATUS:
            controller.power_on()
        elif request.REQUEST.get('power',
                                 None) == PJLinkProtocol.POWER_OFF_STATUS:
            controller.power_off()

        if request.REQUEST.get('mute', None) == PJLinkProtocol.ON:
            controller.set_mute(PJLinkProtocol.VIDEO_MUTE_ON)
        elif request.REQUEST.get('mute', None) == PJLinkProtocol.OFF:
            controller.set_mute(PJLinkProtocol.VIDEO_MUTE_OFF)
    except:
        logging.exception('Could not control the projector')
    audio_mute, video_mute = controller.query_mute()
    info = ProjectorInfo(controller.query_power(), controller.query_name(),
                         controller.query_manufacture_name(),
                         controller.query_product_name(),
                         controller.query_other_info(), audio_mute, video_mute)
    for lamp in controller.query_lamps():
        info.lamps.append(LampInfo(lamp[0], lamp[1]))
    return HttpResponse(dehydrate_to_xml(info), content_type="text/xml")
Ejemplo n.º 5
0
def projector(request, id):
    projector = get_object_or_404(Projector, pk=id)
    controller = PJLinkController(projector.pjlink_host, projector.pjlink_port,
                                  projector.pjlink_password)
    try:
        if request.method == 'POST':
            new_event_form = ProjectorEventForm(request.POST)
            if request.POST.get('power',
                                None) == PJLinkProtocol.POWER_ON_STATUS:
                controller.power_on()
                new_event_form = ProjectorEventForm(
                    initial={'device': projector.id})
            elif request.POST.get('power',
                                  None) == PJLinkProtocol.POWER_OFF_STATUS:
                controller.power_off()
                new_event_form = ProjectorEventForm(
                    initial={'device': projector.id})
            elif request.POST.get('action',
                                  None) == 'delete' and request.POST.get(
                                      'event_id', None):
                event = ProjectorEvent.objects.get(
                    pk=int(request.POST.get('event_id', None)))
                event.delete()
                new_event_form = ProjectorEventForm(
                    initial={'device': projector.id})
            elif new_event_form.is_valid():
                new_event_form.save()
                new_event_form = ProjectorEventForm(
                    initial={'device': projector.id})
        else:
            new_event_form = ProjectorEventForm(
                initial={'device': projector.id})

        audio_mute, video_mute = controller.query_mute()
        info = ProjectorInfo(controller.query_power(), controller.query_name(),
                             controller.query_manufacture_name(),
                             controller.query_product_name(),
                             controller.query_other_info(), audio_mute,
                             video_mute)
        for lamp in controller.query_lamps():
            info.lamps.append(LampInfo(lamp[0], lamp[1]))
    except:
        logging.exception('Could not communicate with the projector')
        info = None

    return render_to_response(
        'lighting/projector.html', {
            'events': ProjectorEvent.objects.filter(device=projector),
            'new_event_form': new_event_form,
            'projector': projector,
            'projector_info': info
        },
        context_instance=RequestContext(request))
Ejemplo n.º 6
0
def main():
    try:
        action = sys.argv[1]
    except IndexError:
        print USAGE_MESSAGE
        return
    if action == 'name':
        controller = PJLinkController(host=sys.argv[2], password=sys.argv[3])
        print controller.query_name()
    elif action == 'off':
        controller = PJLinkController(host=sys.argv[2], password=sys.argv[3])
        controller.power_off()
    elif action == 'on':
        controller = PJLinkController(host=sys.argv[2], password=sys.argv[3])
        controller.power_on()
    elif action == 'status':
        controller = PJLinkController(host=sys.argv[2], password=sys.argv[3])
        print controller.query_power()
    elif action == 'mute':
        controller = PJLinkController(host=sys.argv[2], password=sys.argv[3])
        print controller.set_mute(PJLinkProtocol.VIDEO_MUTE_ON)
    elif action == 'unmute':
        controller = PJLinkController(host=sys.argv[2], password=sys.argv[3])
        print controller.set_mute(PJLinkProtocol.VIDEO_MUTE_OFF)
    elif action == 'mute-status':
        controller = PJLinkController(host=sys.argv[2], password=sys.argv[3])
        print "(audio is muted, video is muted): (%s, %s)"  % controller.query_mute()
    elif action == 'projector':
        projector = MockPJLinkProjector()
        projector.port = 4352
        projector.start()
        seconds_to_wait = 5
        while projector.running == False and seconds_to_wait > 0:
            time.sleep(1)
            seconds_to_wait -= 1
        if not projector.running:
            print 'Could not start the projector'
            return
        print 'Projector running: %s:%s' % (projector.server.getsockname()[0], projector.server.getsockname()[1])
        while True: time.sleep(100)
    else:
        print USAGE_MESSAGE
        return