Esempio n. 1
0
void main(void)
{
	init();

	// for testing
	set_brightness(LED1, 2);
	set_led_pulse(LED2, 1);
	//set_brightness(LED2, 50);
	//set_brightness(LED3, 100);
	uint8_t keyup = 0, keydown = 0;
	while (1)
	{
		keydown = getKeyDown();
		if (keydown)
		{
			if (keydown & _BV(BUTTON1))
				set_brightness(LED3, 100);
			else if (keydown & _BV(BUTTON2))
				set_brightness(LED3, 60);
			else if (keydown & _BV(BUTTON3))
				dim_led(LED3, 90);
			else if (keydown & _BV(BUTTON4))
				dim_led(LED3, 0);
			else if (keydown & _BV(BUTTON5))
				set_brightness(LED3, 0);
		}
		keyup = getKeyUp();
		if (keyup)
		{
			if (keyup & _BV(BUTTON2))
				set_brightness(LED3, 0);
		}
	}
}
Esempio n. 2
0
static void enter_sleep_mode(void)
{
    bool_t wakeUp = bFalse;
    uint16_t i = 4;

    // Turn off GFX and backlight
    set_brightness(0);

    // Disable touch notification
    touch_set_event_handler(NULL);

    do
    {
        // Enable watchdog
        _SWDTEN = 1;

        // Enter idle
        Sleep();

        // Watchdog should wakeup MCU after one second
        // See hal/mcu/mcu_config.c

         // Disable WDT
        _SWDTEN = 0;

        // AFTER ANY INTERRUPT REQUEST:
        // Wait
        delay_ms(100);

        // Touch panel pressed over 2 seconds?
        if(RV_OK == touch_process())
        {
            wakeUp = bTrue;
            while(i--)
            {
                delay_ms(500);
                if(RV_OK != touch_process())
                {
                    wakeUp = bFalse;
                }
            }
        }

        // Clean up message queue
        knl_mailbox_init(&taskMailbox);
    } while(!wakeUp);

    //
    // Wake up
    //

    // Restore kernel handlers
    install_event_handlers();

    // Re-enable GFX and backlight
    set_brightness(lightenBrightness);

    gui_invalidate_all();
    // DONE!
}
Esempio n. 3
0
File: lsc.c Progetto: wcheswick/ex
void
kbd_hit(char key) {
	set_active();
	switch (key) {
	case 'd':
		dump_screen(0);
		break;
	case 'w':
	case 'W':
		save_image();
		break;
	case 'q':
	case 'Q':
	case 'x':
	case 'X':	/* exit the program */
		end_display();
		exit(0);
	case 'v':
		show_video_settings = !show_video_settings;
		refresh_screen = 1;
		break;
	case 'h':
		set_hue(get_hue() - 1);
		refresh_screen = 1;
		break;
	case 'H':
		set_hue(get_hue() + 1);
		refresh_screen = 1;
		break;
	case 's':
		set_saturation(get_saturation() - 1);
		refresh_screen = 1;
		break;
	case 'S':
		set_saturation(get_saturation() + 1);
		refresh_screen = 1;
		break;
	case 'b':
		set_brightness(get_brightness() - 1);
		refresh_screen = 1;
		break;
	case 'B':
		set_brightness(get_brightness() + 1);
		refresh_screen = 1;
		break;
	case 'c':
		set_contrast(get_contrast() - 1);
		refresh_screen = 1;
		break;
	case 'C':
		set_contrast(get_contrast() + 1);
		refresh_screen = 1;
		break;
	}
}
Esempio n. 4
0
void on_pulse(void){
	MSS_GPIO_clear_irq(gpio_i_i);
	if(pulse_direction == BRIGHTER) {
		if(master_brightness < full_brightness)
			set_brightness(master_brightness+1);
		else
			pulse_direction = DIMMER;
	} else {
		if(master_brightness > min_brightness)
			set_brightness(master_brightness-1);
		else
			pulse_direction = BRIGHTER;
	}
}
Esempio n. 5
0
void CEZX::fadeout_screen(int duration) {
	if (current_br == normal_br) {
		int fade_steps = FADE_STEPS,
			tm = duration/fade_steps;
		if (fade_steps > normal_br) fade_steps = normal_br;
		for (float i=current_br; i>=MIN_BRIGHTNESS; i-=(float)normal_br/fade_steps) {
			set_brightness((int)round(i));
			usleep(tm*1000);
		}
	} else {
		set_brightness(0);
	}
	backlight(false);
	keyslight(false);
}
Esempio n. 6
0
void CEZX::fadein_screen(int duration) {
	keyslight(true);
	backlight(true);
	if (current_br < normal_br) {
		int fade_steps = FADE_STEPS,
			tm = duration/fade_steps;
		if (fade_steps > normal_br) fade_steps = normal_br;
		for (float i=current_br; i<=normal_br; i+=(float)normal_br/fade_steps) {
			set_brightness((int)round(i));
			usleep(tm*1000);
		}
	} else {
		set_brightness(normal_br);
	}
}
Esempio n. 7
0
static void brightness_work(struct work_struct *work)
{
	int ret;

	/* Don't set backlight if it's already powered off */
	if (backlight_device->props.power == 4 &&
	    backlight_device->props.brightness == 0) {
		pr_info("mba6x_bl: skipping to set backlight since it's already off\n");
		return;
	}

	ret = set_brightness(backlight_device->props.brightness);

	/* Warn but reschedule even if we failed */
	if (ret)
		pr_debug("mba6x_bl: failed to set brightness\n");

	if (backlight_device->props.brightness == 0)
		backlight_device->props.power = 4;
	else
		backlight_device->props.power = 0;

	/* Reschedule the next update */
	schedule_delayed_work(&dev_priv.work, 3 * HZ);
}
Esempio n. 8
0
static void v4l_picture_controls(struct context *cnt, struct video_dev *viddev)
{
    int dev = viddev->fd_bktr;

    if ((cnt->conf.contrast) && (cnt->conf.contrast != viddev->contrast)) { 
        set_contrast(dev, cnt->conf.contrast);
        viddev->contrast = cnt->conf.contrast;    
    }

    if ((cnt->conf.hue) && (cnt->conf.hue != viddev->hue)) {
        set_hue(dev, cnt->conf.hue);
        viddev->hue = cnt->conf.hue;    
    }

    if ((cnt->conf.brightness) && 
        (cnt->conf.brightness != viddev->brightness)) {
        set_brightness(dev, cnt->conf.brightness);
        viddev->brightness = cnt->conf.brightness; 
    }

    if ((cnt->conf.saturation) && 
        (cnt->conf.saturation != viddev->saturation)) {
        set_saturation(dev, cnt->conf.saturation);
        viddev->saturation = cnt->conf.saturation;
    }
}
Esempio n. 9
0
void bright_down(int event_value) {
	if (!max_brightness) bright_init();

	// If the button has been released, we simply close the BRIGHT_FILENAME file.
	if (event_value == 0) {
		fclose(dev_file);
		return;
	}

	// If the button has been pressed, update the current_value variable.
	else if (event_value == 1) {
		dev_file = fopen(BRIGHT_FILENAME, "r+");
		current_value = get_current_value(dev_file);
	}

	if (current_value == MIN_BRIGHTNESS)
	  return;

	else if (current_value - STEP_VALUE <= MIN_BRIGHTNESS)
	  current_value = MIN_BRIGHTNESS;

	else
	  current_value -= STEP_VALUE;

	set_brightness(dev_file, current_value);
}
Esempio n. 10
0
void display_init(uint8_t brightness)
{
	// outputs
	DATA_DDR  |= _BV(DATA_BIT);
	CLOCK_DDR |= _BV(CLOCK_BIT);
	LATCH_DDR |= _BV(LATCH_BIT);
	BLANK_DDR |= _BV(BLANK_BIT);

	// inputs
	SIGNATURE_DDR &= ~(_BV(SIGNATURE_BIT_0));
	SIGNATURE_DDR &= ~(_BV(SIGNATURE_BIT_1));
	SIGNATURE_DDR &= ~(_BV(SIGNATURE_BIT_2));
	
	// enable pullups for shield bits
	SIGNATURE_PORT |= _BV(SIGNATURE_BIT_0);
	SIGNATURE_PORT |= _BV(SIGNATURE_BIT_1);
	SIGNATURE_PORT |= _BV(SIGNATURE_BIT_2);

	LATCH_ENABLE;
	clear_display();

	detect_shield();

	// Inititalize timer for multiplexing
	TCCR0B |= (1<<CS01); // Set Prescaler to clk/8 : 1 click = 1us. CS21=1
	TIMSK0 |= (1<<TOIE0); // Enable Overflow Interrupt Enable
	TCNT0 = 0; // Initialize counter
	
	set_brightness(brightness);
}
Esempio n. 11
0
int main(int argc, char* argv[]) {
    if (argc < 2) {
        fprintf(stderr, "Expected an argument specifying an increment\n");
        exit(1);
    }

    char* backend = getenv(ENV_BRIGHTNESS_BACKEND);
    if (!backend) {
        backend = DEFAULT_BACKEND;
    }

    int current_brightness = get_brightness(backend, "brightness");
    int max_brightness = get_brightness(backend, "max_brightness");

    char c = argv[1][0];
    double increment = atof(argv[1]) / 100 * max_brightness + 0.5;
    int brightness = c == '+' || c == '-' ?
        current_brightness + increment : increment;

    if (brightness < 0) brightness = 0;
    else if (brightness > max_brightness) brightness = max_brightness;
    double percent = 100.0 * brightness / max_brightness;

    set_brightness(backend, "brightness", brightness);

    printf("%.0f%%\n", percent);
    return 0;
}
void screen_brightness_animation_start(void)
{
    display_unblank();

    set_brightness(0.8);
    alarm_set_relative(screen_brightness_animation_alarm1, NULL, 5000);
    alarm_set_relative(animation_alarm, NULL, ANIMATION_TIMEOUT);
}
Esempio n. 13
0
/*----------------------------------------------------------------------------*/
void set_brightness_fade_out(void)
{
    if (bright_counter < 20)
    {
        bright_counter++;
        set_brightness(23 - bright_counter);
    }
}
Esempio n. 14
0
/* Set status of additional camera capabilities */
static int gc0329_s_ctrl(struct v4l2_subdev *sd, struct v4l2_control *ctrl)
{
	struct gc0329_priv *priv = to_gc0329(sd);
	struct i2c_client *client =
			(struct i2c_client *) v4l2_get_subdevdata(sd);

	switch (ctrl->id) {
	case V4L2_CID_VFLIP:
		priv->flag_vflip = ctrl->value;
		return set_flip(client, priv->flag_vflip);
		break;
	case V4L2_CID_HFLIP:
		priv->flag_hflip = ctrl->value;
		PDBG("set H-FLIP:%d\n", priv->flag_hflip);
		return set_mirror(client, priv->flag_hflip);
		break;
	case V4L2_CID_BRIGHTNESS:
		if (ctrl->value < -4 || ctrl->value > 4) {
			return -EINVAL;
		}
                priv->brightness = ctrl->value;
		return set_brightness(client, priv->brightness);
                break;
	case V4L2_CID_CONTRAST:
		if (ctrl->value < -3 || ctrl->value > 3) {
			return -EINVAL;
		}
                priv->contrast = ctrl->value;
		return set_contrast(client, priv->contrast);
                break;
	case V4L2_CID_SATURATION:
		if (ctrl->value < -3 || ctrl->value > 3) {
			return -EINVAL;
		}
                priv->sat = ctrl->value;
		return set_sat(client, priv->sat);
                break;
	case V4L2_CID_CAMERA_SPECIAL_EFFECT:
		if (ctrl->value < 0 || ctrl->value > 8) {
			return -EINVAL;
		}
                priv->effect = ctrl->value;
		return set_effect(client, priv->effect);
                break;
	case V4L2_CID_DO_WHITE_BALANCE:
		if (ctrl->value < 0 || ctrl->value > 4) {
			return -EINVAL;
		}
                priv->wh_bal = ctrl->value;
		return set_wh_bal(client, priv->wh_bal);
                break;
	default:
		return -EINVAL;
	}

	return 0;
}
Esempio n. 15
0
/*
 ** This code is based on the manpages on strtol. It removed an atoi() call
 ** and will just take 1 parameter. It will further check for the parameter
 ** to be within a certain range. If it does not match it will be set to the
 ** closest bound.
 */
