예제 #1
0
void switch_server() {
    server_tid = MyTid();

    switches_init();

    // Find the location server.
    tid_t location_server_tid = -2;
    do {
        location_server_tid = WhoIs("LocationServer");
        dlog("Location Server Tid %d\n", location_server_tid);
    } while (location_server_tid < 0);

    tid_t tid;
    SwitchServerMessage msg, reply;
    while (1) {
        Receive(&tid, (char *) &msg, sizeof(msg));
        switch (msg.type) {
        case SET_SWITCH:
            reply.type = SET_SWITCH_RESPONSE;
            Reply(tid, (char *) &reply, sizeof(reply));
            switch_set(msg.switch_no, msg.direction, location_server_tid);
            break;
        default:
            break;
        }
    }
}
예제 #2
0
int main(void)
{
    adc_init();

    spi_init();

    switches_init();
    encoders_init();

    for (;;)
    {
        // Check the SS pin, if it is low, send the data through SPI.
        if (spi_slave_selected())
        {
            spi_enable();
            for (uint8_t i=0; i<ENCODER_COUNT; ++i)
            {
                spi_transfer16(g_encoderValues[i]);
            }
            spi_transfer8(g_downMask);
            spi_disable();
        }

        switches_update();
        encoders_update();
    }
}
예제 #3
0
int main(void)
{
    unsigned int switchPressed;

    debug_init(SOFTWARE_NAME);

    PIO_InitializeInterrupts(AT91C_AIC_PRIOR_LOWEST);
    switches_init();
    char_display_init();
    LED_Configure(0);
    LED_Configure(1);

    if (! BCAN_Init(1000, 0, NULL)) {
        printf("INIT FAIL");
        LED_Set(1);
        return 1;
    }

    printf("INIT OK\n\r");
    LED_Set(0);

    BCAN_InitMailboxRegisters( 0, 1, 0x0, (0x5AC << 18), AT91C_CAN_MOT_TX, 0x0);

    while(1) {
        DisplayMenu();

        switchPressed = -1;
        while (switchPressed == -1) {
            if (switches_pressed(0)) {
                TRACE_INFO("Switch 0 is pressed\n\r");
                switchPressed = 0;
            } else if (switches_pressed(1)) {
                TRACE_INFO("Switch 1 is pressed\n\r");
                switchPressed = 1;
            } else if (switches_pressed(2)) {
                TRACE_INFO("Switch 2 is pressed\n\r");
                switchPressed = 2;
            } else if (switches_pressed(3)) {
                TRACE_INFO("Switch 3 is pressed\n\r");
                switchPressed = 3;
            } else {
                //TRACE_INFO("No Switch is pressed\n\r");
            }
            char_display_tick();
            for (volatile unsigned int i = 0xFF; i > 0; i--) ;
        }

        unsigned int result = -1;
        while (result != CAN_STATUS_SUCCESS) {
            result = BCAN_Write(0, 1, 0, switchPressed, 0x1);
        }
        char_display_number(switchPressed);
    }

    return 0;
}
예제 #4
0
파일: main.c 프로젝트: edwkar/TDT4258
static int __init init_switches_dev(void)
{
    switches_init();

    cdev_init(&switches_cdev, &switches_fops);
    switches_cdev.owner = THIS_MODULE;
    if (cdev_add(&switches_cdev, dev_num, 1) < 0) {
        printk(KERN_ALERT "*** cdev_add for switches device failed ***\n");
        return -1;
    }

    return 0;
}
예제 #5
0
//Runs a test of the switches
//switches_read() will run until all switches are in the UP position.
//Masking is used to determine which switches are in the UP position.
//When all switches are on the on position, the LED's are turned off.
void switches_runTest()
{
    switches_init();
    u32 read = switches_read();
    while(read  != HEX_F)
    {
        read = switches_read();
        char result = read & HEX_F;
        leds_write(result);
    }
    leds_write(0);

}
예제 #6
0
파일: switches.c 프로젝트: FoxxGuthy/CS-236
void switches_runTest()
{
    //initialize the LEDS
    leds_init(0);

    //initalize the switches, aka turn off tristate
    switches_init();


    int32_t switchValue = 0;

    //while not all the swtiches are up, continue to test
    //we mask the switchValue with all switches so we just see those bits
    while ((switchValue & SWITCHES_ALL_SWITCHES_ON) != SWITCHES_ALL_SWITCHES_ON)
    {
        switchValue = switches_read();
        //if switch0, led 0 on
        if ((switchValue & SWITCHES_SW0) == SWITCHES_SW0)
        {
            leds_write(SWITCHES_SW0); // this might cause problem, because it specifically turns off the other LEDS
        }
        //if switch1, led 1 on
        if ((switchValue & SWITCHES_SW1) == SWITCHES_SW1)
        {
            leds_write(SWITCHES_SW1); // this might cause problem, because it specifically turns off the other LEDS
        }
            //if switch2, led 2 on
        if ((switchValue & SWITCHES_SW2) == SWITCHES_SW2)
        {
            leds_write(SWITCHES_SW2); // this might cause problem, because it specifically turns off the other LEDS
        }
            //if switch3, led 3 on
        if ((switchValue & SWITCHES_SW3) == SWITCHES_SW3)
        {
            leds_write(SWITCHES_SW3); // this might cause problem, because it specifically turns off the other LEDS
        }
        else //no LEDS on
        {
            //when we put a switch down, turn off that LED
            leds_write(0);
        }
    }
    //turn off all LEDS, test is over
    leds_write(0);
}