QState s_light_timer(ao_light_t * const me) { QState status; switch (Q_SIG(me)) { case Q_ENTRY_SIG: light_on(); status = Q_HANDLED(); break; case LIGHT_OFF_SIG: status = Q_TRAN(&s_light_off); break; case LIGHT_ON_SIG: status = Q_TRAN(&s_light_on); break; case Q_TIMEOUT_SIG: me->timer -= 1; if (me->timer == 0) status = Q_TRAN(&s_light_off); else status = Q_HANDLED(); break; default: status = Q_SUPER(&QHsm_top); break; } return status; }
int main( int argc, char *argv[] ) { int fd = 0; int i = 0; int retval = -1; int interval = 1; if ((retval = arg_filter( argc, argv)) != 0) { return -1; } if ((fd = open("/dev/mem", O_RDWR)) < 0) { perror("open"); return -1; } iobaseaddr = mmap( 0, 0x100000, PROT_READ|PROT_WRITE, MAP_SHARED, fd, (unsigned int)0x1fd00000 ); gpioaddr = iobaseaddr + SB_GPIO_BASE; time = atoi(argv[2]); // Register function to SIGALRM if ( !(strcmp(argv[1], "0")) ) { light_on(); signal(SIGALRM, light_led_continuously); set_timer0( time ); } else if ( !(strcmp(argv[1], "1")) ) { light_on(); interval = 200000; signal(SIGALRM, light_led_blinking); set_timer1( interval ); } while (count < time) { pause(); } return 0; }
void on_off() { light_on(); for (int i = 0; i < 250000; ++i) { } light_off(); for (int i = 0; i < 250000; ++i) { } }
static int32_t module_stop(const mmi_module_t * module) { ALOGI("%s start.", __FUNCTION__); if(module == NULL) { ALOGE("%s NULL point received ", __FUNCTION__); return FAILED; } light_on(false); pthread_kill(module->run_pid, SIGUSR1); return SUCCESS; }
static void *run_test(void *mod) { int delay = 0; if(mod == NULL) { ALOGE("%s NULL for cb function ", __FUNCTION__); return NULL; } delay = atoi(paras["delay"].c_str()); signal(SIGUSR1, signal_handler); while(1) { light_on(true); ((mmi_module_t *) mod)->cb_print(NULL, SUBCMD_MMI, "flashlight on", 13, PRINT); usleep(delay * 1000); light_on(false); ((mmi_module_t *) mod)->cb_print(NULL, SUBCMD_MMI, "flashlight off", 14, PRINT); usleep(delay * 1000); } return NULL; }
void ble_device_on_message(uint8_t type, uint16_t length, uint8_t* value) { uint8_t onoff = value[0]; uint8_t * rgb = value+1; if(onoff == 1) { light_off(); light_set_color(rgb); light_on(); } else if(onoff == 0) { light_off(); } else if(onoff == 2) { light_off(); light_set_color(rgb_color); light_on(); } }
void light_led_blinking( int sig ) { unsigned int tmp; read_reg( (gpioaddr + 0x00), tmp ); if (tmp & 0x00000080) { light_off(); count++; } else { light_on(); } return; }
void draw_lights( Road* r,int x5, int y5 , int road_ratio, CDC* pDC ) { int ratio = road_ratio-90; int u_l_x = get_x4(x5,LIGHT_RADIUM*2,ratio); int u_l_y = get_y4(y5,LIGHT_RADIUM*2,ratio); int l_l_x = get_x2(x5,LIGHT_RADIUM*2,ratio); int l_l_y = get_y2(y5,LIGHT_RADIUM*2,ratio); LightContainer* lc = r->light_group()->lights(); auto old_pen = pDC->SelectObject(DISABLED_BRUSH); for (auto light_iter=lc->begin(); light_iter != lc->end(); ++light_iter) { pDC->SelectObject(DISABLED_BRUSH); if (light_iter->light_on()) { switch (light_iter->color()) { case GREEN: pDC->SelectObject(GREEN_BRUSH); break; case YELLOW: pDC->SelectObject(YELLOW_BRUSH); break; case RED: pDC->SelectObject(RED_BRUSH); break; default: break; } } pDC->Ellipse(u_l_x,u_l_y,l_l_x,l_l_y); u_l_x = get_x4(u_l_x,LIGHT_RADIUM*2,ratio); u_l_y = get_y4(u_l_y,LIGHT_RADIUM*2,ratio); l_l_x = get_x4(l_l_x,LIGHT_RADIUM*2,ratio); l_l_y = get_y4(l_l_y,LIGHT_RADIUM*2,ratio); } CPoint textpoint[2]; textpoint[0].x = u_l_x; textpoint[0].y = u_l_y; textpoint[1].x = l_l_x; textpoint[1].y = l_l_y; int text_x = get_x4(get_x2(left_top(textpoint,2).x,5,ratio),5,ratio); int text_y = get_y4(get_y2(left_top(textpoint,2).y,5,ratio),5,ratio); CString dur; dur.Format(_T("%d"),r->light_group()->duration()); pDC->TextOutW(text_x,text_y,dur); pDC->SelectObject(old_pen); }
int main(void) { int x_pos = 0; int x_pos_old = 0; PCR = CLKDIV_3; // ICLK = SYSCLK / 3 GCR = ZPLL_CLK_DIV_PRE_1; // SYSCLK = 8 x fOSC PCR |= PENABLE; // Enable peripherals HETDIR = 0xFFFFFFFF; // HETx Output direction HETDOUT = 0x00000000; init_lcd(); light_on(); put_cursor( 0,0 ); put_text( "0V" ); put_cursor( 4,0 ); put_text( "1V" ); put_cursor( 9,0 ); put_text( "2V" ); put_cursor( 14,0 ); put_text( "3V" ); ADCR1 |= PS_8; // ADCLK prescaler = 8 ADSAMPEV |= SEN; // ADCSAMP1 controls SW ADSAMP1 = 62; // SW = 62+2 ADCR1 |= ADC_EN; // Enable ADC ADISR1 = 0x0006; // Convert croup 1 = channel 0 //ADISR1 = 0x0001; // Convert croup 1 = channel 0 ADCR2 |= G1_MODE; // Continuous Conversion for (;;) { while (!(ADSR & GP1_END)); // Wait for conversion to complete x_pos_old = x_pos; x_pos = ADDR2/64; //x_pos = ADDR0/64; if( x_pos_old != x_pos ) { put_char(x_pos, 1, SQUARE); put_char(x_pos_old, 1, ' '); } ADSR |= GP1_END; // Clears flag } }
QState s_light_on(ao_light_t * const me) { QState status; switch (Q_SIG(me)) { case Q_ENTRY_SIG: light_on(); status = Q_HANDLED(); break; case LIGHT_OFF_SIG: status = Q_TRAN(&s_light_off); break; default: status = Q_SUPER(&QHsm_top); break; } return status; }
static void * proc_control(void *args) { struct frame_manager *manager = get_frame_manager(CONTROL_MANAGER); struct record_manager * record_manager=get_record_manager(); struct block_filter *filter = NULL; struct frame *pframe = NULL; struct block * pblock = NULL; char buffer[64]; int length; char dest_addr = 0; char src_addr = 0; char operation = 0; char cmd = 0; char tmp; if (manager == NULL) return NULL; filter = get_frame_filter(manager); while (1) { pblock = get_block(filter, TIMEOUT_MAIN_UNIT, BLOCK_FULL); if (pblock != NULL) { set_sys_state(BIT5_MAIN_UNIT,STATE_MAINUNIT_OK); light_on(0); light_main_alarm(0); pframe = (struct frame*) pblock->data; pframe->length = pblock->data_length; dest_addr = destination_of_frame(pframe); src_addr = pframe->data[4]; cmd = command_of_frame(pframe); operation = operation_of_frame(pframe); if (src_addr == MASTER_ADDRESS) { switch (dest_addr) { case RADIO_450M_ADDRESS: if ((operation == 0x03) && (cmd == 0x20)) { //向450M发送机车号 char * cab_id = get_id(); get_frame_real_data(pframe, buffer, &length); buffer[8] = 0; tmp = buffer[3]; buffer[3] = 0; int cab_type = atoi(buffer); buffer[3] = tmp; sprintf(cab_id, "%s-%s", get_cab_code(cab_type), buffer + 3); } break; case ALL_MMI_ADDRESS: if ((operation == 0x03) && (cmd == 0x46)) { //关机命令 flush_all_data(record_manager); } break; } } if (dest_addr == RECORD_ADDRESS) { switch (operation) { case 1: //维护信息 // echo off tmp = 0; if (src_addr == 0x01) { tmp = 0x01; } else if ((src_addr == 0x03) || (src_addr == 0x04)) { tmp = 0x41; } send_frame(manager, RECORD_ADDRESS, src_addr, 1, tmp, pframe->data + 9, 2); switch (cmd) { case (char) 0x33: //播放控制 { if (pframe->data[10] == (char) 0xff) { start_play(src_addr); } else if (pframe->data[10] == 0) { stop_play(); } } break; case (char) 0xfa: //问询测试 break; case (char) 0x34: //查询时钟 { struct tm time; get_time(&time); buffer[0] = to_bcd(time.tm_year - 100); //year buffer[1] = to_bcd(time.tm_mon + 1); buffer[2] = to_bcd(time.tm_mday); buffer[3] = to_bcd(time.tm_hour); buffer[4] = to_bcd(time.tm_min); buffer[5] = to_bcd(time.tm_sec); send_frame(manager, RECORD_ADDRESS, src_addr, 1, (char) 0x91, buffer, 6); } break; case (char) 0x35: //设置时钟 break; case (char) 0xa5: //查询软件版本 { bcopy(version, buffer, 16); send_frame(manager, RECORD_ADDRESS, src_addr, 1, (char) 0xaa, buffer, 16); } break; } break; case 3: //不需要应答 break; } } put_block(pblock, BLOCK_EMPTY); } else { set_sys_state(BIT5_MAIN_UNIT,STATE_MAINUNIT_FAIL); light_main_alarm(1); } } return NULL; }
owerror_t osens_val_receive( OpenQueueEntry_t* msg, coap_header_iht* coap_header, coap_option_iht* coap_options ) { owerror_t outcome = E_FAIL; uint8_t n; static uint8_t buf[128]; uint8_t *pbuf = &buf[0]; uint8_t index; switch (coap_header->Code) { case COAP_CODE_REQ_GET: // reset packet payload msg->payload = &(msg->packet[127]); msg->length = 0; // /s if (((coap_options[1].length == 0) && (coap_options[1].type == COAP_OPTION_NUM_URIPATH)) || (coap_options[1].type != COAP_OPTION_NUM_URIPATH)) { } // /s/1 or /s/12 else if(((coap_options[1].length == 1 || coap_options[1].length == 2)) && (coap_options[1].type == COAP_OPTION_NUM_URIPATH)) { osens_point_t pt; #if (MYLINKXS_LIGHT_CONTROL == 0) if(coap_options[1].length == 2) index = (coap_options[1].pValue[0] - 0x30) * 10 + (coap_options[1].pValue[1] - 0x30); else index = coap_options[1].pValue[0] - 0x30; if(osens_get_point(index,&pt)) { pbuf = insert_str(pbuf,(uint8_t*)"{\"v\":",5,0); pbuf = insert_point_val(pbuf,&pt); pbuf = insert_str(pbuf,(uint8_t*)"}",1,0); #if (ENABLE_DEBUG_RFF == 1) && (DBG_APP_1 == 1) uint8_t pos=0; uint8_t *paux; rffbuf[pos++]= 0x85; rffbuf[pos++]= index; paux = (uint8_t*) &pt.value.fp32; rffbuf[pos++]= *paux++; rffbuf[pos++]= *paux++; rffbuf[pos++]= *paux++; rffbuf[pos++]= *paux++; paux = (uint8_t*) &pbuf[0]; rffbuf[pos++]= *paux++; rffbuf[pos++]= *paux++; rffbuf[pos++]= *paux++; rffbuf[pos++]= *paux++; openserial_printStatus(STATUS_RFF,(uint8_t*)&rffbuf,pos); #endif } else pbuf = insert_str(pbuf,(uint8_t*)"{}",2,0); #else //QUANDO TRABALHANDO COM A LAMPADA ESTAVA ESTE OUTRO CODIGO //TODO!!! DEIXAR O CODIGO UNICO pt.type = OSENS_DT_U8; pt.value.u8 = light_get_value(); pbuf = insert_str(pbuf,(uint8_t*)"{\"v\":",5,0); pbuf = insert_point_val(pbuf,&pt); pbuf = insert_str(pbuf,(uint8_t*)"}",1,0); #endif outcome = E_SUCCESS; } if(outcome == E_SUCCESS) { n = ((uint32_t)pbuf - (uint32_t)buf); packetfunctions_reserveHeaderSize(msg, 1 + n); msg->payload[0] = COAP_PAYLOAD_MARKER; memcpy(&msg->payload[1], buf, n); coap_header->Code = COAP_CODE_RESP_CONTENT; } break; case COAP_CODE_REQ_PUT: // reset packet payload msg->payload = &(msg->packet[127]); msg->length = 0; #if (DEBUG_LOG_RIT == 1) { uint8_t pos=0; rffbuf[pos++]= RFF_COMPONENT_STORMCOAP_TX; rffbuf[pos++]= 0x01; rffbuf[pos++]= coap_options[1].length; rffbuf[pos++]= coap_options[2].length; rffbuf[pos++]= coap_options[1].type; rffbuf[pos++]= coap_options[2].type; //rffbuf[pos++]= sensor_points.points[0].value.value.u8; openserial_printStatus(STATUS_RFF,(uint8_t*)&rffbuf,pos); } #endif // /s/2/-12.45 or /s/12/12.45 if((coap_options[1].length == 1 || coap_options[1].length == 2) && (coap_options[2].length > 0) && (coap_options[1].type == COAP_OPTION_NUM_URIPATH) && (coap_options[2].type == COAP_OPTION_NUM_URIPATH)) { #if 0 uint8_t index; double number; osens_point_t pt; if(coap_options[1].length == 2) index = (coap_options[1].pValue[0] - 0x30) * 10 + (coap_options[1].pValue[1] - 0x30); else index = coap_options[1].pValue[0] - 0x30; number = decode_number(coap_options[2].pValue,coap_options[2].length); pt.type = osens_get_ptype(index); if(pt.type >= 0) { set_point_val(&pt,number); if(osens_set_pvalue(index,&pt)) { // set the CoAP header coap_header->Code = COAP_CODE_RESP_CHANGED; outcome = E_SUCCESS; } } #else // switch on the light pulse (50 ms) light_on(); opentimers_start(1000,TIMER_ONESHOT,TIME_MS,light_timer); #endif } break; default: outcome = E_FAIL; break; } return outcome; }