//----------------------------------------------------------------------------- // Main function //----------------------------------------------------------------------------- int main(void) { WDT_INIT(); InitMCU(); initRotary(); InitUART(); timer_init(); rotary__GetValue(); nRF24L01_Initial(); // initialize dmx driver MDP_SendDimmingReqToMDP(0xff, 0xFF); //DMX512Send(); PORTC = 0x00; TCCR1A = 0x00; TCCR1B = 0x06; TCNT1H = 0xFF; TCNT1L = 0xFF; TIMSK |= 0x04; ZRMSendSetPreconfig(0x15); MSLEEP(100); ZRMSendReset(); MSLEEP(1000); timer_set(ON_WTD_TIMER_ID, 500); timer_set(ON_TEST_TIMER_ID, 3000); timer_set(ON_ZIGBEE_PING_TIMER_ID, 3000); timer_set(ON_ONTIME_TIMER_ID, 100); timer_set(NCP_TIMER_ID, 2000); tmp_zrmp.zrm_State = ZRM_INIT; xcps_init_zigbee(USART0_Receive, USART0_Transmit); xcps_init_rs485(USART1_Receive, USART1_Transmit); // FILE mystdout = TX_Mode(0); // FDEV_SETUP_STREAM((void *)USART0_Transmit, NULL, _FDEV_SETUP_WRITE); // stdout = &mystdout; // // DEBUG("\n\r=========START PROGRAM ===========\n\r"); while (1) { ledTask(); ZigbeeUsartTask(); NCP_Task(); } return 0; }
/** * initialization procedure of LCD * * @param LcdData_t* lcd handler structure address * @param lcd_topology number representing topology of LCD * @return none * */ void lcdinit(LcdData_t *lcd, lcd_topology topo) { memset(lcd->buffer, 0x20, LCD_BUFFER_SIZE); //Fill buffer with spaces if (topo > LCD_TOPO_8x2) topo = LCD_TOPO_16x2; lcd->organization.topology = topo; lcd->organization.columns = topoaddr[topo][4]; lcd->organization.rows = topoaddr[topo][5]; memcpy(lcd->organization.addresses, topoaddr[topo], sizeof(topoaddr[topo]) - 2); lcd->organization.toponame = toponames[topo]; lcd->displaycontrol = 0; lcd->displaymode = 0; lcd->displayfunction = LCD_FS_4BITDATA | LCD_FS_1LINE | LCD_FS_5x8FONT; if (lcd->organization.rows > 1) lcd->displayfunction |= LCD_FS_2LINES; MSLEEP(50); _buswrite(lcd, lcd->backlight ? (1 << PIN_BACKLIGHTON) : 0); MSLEEP(100); _write4bits(lcd, (1 << PIN_DB4) | (1 << PIN_DB5)); MSLEEP(5); _write4bits(lcd, (1 << PIN_DB4) | (1 << PIN_DB5)); MSLEEP(5); _write4bits(lcd, (1 << PIN_DB4) | (1 << PIN_DB5)); MSLEEP(15); _write4bits(lcd, (1 << PIN_DB5)); lcdcommand(lcd, lcd->displayfunction); lcd->displaycontrol |= LCD_DC_DISPLAYON | LCD_DC_CURSOROFF | LCD_DC_CURSORBLINKOFF; lcdcommand(lcd, lcd->displaycontrol); lcdclear(lcd); lcdhome(lcd); lcdsetcursor(lcd, lcd->column, lcd->row); lcdcursor(lcd, lcd->cursor); lcdblink(lcd, lcd->blink); }
INT CGSCondEx::BroadcastSignal(void) { #ifdef _WIN32 ::SetEvent(m_hEvent); INT x = m_iWaitConts-1; for( ;x>0; x-- ) { if( !::SetEvent(m_hEvent) ) { assert(0); } MSLEEP(1); } //ResetEvent(m_hEvent); return R_SUCCESS; #else if( ::pthread_cond_broadcast(&m_hEvent) ) { return R_ESYSTEM; } return R_SUCCESS; #endif }
/** * will set LCD back to home, which usually is cursor set at position 0,0 * * @param LcdData_t* lcd handler structure address * @return none * */ void lcdhome(LcdData_t *lcd) { lcd->column = 0; lcd->row = 0; lcdcommand(lcd, LCD_HOME); MSLEEP(2); }
SqlOpenLob::~SqlOpenLob() { bool done = false; while(!done) { sword res = OCICALL(OCILobClose( _lob._conn._svc_ctx, _lob._conn._env._errh, _lob._loc )); if( res != OCI_SUCCESS ) { sb4 errorcode; sword res2 = OCICALL(OCIErrorGet(_lob._conn._env._errh, 1, NULL, &errorcode, NULL, 0, OCI_HTYPE_ERROR)); assert(res2 == OCI_SUCCESS); if(errorcode == 3127) // ORA-03127: no new operations allowed until the active operation ends { std::cerr << "ORA-03127: no new operations allowed until the active operation ends" << std::endl; MSLEEP(100); } else { oci_check_error(__TROTL_HERE__, _lob._conn._env._errh, res); } } else { done = true; } } };
oraub8 SqlLob::length() { if(!is_not_null()) return 0; bool done = false; oraub8 len; while(!done) { sword res = OCICALL(OCILobGetLength2(_conn._svc_ctx, _conn._env._errh, _loc, &len)); if( res != OCI_SUCCESS ) { sb4 errorcode; sword res2 = OCICALL(OCIErrorGet(_conn._env._errh, 1, NULL, &errorcode, NULL, 0, OCI_HTYPE_ERROR)); assert(res2 == OCI_SUCCESS); if(errorcode == 3127) // ORA-03127: no new operations allowed until the active operation ends { std::cerr << "ORA-03127: no new operations allowed until the active operation ends" << std::endl; MSLEEP(100); } else { oci_check_error(__TROTL_HERE__, _conn._env._errh, res); } } else { done = true; } } return len; };
/* * NOTE: !! offset has to be >= 1. Oracle's LOBs start at 1st byte. */ oraub8 SqlClob::read(dvoid* bufp, oraub8 buflen, oraub8 offset, oraub8 amount, oraub8 *chars, ub2 csid, ub1 csfrm) { oraub8 char_amt = 0; bool done = false; while(!done) { sword res = OCICALL(OCILobRead2( _conn._svc_ctx, _conn._env._errh, _loc, &amount, &char_amt, offset, bufp, buflen, OCI_ONE_PIECE, /* ub1 piece */ NULL, /* dvoid* ctxp */ NULL, /* sb4 (*cbfp)(dvoid*ctxp,CONST dvoid*bufp,oraub8*len,ub1*piece) */ 0 /* csid */, 0 /* csfrm */ )); if( res != OCI_SUCCESS ) { sb4 errorcode; sword res2 = OCICALL(OCIErrorGet(_conn._env._errh, 1, NULL, &errorcode, NULL, 0, OCI_HTYPE_ERROR)); assert(res2 == OCI_SUCCESS); if(errorcode == 24804) // ORA-24804: Lob read/write functions called while another OCI LOB read/write streaming is in progress { std::cerr << "ORA-24804: Lob read/write functions called while another OCI LOB read/write streaming is in progress" << std::endl; MSLEEP(100); } else { oci_check_error(__TROTL_HERE__, _conn._env._errh, res); } } else { done = true; } } if(chars) *chars = char_amt; return amount; };
int main() { printf("checklist"); printf("hit black button when ready"); while(black_button()); printf("MAKE SURE CREATE IS ON!!!!!!!!"); while(!black_button()); printf("MAKE SURE ARM IS IN DOWN POSITION!!!!!!!!"); while(!black_button()); printf("MAKE SURE ARM AND CLAW WORK"); while(!black_button()); printf("CHECK POSITION OF CLAW AND ARM"); while(!black_button()); printf("MAKE SURE LIGHT SENSORT IS CALIBRATED"); while(!black_button()); // this starts the robot SECTion 1 wait_for_light(0); shut_down_in(120.0); //this shuts the robot down after 120.0 seconds while(create_connect()); //connects create to cbc set_servo_position(3, 0); set_servo_position(0, 1800); enable_servos(); msleep(500); create_full(); //section 2 create_drive_direct(SUPER_FAST, SUPER_FAST); msleep(1646); //leave beach create_stop(); msleep(300); create_drive_direct(SUPER_FAST, -SUPER_FAST); msleep(435); //turn towards center create_stop(); msleep(300); create_drive_direct(SUPER_FAST, SUPER_FAST); msleep(1600); //move towards botguy create_stop(); msleep(500); //section 3 set_servo_position(0, 1424); msleep(1800); set_servo_position(0, 1100); msleep(1800); set_servo_position(0, 924); msleep(1800); set_servo_position(0, 724); msleep(1800); set_servo_position(3, 1024); msleep(1800); set_servo_position(0, 924); msleep(1800); set_servo_position(0, 1100); msleep(1800); set_servo_position(0, 1200); msleep(2000); //retrieve botguy //section 4 create_drive_direct(-FAST, FAST); msleep(445); create_stop(); create_drive_direct(-FAST, -FAST); msleep(2000); create_stop(); create_drive_direct(FAST, -FAST); msleep(445); create_stop(); create_drive_direct(-FAST, -FAST); msleep(900); create_stop(); msleep(1600); create_stop(); set_servo_position(3, 0); set_servo_position(0, 1800); msleep(1200); set_servo_position(0, 1200); msleep(1000); set_servo_position(0, 1800); msleep(1000); create_drive_direct(1000, 1000); msleep(800); create_drive_direct(-1000, -1000); msleep(800); DRIVE(SUPER_FAST); MSLEEP(800); TURN(-SUPER_FAST, SUPER_FAST); MSLEEP(460); DRIVE(SUPER_FAST); MSLEEP(1380); TURN(SUPER_FAST, -SUPER_FAST); MSLEEP(425); DRIVE(SUPER_FAST); SLEEP(1.5); while(get_create_lbump(0.01) == 0) { DRIVE(SUPER_FAST); } TURN(-SUPER_FAST, SUPER_FAST); MSLEEP(435); TURN(SUPER_FAST, 975); MSLEEP(500); while(get_create_rbump(0.01) == 0) { TURN(SUPER_FAST, 990); } create_stop(); create_disconnect(); }
INT32 CGSProcessInfo::GSGetTotalCPUUsage(INT32 &iCPU) { INT32 iRet = -1; #ifdef _WIN32 FILETIME preidleTime; FILETIME prekernelTime; FILETIME preuserTime; FILETIME idleTime; FILETIME kernelTime; FILETIME userTime; GetSystemTimes( &idleTime, &kernelTime, &userTime ); preidleTime = idleTime; prekernelTime = kernelTime; preuserTime = userTime ; //休眠1s后再获取 MSLEEP(1000); GetSystemTimes( &idleTime, &kernelTime, &userTime ); INT64 idle = CompareFileTime( preidleTime,idleTime); INT64 kernel = CompareFileTime( prekernelTime, kernelTime); INT64 user = CompareFileTime(preuserTime, userTime); //CPU利用率 iCPU = (kernel +user - idle) *100/(kernel+user); //CPU空闲率 INT64 cpuidle = ( idle) *100/(kernel+user); iRet = 0; #elif _LINUX DWORD total1; DWORD total2; DWORD user1; DWORD nice1; DWORD system1; DWORD idle1; DWORD iowait1; DWORD irq1; DWORD softirq1; DWORD user2; DWORD nice2; DWORD system2; DWORD idle2; DWORD iowait2; DWORD irq2; DWORD softirq2; char cpu[21]; char text[201]; FILE *fp; fp = fopen("/proc/stat", "r"); fgets(text, 200, fp); if(strstr(text, "cpu")) { sscanf(text, "%s%lu%lu%lu%lu", cpu, &user1, &nice1, &system1, &idle1, &iowait1, &irq1, &softirq1); } fclose(fp); total1 = (user1+nice1+system1+idle1+iowait1+irq1+softirq1); MSLEEP(1000); fp = fopen("/proc/stat", "r"); fgets(text, 200, fp); if(strstr(text, "cpu")) { sscanf(text, "%s%lu%lu%lu%lu", cpu, &user2, &nice2, &system2, &idle2, &iowait2, &irq2, &softirq2); } fclose(fp); total2 = (user2+nice2+system2+idle2+iowait2+irq2+softirq2); if ((total2 - total1) == 0) { iCPU = 0; } else { iCPU = (INT32)((user2-user1+nice2 - nice1 +system2 - system1)*10000)/(total2-total1); } iRet = 0; #endif return iRet; }
/** * clears buffer by setting all bytes to 0x20 (ASCII code for space) and * send clear command to a LCD * * @param LcdData_t* lcd handler structure address * @return none * */ void lcdclear(LcdData_t *lcd) { memset(lcd->buffer, 0x20, LCD_BUFFER_SIZE); //Fill buffer with spaces lcdcommand(lcd, LCD_CLEAR); MSLEEP(2); }
//----------------------------------------------------------------------// void resetZigbee() { PORTD &= ~(0x80); MSLEEP(100); PORTD |= 0x80; }
void bs_sleep( int ms ) { // TODO: Need the value from datasheet. MSLEEP(ms); }
static void lcd_truely_1p3828_config_480_800() { int spi_fd, i; char buf[64]; #ifndef LCD_BRIGHEST int pwm_fd1, pwm_fd2; int lcd_brightness; int ret; #endif /* Power On */ lcd_power_on(); /* Hardware Reset */ lcd_reset(); #ifdef LCD_BRIGHEST /* Backlight on */ lcd_backlight_on(); #endif /* Program TRUELY_1P3828 to output 480x800 */ if (lcd_spi_dev_node(buf)) { perror("Unable to get lcd spi bus_id or cs_id!\n"); goto lcd_truely_1p3828_config_480_800_exit; } spi_fd = open(buf, O_WRONLY); if (spi_fd < 0) { perror("Can't open TRUELY_1P3828_SPI_DEV_NODE to write"); goto lcd_truely_1p3828_config_480_800_exit; } else { truely_1p3828_set_spi_bus(spi_fd); } truely_1p3828_write_cmd(spi_fd, 0xB9); //Set_EXTC truely_1p3828_write_data(spi_fd, 0xFF); truely_1p3828_write_data(spi_fd, 0x83); truely_1p3828_write_data(spi_fd, 0x69); truely_1p3828_write_cmd(spi_fd, 0xB1); //Set Power truely_1p3828_write_data(spi_fd, 0x01); truely_1p3828_write_data(spi_fd, 0x00); truely_1p3828_write_data(spi_fd, 0x34); truely_1p3828_write_data(spi_fd, 0x06); truely_1p3828_write_data(spi_fd, 0x00); truely_1p3828_write_data(spi_fd, 0x0F); // truely_1p3828_write_data(spi_fd, 0x0F); truely_1p3828_write_data(spi_fd, 0x2A); truely_1p3828_write_data(spi_fd, 0x32); truely_1p3828_write_data(spi_fd, 0x3F); truely_1p3828_write_data(spi_fd, 0x3F); truely_1p3828_write_data(spi_fd, 0x07); truely_1p3828_write_data(spi_fd, 0x23); truely_1p3828_write_data(spi_fd, 0x01); truely_1p3828_write_data(spi_fd, 0xE6); truely_1p3828_write_data(spi_fd, 0xE6); truely_1p3828_write_data(spi_fd, 0xE6); truely_1p3828_write_data(spi_fd, 0xE6); truely_1p3828_write_data(spi_fd, 0xE6); truely_1p3828_write_cmd(spi_fd, 0xB2); // SET Display 480x800 truely_1p3828_write_data(spi_fd, 0x00); truely_1p3828_write_data(spi_fd, 0x2b); truely_1p3828_write_data(spi_fd, 0x0A); truely_1p3828_write_data(spi_fd, 0x0A); truely_1p3828_write_data(spi_fd, 0x70); truely_1p3828_write_data(spi_fd, 0x00); truely_1p3828_write_data(spi_fd, 0xFF); truely_1p3828_write_data(spi_fd, 0x00); truely_1p3828_write_data(spi_fd, 0x00); truely_1p3828_write_data(spi_fd, 0x00); truely_1p3828_write_data(spi_fd, 0x00); truely_1p3828_write_data(spi_fd, 0x03); truely_1p3828_write_data(spi_fd, 0x03); truely_1p3828_write_data(spi_fd, 0x00); truely_1p3828_write_data(spi_fd, 0x01); truely_1p3828_write_cmd(spi_fd, 0xB4); // SET Display 480x800 truely_1p3828_write_data(spi_fd, 0x00); truely_1p3828_write_data(spi_fd, 0x18); truely_1p3828_write_data(spi_fd, 0x80); truely_1p3828_write_data(spi_fd, 0x10); truely_1p3828_write_data(spi_fd, 0x01); truely_1p3828_write_cmd(spi_fd, 0xB6); // SET VCOM truely_1p3828_write_data(spi_fd, 0x2C); truely_1p3828_write_data(spi_fd, 0x2C); truely_1p3828_write_cmd(spi_fd, 0xD5); //SET GIP truely_1p3828_write_data(spi_fd, 0x00); truely_1p3828_write_data(spi_fd, 0x05); truely_1p3828_write_data(spi_fd, 0x03); truely_1p3828_write_data(spi_fd, 0x00); truely_1p3828_write_data(spi_fd, 0x01); truely_1p3828_write_data(spi_fd, 0x09); truely_1p3828_write_data(spi_fd, 0x10); truely_1p3828_write_data(spi_fd, 0x80); truely_1p3828_write_data(spi_fd, 0x37); truely_1p3828_write_data(spi_fd, 0x37); truely_1p3828_write_data(spi_fd, 0x20); truely_1p3828_write_data(spi_fd, 0x31); truely_1p3828_write_data(spi_fd, 0x46); truely_1p3828_write_data(spi_fd, 0x8A); truely_1p3828_write_data(spi_fd, 0x57); truely_1p3828_write_data(spi_fd, 0x9B); truely_1p3828_write_data(spi_fd, 0x20); truely_1p3828_write_data(spi_fd, 0x31); truely_1p3828_write_data(spi_fd, 0x46); truely_1p3828_write_data(spi_fd, 0x8A); truely_1p3828_write_data(spi_fd, 0x57); truely_1p3828_write_data(spi_fd, 0x9B); truely_1p3828_write_data(spi_fd, 0x07); truely_1p3828_write_data(spi_fd, 0x0F); truely_1p3828_write_data(spi_fd, 0x02); truely_1p3828_write_data(spi_fd, 0x00); truely_1p3828_write_cmd(spi_fd, 0xE0); //SET GAMMA truely_1p3828_write_data(spi_fd, 0x00); truely_1p3828_write_data(spi_fd, 0x08); truely_1p3828_write_data(spi_fd, 0x0D); truely_1p3828_write_data(spi_fd, 0x2D); truely_1p3828_write_data(spi_fd, 0x34); truely_1p3828_write_data(spi_fd, 0x3F); truely_1p3828_write_data(spi_fd, 0x19); truely_1p3828_write_data(spi_fd, 0x38); truely_1p3828_write_data(spi_fd, 0x09); truely_1p3828_write_data(spi_fd, 0x0E); truely_1p3828_write_data(spi_fd, 0x0E); truely_1p3828_write_data(spi_fd, 0x12); truely_1p3828_write_data(spi_fd, 0x14); truely_1p3828_write_data(spi_fd, 0x12); truely_1p3828_write_data(spi_fd, 0x14); truely_1p3828_write_data(spi_fd, 0x13); truely_1p3828_write_data(spi_fd, 0x19); truely_1p3828_write_data(spi_fd, 0x00); truely_1p3828_write_data(spi_fd, 0x08); truely_1p3828_write_data(spi_fd, 0x0D); truely_1p3828_write_data(spi_fd, 0x2D); truely_1p3828_write_data(spi_fd, 0x34); truely_1p3828_write_data(spi_fd, 0x3F); truely_1p3828_write_data(spi_fd, 0x19); truely_1p3828_write_data(spi_fd, 0x38); truely_1p3828_write_data(spi_fd, 0x09); truely_1p3828_write_data(spi_fd, 0x0E); truely_1p3828_write_data(spi_fd, 0x0E); truely_1p3828_write_data(spi_fd, 0x12); truely_1p3828_write_data(spi_fd, 0x14); truely_1p3828_write_data(spi_fd, 0x12); truely_1p3828_write_data(spi_fd, 0x14); truely_1p3828_write_data(spi_fd, 0x13); truely_1p3828_write_data(spi_fd, 0x19); truely_1p3828_write_cmd(spi_fd, 0xC1); //set DGC truely_1p3828_write_data(spi_fd, 0x01); //enable DGC function truely_1p3828_write_data(spi_fd, 0x02); //SET R-GAMMA truely_1p3828_write_data(spi_fd, 0x08); truely_1p3828_write_data(spi_fd, 0x12); truely_1p3828_write_data(spi_fd, 0x1A); truely_1p3828_write_data(spi_fd, 0x22); truely_1p3828_write_data(spi_fd, 0x2A); truely_1p3828_write_data(spi_fd, 0x31); truely_1p3828_write_data(spi_fd, 0x36); truely_1p3828_write_data(spi_fd, 0x3F); truely_1p3828_write_data(spi_fd, 0x48); truely_1p3828_write_data(spi_fd, 0x51); truely_1p3828_write_data(spi_fd, 0x58); truely_1p3828_write_data(spi_fd, 0x60); truely_1p3828_write_data(spi_fd, 0x68); truely_1p3828_write_data(spi_fd, 0x70); truely_1p3828_write_data(spi_fd, 0x78); truely_1p3828_write_data(spi_fd, 0x80); truely_1p3828_write_data(spi_fd, 0x88); truely_1p3828_write_data(spi_fd, 0x90); truely_1p3828_write_data(spi_fd, 0x98); truely_1p3828_write_data(spi_fd, 0xA0); truely_1p3828_write_data(spi_fd, 0xA7); truely_1p3828_write_data(spi_fd, 0xAF); truely_1p3828_write_data(spi_fd, 0xB6); truely_1p3828_write_data(spi_fd, 0xBE); truely_1p3828_write_data(spi_fd, 0xC7); truely_1p3828_write_data(spi_fd, 0xCE); truely_1p3828_write_data(spi_fd, 0xD6); truely_1p3828_write_data(spi_fd, 0xDE); truely_1p3828_write_data(spi_fd, 0xE6); truely_1p3828_write_data(spi_fd, 0xEF); truely_1p3828_write_data(spi_fd, 0xF5); truely_1p3828_write_data(spi_fd, 0xFB); truely_1p3828_write_data(spi_fd, 0xFC); truely_1p3828_write_data(spi_fd, 0xFE); truely_1p3828_write_data(spi_fd, 0x8C); truely_1p3828_write_data(spi_fd, 0xA4); truely_1p3828_write_data(spi_fd, 0x19); truely_1p3828_write_data(spi_fd, 0xEC); truely_1p3828_write_data(spi_fd, 0x1B); truely_1p3828_write_data(spi_fd, 0x4C); truely_1p3828_write_data(spi_fd, 0x40); truely_1p3828_write_data(spi_fd, 0x02); //SET G-Gamma truely_1p3828_write_data(spi_fd, 0x08); truely_1p3828_write_data(spi_fd, 0x12); truely_1p3828_write_data(spi_fd, 0x1A); truely_1p3828_write_data(spi_fd, 0x22); truely_1p3828_write_data(spi_fd, 0x2A); truely_1p3828_write_data(spi_fd, 0x31); truely_1p3828_write_data(spi_fd, 0x36); truely_1p3828_write_data(spi_fd, 0x3F); truely_1p3828_write_data(spi_fd, 0x48); truely_1p3828_write_data(spi_fd, 0x51); truely_1p3828_write_data(spi_fd, 0x58); truely_1p3828_write_data(spi_fd, 0x60); truely_1p3828_write_data(spi_fd, 0x68); truely_1p3828_write_data(spi_fd, 0x70); truely_1p3828_write_data(spi_fd, 0x78); truely_1p3828_write_data(spi_fd, 0x80); truely_1p3828_write_data(spi_fd, 0x88); truely_1p3828_write_data(spi_fd, 0x90); truely_1p3828_write_data(spi_fd, 0x98); truely_1p3828_write_data(spi_fd, 0xA0); truely_1p3828_write_data(spi_fd, 0xA7); truely_1p3828_write_data(spi_fd, 0xAF); truely_1p3828_write_data(spi_fd, 0xB6); truely_1p3828_write_data(spi_fd, 0xBE); truely_1p3828_write_data(spi_fd, 0xC7); truely_1p3828_write_data(spi_fd, 0xCE); truely_1p3828_write_data(spi_fd, 0xD6); truely_1p3828_write_data(spi_fd, 0xDE); truely_1p3828_write_data(spi_fd, 0xE6); truely_1p3828_write_data(spi_fd, 0xEF); truely_1p3828_write_data(spi_fd, 0xF5); truely_1p3828_write_data(spi_fd, 0xFB); truely_1p3828_write_data(spi_fd, 0xFC); truely_1p3828_write_data(spi_fd, 0xFE); truely_1p3828_write_data(spi_fd, 0x8C); truely_1p3828_write_data(spi_fd, 0xA4); truely_1p3828_write_data(spi_fd, 0x19); truely_1p3828_write_data(spi_fd, 0xEC); truely_1p3828_write_data(spi_fd, 0x1B); truely_1p3828_write_data(spi_fd, 0x4C); truely_1p3828_write_data(spi_fd, 0x40); truely_1p3828_write_data(spi_fd, 0x02); //SET B-Gamma truely_1p3828_write_data(spi_fd, 0x08); truely_1p3828_write_data(spi_fd, 0x12); truely_1p3828_write_data(spi_fd, 0x1A); truely_1p3828_write_data(spi_fd, 0x22); truely_1p3828_write_data(spi_fd, 0x2A); truely_1p3828_write_data(spi_fd, 0x31); truely_1p3828_write_data(spi_fd, 0x36); truely_1p3828_write_data(spi_fd, 0x3F); truely_1p3828_write_data(spi_fd, 0x48); truely_1p3828_write_data(spi_fd, 0x51); truely_1p3828_write_data(spi_fd, 0x58); truely_1p3828_write_data(spi_fd, 0x60); truely_1p3828_write_data(spi_fd, 0x68); truely_1p3828_write_data(spi_fd, 0x70); truely_1p3828_write_data(spi_fd, 0x78); truely_1p3828_write_data(spi_fd, 0x80); truely_1p3828_write_data(spi_fd, 0x88); truely_1p3828_write_data(spi_fd, 0x90); truely_1p3828_write_data(spi_fd, 0x98); truely_1p3828_write_data(spi_fd, 0xA0); truely_1p3828_write_data(spi_fd, 0xA7); truely_1p3828_write_data(spi_fd, 0xAF); truely_1p3828_write_data(spi_fd, 0xB6); truely_1p3828_write_data(spi_fd, 0xBE); truely_1p3828_write_data(spi_fd, 0xC7); truely_1p3828_write_data(spi_fd, 0xCE); truely_1p3828_write_data(spi_fd, 0xD6); truely_1p3828_write_data(spi_fd, 0xDE); truely_1p3828_write_data(spi_fd, 0xE6); truely_1p3828_write_data(spi_fd, 0xEF); truely_1p3828_write_data(spi_fd, 0xF5); truely_1p3828_write_data(spi_fd, 0xFB); truely_1p3828_write_data(spi_fd, 0xFC); truely_1p3828_write_data(spi_fd, 0xFE); truely_1p3828_write_data(spi_fd, 0x8C); truely_1p3828_write_data(spi_fd, 0xA4); truely_1p3828_write_data(spi_fd, 0x19); truely_1p3828_write_data(spi_fd, 0xEC); truely_1p3828_write_data(spi_fd, 0x1B); truely_1p3828_write_data(spi_fd, 0x4C); truely_1p3828_write_data(spi_fd, 0x40); truely_1p3828_write_cmd(spi_fd, 0x2D);//Look up table for(i = 0; i < 64; i++) { truely_1p3828_write_data(spi_fd, 8 * i); } for(i = 0; i < 64; i++) { truely_1p3828_write_data(spi_fd, 4 * i); } for(i = 0; i < 64; i++) { truely_1p3828_write_data(spi_fd, 8 * i); } MSLEEP(10); truely_1p3828_write_cmd(spi_fd, 0x3A); //Set COLMOD truely_1p3828_write_data(spi_fd, 0x77); truely_1p3828_write_cmd(spi_fd, 0x11); //Sleep Out MSLEEP(120); truely_1p3828_write_cmd(spi_fd, 0x29); //Display On //truely_1p3828_write_cmd(spi_fd, 0x2C); //Display On close(spi_fd); #ifndef LCD_BRIGHEST /* Backlight on */ pwm_fd1 = open(TRUELY_1P3828_PWM_PATH("max_brightness"), O_RDONLY); if (pwm_fd1 < 0) { perror("Can't open max_brightness to read"); goto lcd_truely_1p3828_config_480_800_exit; } ret = read(pwm_fd1, buf, sizeof(buf)); close(pwm_fd1); if (ret <= 0) { perror("Can't read max_brightness"); goto lcd_truely_1p3828_config_480_800_exit; } else { lcd_brightness = atoi(buf) / 2; } pwm_fd2 = open(TRUELY_1P3828_PWM_PATH("brightness"), O_WRONLY); if (pwm_fd2 < 0) { perror("Can't open brightness to write"); goto lcd_truely_1p3828_config_480_800_exit; } sprintf(buf, "%d", lcd_brightness); ret = write(pwm_fd2, buf, sizeof(buf)); close(pwm_fd2); if (ret <= 0) { perror("Can't write brightness"); goto lcd_truely_1p3828_config_480_800_exit; } #endif lcd_truely_1p3828_config_480_800_exit: return; }
int main(int argc, char **argv) { lbm_context_t *ctx; server_t server; /* State information for the server. */ char response_topic_name[256]; int err; /* Get (pretty much) unique client name. */ sprintf(response_topic_name, "Client.%lx.Response", (long)getpid()); #if defined(_MSC_VER) /* windows-specific code */ WSADATA wsadata; int wsStat = WSAStartup(MAKEWORD(2,2), &wsadata); if (wsStat != 0) { printf("line %d: wsStat=%d\n",__LINE__,wsStat); exit(1); } #endif server.ctx = NULL; server.topic_name = "Server1.Request"; server.src = NULL; /* Source to send requests to server. */ server.rcv = NULL; /* Receiver for responses from server. */ server.state = 0; /* Waiting for registration. */ err = lbm_config("client.cfg"); EX_LBM_CHK(err); err = lbm_context_create(&ctx, NULL, NULL, NULL); EX_LBM_CHK(err); server.ctx = ctx; /* Create source to send requests to server. */ { lbm_topic_t *topic; err = lbm_src_topic_alloc(&topic, ctx, server.topic_name, NULL); EX_LBM_CHK(err); err = lbm_src_create(&server.src, ctx, topic, NULL, NULL, NULL); EX_LBM_CHK(err); } /* Create receiver for responses from server. */ { lbm_topic_t *topic; err = lbm_rcv_topic_lookup(&topic, ctx, response_topic_name, NULL); EX_LBM_CHK(err); err = lbm_rcv_create(&server.rcv, ctx, topic, response_rcv_cb, &server, NULL); EX_LBM_CHK(err); } /* Register with the server. May need multiple tries. */ { int try_cnt = 0; int backoff_delay; char register_msg[257]; sprintf(register_msg, "r%s", response_topic_name); backoff_delay = 1; /* In milliseconds. */ MSLEEP(backoff_delay); /* Let TR complete. */ while (server.state == 0) { try_cnt ++; err = lbm_src_send(server.src, register_msg, strlen(register_msg) + 1, LBM_MSG_FLUSH | LBM_SRC_BLOCK); EX_LBM_CHK(err); printf("Sent '%s' to %s\n", register_msg, server.topic_name); /* Exponential backoff, to max of 1 sec. */ backoff_delay *= 2; /* Exponential backoff to max of 1 sec. */ if (backoff_delay > 1000) { backoff_delay = 1000; } MSLEEP(backoff_delay); /* Wait for server response. */ } printf("Took %d tries to register with server.\n", try_cnt); } /* Main work of the program, which includes sending 5 requests. */ { int i; char send_buf[500]; req_hdr_t *req_hdr = (req_hdr_t *)send_buf; memset((char *)req_hdr, '0', sizeof(req_hdr_t)); req_hdr->data[0] = 'R'; for (i = 0; i < 5; i++) { /* The application builds a request into <tt>request_msg</tt>. */ char request_msg[257]; sprintf(request_msg, "%s.%d", response_topic_name, i); /* The application message is copied in after the header. */ strcpy(&send_buf[sizeof(req_hdr_t)], request_msg); err = lbm_src_send(server.src, send_buf, strlen(send_buf) + 1, LBM_MSG_FLUSH | LBM_SRC_NONBLOCK); EX_LBM_CHK(err); MSLEEP(1000); } } printf("Client exiting.\n"); err = lbm_rcv_delete(server.rcv); EX_LBM_CHK(err); err = lbm_src_delete(server.src); EX_LBM_CHK(err); err = lbm_context_delete(ctx); EX_LBM_CHK(err); #if defined(_MSC_VER) WSACleanup(); #endif return 0; } /* main */