int main(int argc, char *argv[])
{
        if (argc != 2) {
                fprintf(stderr, "Usage: %s str\n", argv[0]);
                exit(EXIT_FAILURE);
        }

        struct data *brgt = malloc(sizeof(struct data));
        memset(brgt, 0, sizeof(struct data));
        FILE *fp = fopen(path_val, "rb+");

        if (!fp) {
                perror("fopen failed");
                exit(EXIT_FAILURE);
        }

        FILE *fp2 = fopen(path_max_val, "rb");

        if (!fp2) {
                perror("fopen failed");
                exit(EXIT_FAILURE);
        }

        process_input(argv[1], brgt);
        long val = get_brightness(fp);
        long max_val = get_brightness(fp2);
        long min_val = 1; /* set to 1 for lcd-backlight */

        if (fclose(fp2)) {
                perror("fclose failed");
                exit(EXIT_FAILURE);
        }

        /* We have a relative value to set */
        if (brgt->sign) {
                brgt->brightness = val + brgt->brightness;
        }

        /* Check and set sensible bounds */
        if (brgt->brightness > max_val) {
                brgt->brightness = max_val;
        } else if (brgt->brightness < min_val) {
                brgt->brightness = min_val;
        }

        size_t write = set_brightness(fp, brgt->brightness);
        
        if (fclose(fp)) {
                perror("fclose failed");
                exit(EXIT_FAILURE);
        }

        free(brgt);

        exit(EXIT_SUCCESS);
}
Esempio n. 16
0
void processTWI( void )
{
	uint8_t b,p1,p2;

	b = usiTwiReceiveByte();

	switch (b) {
	case 0x81: // set slave address
		p1 = usiTwiReceiveByte();
		if(p1 < 128) // Address is 7 bit
		{
			eeprom_update_byte(&b_slave_address, p1);
			usiTwiSlaveInit(eeprom_read_byte(&b_slave_address));
		}
		break;
	case 0x82: // clear led
		led_clear();
		break;
	case 0x83: // set led brightness, p1=led, p2=brightness
		p1 = usiTwiReceiveByte();
		p2 = usiTwiReceiveByte();
		set_led_pulse(p1,0); // Turn off pulsing
		set_brightness(p1,p2);
		break;
	case 0x84: // Set to pulse led, p1=led, p2 = (0 = OFF, 1 = ON)
		set_led_pulse(usiTwiReceiveByte(),usiTwiReceiveByte());
		break;
	case 0x85: // Dim up/down led to specific value, p1=led, p2=value to dim to
		dim_led(usiTwiReceiveByte(),usiTwiReceiveByte());
		break;
	case 0x86: // get firmware revision
		usiTwiTransmitByte(FIRMWARE_REVISION);
		break;
	case 0x90: // get keyUp Event
		usiTwiTransmitByte(getKeyUp());
		break;
	case 0x91: // get KeyDown Event
		usiTwiTransmitByte(getKeyDown());
		break;
	case 0x92: // set keyrepeat
		set_keyrepeat(usiTwiReceiveByte(),usiTwiReceiveByte());
		break;
	case 0xFE: // reset to known state
		led_clear();
		button_init();
		flushTwiBuffers();
		break;
	case 0xFF: // flush the bus
		break;
	default:
		break;
	}
}
void screen_brightness_animation_alarm2(void *_)
{
    set_brightness(0.0);

    alarm_cancel(animation_alarm);

    if (shutdown)
    {
        ALOGD("power off after 5-10 display cycle!\n");
        reboot(RB_POWER_OFF);
    }
    display_blank();
}
Esempio n. 18
0
/* Start/Stop streaming from the device */
static int gc0309_s_stream(struct v4l2_subdev *sd, int enable)
{
    struct i2c_client *client = v4l2_get_subdevdata(sd);
    struct gc0309_priv *priv = to_gc0309(sd);
    int ret = 0;

    /* Program orientation register. */
    ret = set_flip(client, priv->flag_vflip);
    if (ret < 0)
        return ret;

    ret = set_brightness(client, priv->brightness);
    if (ret < 0)
        return ret;

    ret = set_contrast(client, priv->contrast);
    if (ret < 0)
        return ret;

    ret = set_sat(client, priv->sat);
    if (ret < 0)
        return ret;

    ret = set_effect(client, priv->effect);
    if (ret < 0)
        return ret;

    ret = set_wh_bal(client, priv->wh_bal);
    if (ret < 0)
        return ret;

    ret = set_mirror(client, priv->flag_hflip);
    if (ret < 0)
        return ret;

    if (enable) {
        PDBG("Enabling Streaming\n");
        /* Start Streaming */
        ret = gc0309_write(client, 0x25, 0x0f);
        if (ret)
            goto out;
        
    } else {
        PDBG( "Disabling Streaming\n");
        
        ret = gc0309_write(client, 0x25, 0x00);
    }

out:
    return ret;
}
Esempio n. 19
0
/* Start/Stop streaming from the device */
static int gc0329_s_stream(struct v4l2_subdev *sd, int enable)
{
	struct i2c_client *client = v4l2_get_subdevdata(sd);
	struct gc0329_priv *priv = to_gc0329(sd);
	int ret = 0;
	u8 val;

	/* Program orientation register. */
	ret = set_flip(client, priv->flag_vflip);
	if (ret < 0)
		return ret;

	ret = set_brightness(client, priv->brightness);
	if (ret < 0)
		return ret;

	ret = set_contrast(client, priv->contrast);
	if (ret < 0)
		return ret;

	ret = set_sat(client, priv->sat);
	if (ret < 0)
		return ret;

	ret = set_effect(client, priv->effect);
	if (ret < 0)
		return ret;

	ret = set_wh_bal(client, priv->wh_bal);
	if (ret < 0)
		return ret;

	ret = set_mirror(client, priv->flag_hflip);
	if (ret < 0)
		return ret;

	if (enable) {
		dev_dbg(&client->dev, "Enabling Streaming\n");
		/* Start Streaming */
	} else {
		dev_dbg(&client->dev, "Disabling Streaming\n");
	}



out:
	return ret;
}
Esempio n. 20
0
void init(void)
{
    cli();	// disable interrupts

    spiX_initslave(SPIMODE);
    set_brightness(eeprom_read_byte(&b_brightness));
    display_init(g_brightness);

    sei(); // enable interrupts


    /*
    // set up interrupt for alarm switch
    PCICR |= (1 << PCIE2);
    PCMSK2 |= (1 << PCINT18);
    */
}
Esempio n. 21
0
static int gc0311_s_stream(struct v4l2_subdev *sd, int enable)
{
    struct i2c_client *client = v4l2_get_subdevdata(sd);
    struct gc0311_priv *priv = to_gc0311(sd);
    int ret = 0;

    ret = set_flip(client, priv->flag_vflip);
    if (ret < 0)
        return ret;

    ret = set_brightness(client, priv->brightness);
    if (ret < 0)
        return ret;

    ret = set_contrast(client, priv->contrast);
    if (ret < 0)
        return ret;

    ret = set_sat(client, priv->sat);
    if (ret < 0)
        return ret;

    ret = set_effect(client, priv->effect);
    if (ret < 0)
        return ret;

    ret = set_wh_bal(client, priv->wh_bal);
    if (ret < 0)
        return ret;

    ret = set_mirror(client, priv->flag_hflip);
    if (ret < 0)
        return ret;

    if (enable) {
        ret = gc0311_write(client, 0x25, 0x0f);
        if (ret)
            goto out;
    } else {
        ret = gc0311_write(client, 0x25, 0x00);
    }

out:
    return ret;
}
Esempio n. 22
0
void CameraSettings::setup(MMAL_COMPONENT_T *camera_)
{
	camera = camera_;
	set_saturation(saturation);
	set_sharpness(sharpness);
	set_contrast(contrast);
	set_brightness(brightness);
	//set_ISO(ISO); TODO Not working for some reason
	set_video_stabilisation(videoStabilisation);
	set_exposure_compensation(exposureCompensation);
	set_exposure_mode(exposureMode);
	set_metering_mode(exposureMeterMode);
	set_awb_mode(awbMode);
	set_imageFX(imageEffect);
	set_colourFX(&colourEffects);
	//set_thumbnail_parameters(camera, &params->thumbnailConfig);  TODO Not working for some reason
	set_rotation(rotation);
	set_flips(hflip, vflip);
}
Esempio n. 23
0
static PyObject *
flea_set_brightness(PyObject *self, PyObject *args)
{
	int handle = -1;
	float brightness=0.0;
	fleaCamera* cam = NULL;

	if (!PyArg_ParseTuple(args, "if", &handle, &brightness))
		return NULL;

	if (handle >= 0 && handle < NUM_CAMERA_HANDLES && cameras[handle]) {
		cam = cameras[handle];
		set_brightness(cam, brightness);
	} else {
		PyErr_SetString(FleaError, "Invalid handle");
		return NULL;
	}

	Py_RETURN_NONE;
}
Esempio n. 24
0
void display_init(uint8_t brightness)
{
	// outputs
	DATA_DDR  |= _BV(DATA_BIT);
	CLOCK_DDR |= _BV(CLOCK_BIT);
	STROBE_DDR |= _BV(STROBE_BIT);
	BLANK_DDR |= _BV(BLANK_BIT);

	EXTRA1_DDR |= _BV(EXTRA1_BIT);
	EXTRA2_DDR |= _BV(EXTRA2_BIT);
	EXTRA1_LOW;
	EXTRA2_LOW;

	STROBE_LOW;
	BLANK_LOW;  // Unblank display

	clear_display();
	detect_shield();

// PD2 is Strobe
// PB2/OC0A is Blank (with 10k pullup)

// We use Timer0 for both the display multiplext interrupt
// and for PWM on OC0A for blanking

	// Inititalize Timer1 for multiplexing interrupt
//	TCCR1B = (1<<CS11); // Set Prescaler to clk/8 : 1 click = 1us. CS01=1 
//	TCCR1B = (1<<CS10); // Set Prescaler to clk/1 : 1 click = 1us. CS00=1 (8 bit timer)
//  TCCR1A |= _BV(WGM10); // Set TOP 0x00ff - makes Timer1 an 8 bit timer
//	TIMSK |= (1<<TOIE1); // Enable Overflow Interrupt
//	TCNT1 = 0;  // Initialize counter 

	// Inititalize Timer0 for PWM on PB2/OC0A (Blank)
	TCCR0B = (1<<CS00); // Set Prescaler to clk: 1 click = ???. CS00=1
  // fast PWM, 8 bit (TOP=0xff), clear OC0A (Blank pin) on match
  TCCR0A |= _BV(COM0A1) | _BV(WGM01) | _BV(WGM00);
	TIMSK |= (1<<TOIE0); // Enable Timer0 Overflow Interrupt for Strobe
	TCNT0 = 0; // Initialize counter
	
	set_brightness(10);
}
Esempio n. 25
0
int main(int argc, char *argv[])
{
    int bright = -1;
    
    switch(argc)
    {
        case 2:
        {
            int max = cat(MAX_FILE);
            int current = cat(CTL_FILE);

            printf("brightness: max %d, current %d", max, current);
            const char *method = argv[1];

            if (strcmp(method, "up") == 0 && current < max)
            {
                bright = current + 1;
            }
            else if(strcmp(method, "down") == 0 && current > 0)
            {
                bright = current - 1;
            }
            break;
        }
        default:
        {
            show_help();
            return -1;
        }
    }
    if(bright > -1)
    {
        printf(", set %d", bright);
        set_brightness(bright);
    }
    printf("\n");
    return 0;
}
Esempio n. 26
0
static bright_adjust(int event_value, int delta)
{
	int new_value;

	if (max_brightness == -1) {
		max_brightness_init();
		if (max_brightness == -1)
			return;
	}

	if (event_value == 0) { // key release
		dev_file_close();
		return;
	}

	if (event_value == 1) { // new key press (not a repeat)
		// Make sure we fetch an up-to-date value in the next step.
		dev_file_close();
		current_value = -1;
	}

	if (current_value == -1) {
		current_value = get_brightness();
		if (current_value == -1)
			return;
	}

	new_value = current_value + delta;
	if (new_value < MIN_BRIGHTNESS)
		new_value = MIN_BRIGHTNESS;
	else if (new_value > max_brightness)
		new_value = max_brightness;

	if (new_value != current_value) {
		current_value = new_value;
		set_brightness(current_value);
	}
}
Esempio n. 27
0
static void brightness_work(struct work_struct *work)
{
	int ret, i;

	/* Retry for a maximum of 2 seconds */
	for (i = 0; i < MAX_RETRIES; i++) {
		ret = set_brightness(backlight_device->props.brightness);
		if (!ret)
			break;
		msleep(100);
	}

	if (i >= MAX_RETRIES) {
		pr_info("mba6x_bl: failed to set brightness\n");
		return;
	} else if (i > 0) {
		pr_info("mba6x_bl: set brightness retries = %d\n", i);
	}

	if (backlight_device->props.brightness == 0)
		backlight_device->props.power = 4;
	else
		backlight_device->props.power = 0;
}
Esempio n. 28
0
File: lock.c Progetto: Yomin/neobox
int handler(struct neobox_event event, void *state)
{
    switch(event.type)
    {
    case NEOBOX_EVENT_CHAR:
        switch(event.value.c.c[0])
        {
        case 's':
            if(password)
            {
                neobox_text_password(ID_PASS, 0, NEOBOX_TEXT_PASSWORD_OFF, 1);
                neobox_button_set_name(ID_SHOW, 0, "hide", 1);
            }
            else
            {
                neobox_text_password(ID_PASS, 0, NEOBOX_TEXT_PASSWORD_ALLBUTONE, 1);
                neobox_button_set_name(ID_SHOW, 0, "show", 1);
            }
            password = !password;
            break;
        case 'u':
            if(!strcmp(pass, neobox_text_get(ID_PASS, 0)))
            {
                if(verbose)
                    printf("unlocked\n");
                neobox_text_reset(ID_PASS, 0, 1);
                if(!password)
                {
                    neobox_text_password(ID_PASS, 0, NEOBOX_TEXT_PASSWORD_ALLBUTONE, 1);
                    neobox_button_set_name(ID_SHOW, 0, "show", 1);
                }
                unlock();
            }
            else if(verbose)
                printf("wrong password\n");
            break;
        }
        return NEOBOX_HANDLER_SUCCESS;
    case NEOBOX_EVENT_BUTTON:
        switch(event.id)
        {
        case NEOBOX_BUTTON_POWER:
            if(!event.value.i)
                break;
            powersave = !powersave;
powersave:  if(neobox_lock(powersave))
                printf("Failed to %s screen\n", powersave?"lock":"unlock");
            set_brightness(!powersave);
            neobox_powersave(powersave);
            break;
        }
        return NEOBOX_HANDLER_SUCCESS;
    case NEOBOX_EVENT_SIGNAL:
        switch(event.value.i)
        {
        case SIGCHLD:
            wait(0);
            cmd_pid = -1;
            return NEOBOX_HANDLER_SUCCESS;
        case SIGHUP:
            goto powersave;
        }
    }
    
    return NEOBOX_HANDLER_DEFER;
}
Esempio n. 29
0
static int update_status(struct backlight_device *bd)
{
        set_brightness(bd->props.brightness);
        return 0;
}
Esempio n. 30
0
int main(void) {
  //  uint8_t i;
  uint8_t mcustate;

  // turn boost off
  TCCR0B = 0;
  BOOST_DDR |= _BV(BOOST);
  BOOST_PORT &= ~_BV(BOOST); // pull boost fet low

  // check if we were reset
  mcustate = MCUSR;
  MCUSR = 0;

  wdt_disable();
  // now turn it back on... 2 second time out
  //WDTCSR |= _BV(WDP0) | _BV(WDP1) | _BV(WDP2);
  //WDTCSR = _BV(WDE);
  wdt_enable(WDTO_2S);
  kickthedog();

  // we lost power at some point so lets alert the user
  // that the time may be wrong (the clock still works)
  timeunknown = 1;

  // have we read the time & date from eeprom?
  restored = 0;

  // setup uart
  uart_init(BRRL_192);
  //DEBUGP("VFD Clock");
  DEBUGP("!");

  //DEBUGP("turning on anacomp");
  // set up analog comparator
  ACSR = _BV(ACBG) | _BV(ACIE); // use bandgap, intr. on toggle!
  // settle!
  if (ACSR & _BV(ACO)) {
    // hmm we should not interrupt here
    ACSR |= _BV(ACI);

    // even in low power mode, we run the clock 
    DEBUGP("clock init");
    clock_init();  

  } else {
    // we aren't in low power mode so init stuff

    // init io's
    initbuttons();
    
    VFDSWITCH_PORT &= ~_BV(VFDSWITCH);
    
    DEBUGP("turning on buttons");
    // set up button interrupts
    DEBUGP("turning on alarmsw");
    // set off an interrupt if alarm is set or unset
    EICRA = _BV(ISC00);
    EIMSK = _BV(INT0);
  
    displaymode = SHOW_TIME;
    DEBUGP("vfd init");
    vfd_init();
   
    dimmer_init();
 
    DEBUGP("boost init");
    brightness_level = eeprom_read_byte((uint8_t *)EE_BRIGHT);
    boost_init(brightness_level);
    sei();

    region = eeprom_read_byte((uint8_t *)EE_REGION);
    
    DEBUGP("speaker init");
    speaker_init();

    beep(4000, 1);

    DEBUGP("clock init");
    clock_init();  

    DEBUGP("alarm init");
    setalarmstate();
  }
  DEBUGP("done");
  while (1) {
    //_delay_ms(100);
    kickthedog();
    //uart_putc_hex(ACSR);
    if (ACSR & _BV(ACO)) {
      // DEBUGP("SLEEPYTIME");
      gotosleep();
      continue;
    }
    //DEBUGP(".");
    if (just_pressed & 0x1) {
      just_pressed = 0;
      switch(displaymode) {
      case (SHOW_TIME):
	displaymode = SET_ALARM;
	display_str("set alarm");
	set_alarm();
	break;
      case (SET_ALARM):
	displaymode = SET_TIME;
	display_str("set time");
	set_time();
	timeunknown = 0;
	break;
      case (SET_TIME):
	displaymode = SET_DATE;
	display_str("set date");
	set_date();
	break;
      case (SET_DATE):
	displaymode = SET_BRIGHTNESS;
	display_str("set brit");
	set_brightness();
	break;
      case (SET_BRIGHTNESS):
	displaymode = SET_DIMMER;
	display_str("set dimr");
	set_dimmer();
	break;
      case (SET_DIMMER):
	displaymode = SET_VOLUME;
	display_str("set vol ");
	set_volume();
	break;
      case (SET_VOLUME):
	displaymode = SET_REGION;
	display_str("set regn");
	set_region();
	break;
	/*
      case (SET_REGION):
	displaymode = SET_SNOOZE;
	display_str("set snoz");
	set_snooze();
	break;
	*/
      default:
	displaymode = SHOW_TIME;
      }
    } else if ((just_pressed & 0x2) || (just_pressed & 0x4)) {
      just_pressed = 0;
      displaymode = NONE;
      display_date(DAY);

      kickthedog();
      delayms(1500);
      kickthedog();

      displaymode = SHOW_TIME;     
    } 
  }
}