int main() { init_malloc_wrapper(); lcd_t lcd; pin_t sclk = { .port = GPIO_PORT_C, .pin = 10 }; pin_t mosi = { .port = GPIO_PORT_C, .pin = 12 }; pin_t miso = { .port = GPIO_PORT_C, .pin = 11 }; pin_t cs = { .port = GPIO_PORT_C, .pin = 8 }; pin_t rs = { .port = GPIO_PORT_F, .pin = 12 }; pin_t rw = { .port = GPIO_PORT_F, .pin = 13 }; pin_t e = { .port = GPIO_PORT_C, .pin = 6 }; ssp_port_t ssp = { .ssp = ssp_port_3, .sclk = sclk, .mosi = mosi, .miso = miso}; if (!lcd_init(&lcd, ssp, cs, rs, rw, e)) { printf("Cannot initialize lcd"); return 0; } lcd_move_to(&lcd, 0, 0); lcd_print_string(&lcd, "Test"); while(1) { } return 0; }
void handle(struct test_type *test, int length) { int i=0; for( i = 0; i<length ;i++) { lcd_print_num(test[i].num); lcd_print_string(test[i].name); } }
void test_lcd() { //char string [] = {'h','e','l','l','o',' ','w','o','r','l','d','\0'}; //char string2 [] = {' ','c','r','a','f','t','e','r','s',' ','\0'}; lcd_print_string("helloworld! \n"); lcd_print_string("CRAFTER projects!\n"); //lcd_print_string(string2); //int test = 2013; //lcd_print_num(test); //int length = strlen(string); //int length2 = strlen(string2); //lcd_print_num(length); //lcd_print_num(length2); //lcd_print_string(" TUT"); }
void main(void) { //TRISB = 0; TRISBbits.TRISB4 = 0; uart_init(); ei(); delay_onesec_int(); LATBbits.LATB4=0; oneSecTick = 1; delay_onesec(); i2c_init(); lcd_init(); lcd_print_string((unsigned char*)"Sarbani i Ghosh"); /* * USB Setup */ uart_printline("\nSetting up usb"); usb_init(); while(1) { /* if (oneSecTick == 1) { oneSecTick = 0; LATBbits.LATB4 = 1 ^ PORTBbits.RB4; uart_printline((unsigned char*)"Ghosh\r\n"); lcd_init(); lcd_print_string((unsigned char*)"Sarbani i Ghosh"); i2c_start(); eep_write(0b10100010, 0x0000, 'b'); delayz(); eep_write(0b10100010, 0x0001, 'o'); delayz(); eep_write(0b10100010, 0x0002, 'u'); delayz(); unsigned char byte1 = eep_read(0b10100010, 0x0000); unsigned char byte2 = eep_read(0b10100010, 0x0001); unsigned char byte3 = eep_read(0b10100010, 0x0002); uart_printline("\r\n--\r\n"); uart_sendbyte(byte1); uart_sendbyte(byte2); uart_sendbyte(byte3); uart_printline("\r\n--\r\n"); } */ } }
int main() // Main function { while(1) // Main loop { distance = ping_cm(8); // Get cm distance from Ping))) if(distance>30){ int qtis = getQTIs(7, 4); // Check stripe position if(qtis == 0b1000) drive_speed(-64, 64); // Far left, rotate left if(qtis == 0b1100) drive_speed(0, 64); // Left, pivot left if(qtis == 0b0100) drive_speed(32, 64); // A little left, curve left if(qtis == 0b0110) drive_speed(64, 64); // Stripe centered, forward if(qtis == 0b0010) drive_speed(64, 32); // A little right, curve right if(qtis == 0b0011) drive_speed(64, 0); // Right, pivot right if(qtis == 0b0001) drive_speed(64, -64); // Far right, rotate right if(qtis == 0b1111) drive_speed(0, 0); lcd_print_string("station reached"); } } }
void test_getpid() { lcd_print_string("testpid"); int pid = getpid(); lcd_print_num(pid); }
int main(int argc, const char *argv[]) { uint8_t ret; uint8_t init = 1; cfg_t *cfg; int32_t adc_channel = -1; uint32_t val_cur[MCP32XX_MAX_CHANNEL], val_old[MCP32XX_MAX_CHANNEL]; int32_t diff; struct mcp32xx_dev mcp_dev; struct volume_handle v_handle = {0}; struct mpd_handle m_handle = {0}; struct lcd_handle l_handle = {0}; useconds_t sleep_usec; uint8_t song_update_count_max; uint8_t song_update_count = 0; cfg_opt_t opts[] = { CFG_INT("UpdateInterval", 300000, CFGF_NONE), CFG_INT("SongUpdateInterval", 2000000, CFGF_NONE), CFG_INT("ChannelUsed", 2, CFGF_NONE), CFG_INT("VolumeChannel", 0, CFGF_NONE), CFG_INT("TunerChannel", 1, CFGF_NONE), CFG_INT("MaxLineChar", 16, CFGF_NONE), CFG_INT("MaxLineBuf", 80, CFGF_NONE), CFG_STR("HostName", "localhost", CFGF_NONE), CFG_INT("Port", 6600, CFGF_NONE), CFG_INT("MaxTunerPos", 12, CFGF_NONE), CFG_INT("MaxVolSteps", 50, CFGF_NONE), CFG_STR("RadioPlaylistName", "stations", CFGF_NONE), CFG_INT("LCD-Pin_RS", 25, CFGF_NONE), CFG_INT("LCD-Pin_E", 24, CFGF_NONE), CFG_INT("LCD-Pin_DB4", 23, CFGF_NONE), CFG_INT("LCD-Pin_DB5", 17, CFGF_NONE), CFG_INT("LCD-Pin_DB6", 27, CFGF_NONE), CFG_INT("LCD-Pin_DB7", 22, CFGF_NONE), CFG_STR("FillPatternFirstLine", " ++ ", CFGF_NONE), CFG_STR("FillPatternSecondLine", " ** ", CFGF_NONE), CFG_INT("MaxLineLength", 16, CFGF_NONE), CFG_INT("MaxLineBufferLength", 80, CFGF_NONE), CFG_END() }; cfg = cfg_init(opts, CFGF_NONE); ret = cfg_parse(cfg, "/etc/radioberry.conf"); if(ret == CFG_FILE_ERROR) { perror("/etc/radioberry.conf"); printf("WARN: could not read /etc/radioberry.conf," " process with default values\n"); } else if (ret == CFG_PARSE_ERROR) { printf("configuration parse error\n"); goto out; } /* get configuration values */ channel_used = (uint8_t)cfg_getint(cfg, "ChannelUsed"); volume_chan = (uint8_t)cfg_getint(cfg, "VolumeChannel"); tuner_chan = (uint8_t)cfg_getint(cfg, "TunerChannel"); sleep_usec = cfg_getint(cfg, "UpdateInterval") / channel_used; printf("sleep_usec %d\n", sleep_usec); song_update_count_max = cfg_getint(cfg, "SongUpdateInterval") / sleep_usec; /* pass over pointer to handles of mpd, lcd and volume */ m_handle.lh = &l_handle; v_handle.mh = &m_handle; m_handle.cfg = cfg; l_handle.cfg = cfg; signal(SIGINT, sigintterm_handler); signal(SIGTERM, sigintterm_handler); ret = lcd_init(&l_handle); if (ret) { printf("failed to initialize lcd, lcd control disabled \n"); lcd_control_enabled = 0; } if (lcd_control_enabled) { lcd_print_string("Radioberry"); lcd_move_cursor_down(); lcd_print_string("=== Welcome ==="); } ret = mcp32xx_init(&mcp_dev); if (ret) { printf("failed to initialize spi device, analog control" " devices disabled\n"); tuner_control_enabled = 0; vol_control_enabled = 0; } ret = init_mpd_handle(&m_handle); if (ret) { printf("could not initialize mpd client," " tuner control disabled\n"); tuner_control_enabled = 0; } /* disable tuner control if we cannot get any station at all. If one * station fails, let's process and wait for tuner changes */ ret = load_stations_playlist(&m_handle); if (ret == 1) { printf("could not load radio stations list," " tuner control disabled\n"); tuner_control_enabled = 0; } ret = init_vol_control(&v_handle); if (ret) { printf("could not initialize volume control," " volumen control disabled\n"); vol_control_enabled = 0; } running = 1; while ( running ) { usleep(sleep_usec); if (adc_channel + 1 == channel_used) { adc_channel = 0; mpd_status_update(m_handle.mpd_obj); /* detect if initial loop is done. Start update lcd * after initial loop */ if (init) init = 0; else { if (lcd_control_enabled) lcd_update_screen(&l_handle); } } else adc_channel++; if (song_update_count == song_update_count_max) { update_song_info(&m_handle); song_update_count = 0; } else song_update_count++; /* loop over all channels in singel ended mode * and reset counter in the last loop. */ val_cur[adc_channel] = mcp32xx_get_val(&mcp_dev, adc_channel); /* fill the old value buffer and intialize the player with * current settings*/ if (init) { val_old[adc_channel] = val_cur[adc_channel]; ret = process_value(&v_handle, &m_handle, val_cur[adc_channel], adc_channel); /* skip comparing old/new values while intializing */ if (ret) { printf("unrecoverable error, quit now\n"); break; } else continue; } diff = val_old[adc_channel] - val_cur[adc_channel]; #ifdef DEBUG printf("adc_channel: %u, old %u, new %u, diff %d\n", adc_channel, val_cur[adc_channel], val_old[adc_channel], diff); #endif if (abs(diff) < TOLERANT_THRESHOLD) continue; #ifdef DEBUG if (diff > 0) printf("Poti %u was turned left, current val: %d\n", adc_channel + 1, val_cur[adc_channel]); else printf("Poti %u was turned right, current Pos: %d\n", adc_channel + 1, val_cur[adc_channel]); #endif process_value(&v_handle, &m_handle, val_cur[adc_channel], adc_channel); val_old[adc_channel] = val_cur[adc_channel]; } out: lcd_clear_screen(); lcd_close(&l_handle); mcp32xx_close(&mcp_dev); close_vol_ctl(&v_handle); close_mpd_handle(&m_handle); exit(ret); }