static int platform_led_probe(struct platform_device *pdev) { int result; dev_t devno; devno = MKDEV(major,minor); if(major) result = register_chrdev_region(devno,1,"led-dyf"); else{ result = alloc_chrdev_region(&devno,0,1,"led-dyf"); major = MAJOR(devno); } if(result < 0){ printk("driver init unsuccess!\n"); return result; } gpbcon = (volatile unsigned long *)ioremap(0x56000010,16); gpbdat = gpbcon + 1; cdev_setup(); dyf_led_init(); led_all_off(); printk("platform_led_driver is init successfull!\n"); return 0; }
void led_on_or_off(unsigned long lednum,unsigned int on_or_off) { led_all_off(); switch(lednum) { case 1:if(on_or_off == 0) *gpbdat &= ~(1<<5); else *gpbdat |= (1<<5); break; case 2:if(on_or_off == 0) *gpbdat &= ~(1<<6); else *gpbdat |= (1<<6); break; case 3:if(on_or_off == 0) *gpbdat &= ~(1<<7); else *gpbdat |= (1<<7); break; case 4:if(on_or_off == 0) *gpbdat &= ~(1<<8); else *gpbdat |= (1<<8); break; default:break; } }
void led_off_id(unsigned char id) { switch (id) { case 1: led1_off();break; case 2: led2_off();break; case 3: led3_off();break; case 4: led4_off();break; default: led_all_off();break; } }
static void led_rotation_blink_all(void) { static uint16_t count; count++; static const uint16_t count_max = 100; if (count % count_max < count_max / 2) { led_all_off(); } else { led_all_on(); } }
static void led_rotation_rotate_leds_double(void) { static uint16_t count; count++; led_all_off(); static const uint16_t count_max = 100; if (count % count_max < count_max / 2) { SET_LED(LED_1); SET_LED(LED_3); } else { SET_LED(LED_2); SET_LED(LED_4); } }
void rt_hw_led_init(void) { GPIO_InitTypeDef GPIO_InitStructure; /* Enable GPIOB, GPIOC and AFIO clock */ RCC_APB2PeriphClockCmd(RCC_GPIO_LED | RCC_APB2Periph_AFIO , ENABLE); //RCC_APB2Periph_AFIO /* LEDs pins configuration */ GPIO_InitStructure.GPIO_Pin = GPIO_LED_ALL; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; GPIO_Init(GPIO_LED_PORT, &GPIO_InitStructure); led_all_off(); }
int main () { pl2303_init (); led_init (); disp_init (); serial_init (9600); while (1) { int c; switch ((c = serial_getchar ())) { case '!': led_all_off (); break; case '&': switch (serial_getchar ()) { case 'R': led_on (LED_R); break; case 'G': led_on (LED_G); break; case 'B': led_on (LED_B); break; case 'r': led_off (LED_R); break; case 'g': led_off (LED_G); break; case 'b': led_off (LED_B); break; case 'i': serial_puts ("Pripravek PIC24f Starter Kit;"); break; case 's': disp_clear (); disp_at (1, 1); while ((c = serial_getchar ()) != ';') disp_char (c); break; default: disp_clear (); disp_at (1, 1); disp_str ("unrecognized '"); disp_char (c); disp_char ('\''); } } } return 0; }
/***************************************************************************** * * ReadCloudCommands * * \param None * * \return None * * \brief Reads the commands from Exosite cloud * *****************************************************************************/ void ReadCloudCommands(void) { char * pbuf = exo_buffer; DisplayLCD(LCD_LINE6, " Exosite "); DisplayLCD(LCD_LINE7, " Read "); if (Exosite_Read("led_ctrl", pbuf, EXO_BUFFER_SIZE)) { DisplayLCD(LCD_LINE8, " OK "); if (!strncmp(pbuf, "0", 1)) led_all_off(); else if (!strncmp(pbuf, "1", 1)) led_all_on(); } else show_status(); MSTimerDelay(500); return; }
int main(void) { HAL_Init(); led_all_init(); SystemClock_Config(); BSP_PB_Init(BUTTON_KEY, BUTTON_MODE_EXTI); while (1) { isPressed = 0; demos[demoID](); demoID = (demoID + 1) % 2; isPressed = 0; led_all_on(); while (!isPressed); led_all_off(); } }
static void led_rotation_rotate_leds_race(void) { static uint16_t count; count++; led_all_off(); static uint16_t count_max = 1000; count_max--; if (count_max == 20) { count_max = 1000; } if (count % count_max < count_max / 4) { SET_LED(LED_1); } else if (count % count_max < count_max / 2) { SET_LED(LED_2); } else if (count % count_max < 3 * count_max / 4) { SET_LED(LED_3); } else { SET_LED(LED_4); } }
// Output Compare callback in non blocking mode void HAL_TIM_OC_DelayElapsedCallback(TIM_HandleTypeDef *htim) { if (ledState == LED3_TOGGLE) { BSP_LED_Toggle(LED3); BSP_LED_Off(LED6); BSP_LED_Off(LED4); } else if (ledState == LED4_TOGGLE) { BSP_LED_Toggle(LED4); BSP_LED_Off(LED6); BSP_LED_Off(LED3); } else if (ledState == LED6_TOGGLE) { BSP_LED_Off(LED3); BSP_LED_Off(LED4); BSP_LED_Toggle(LED6); } else if (ledState == STOP_TOGGLE) { BSP_LED_On(LED6); } else if (ledState == LEDS_OFF) { led_all_off(); } /* Get the TIM4 Input Capture 1 value */ uint32_t capture = HAL_TIM_ReadCapturedValue(htim, TIM_CHANNEL_1); /* Set the TIM4 Capture Compare1 Register value */ __HAL_TIM_SET_COMPARE(htim, TIM_CHANNEL_1, (CCR1Val + capture)); }
int led_release(struct inode *node,struct file *myfile) { led_all_off(); return 0; }
/** * Function to process debugging module * Checks for debbunging commands and things like this */ void debug_process(void){ #ifdef CFG_SUART_RX // check for recieved commands if( suart_rxFlag ){ uint8_t cmd = suart_getc(); #if !defined(CFG_CODE_LEVEL_AVG) uint16_t tmp; #endif // process command switch(cmd){ case 'f': motor_set_speed(MOTOR_ADDR_L, 0x50, MOTOR_FORWARD); motor_set_speed(MOTOR_ADDR_R, 0x40, MOTOR_FORWARD); break; case'b': motor_set_speed(MOTOR_ADDR_L, 0x40, MOTOR_BACKWARD); motor_set_speed(MOTOR_ADDR_R, 0x43, MOTOR_BACKWARD); break; case 'z': motor_set_speed(MOTOR_ADDR_L, 0x00, MOTOR_BRAKE); motor_set_speed(MOTOR_ADDR_R, 0x00, MOTOR_BRAKE); break; #if !defined(CFG_CODE_LEVEL_AVG) case 'g': led_set_allcolors(); led_all_on(); break; case 'h': led_set_nocolors(); led_all_off(); break; #endif case 's': led_on(LED_STATUS); break; case 'r': led_off(LED_STATUS); break; case 'c': motor_set_speed(MOTOR_ADDR_L, MOTOR_SPEED_HALF, MOTOR_FORWARD); motor_set_speed(MOTOR_ADDR_R, MOTOR_SPEED_HALF, MOTOR_BACKWARD); break; case 'a': motor_set_speed(MOTOR_ADDR_L, MOTOR_SPEED_HALF, MOTOR_BACKWARD); motor_set_speed(MOTOR_ADDR_R, MOTOR_SPEED_HALF, MOTOR_FORWARD); break; #if !defined(CFG_CODE_LEVEL_AVG) case 'm': debug_send_c( motor_get_speed(MOTOR_ADDR_L), TRUE ); break; case 'n': debug_send_c( motor_get_speed(MOTOR_ADDR_R), TRUE ); break; case 'o': debug_send_c( motor_get_direction(MOTOR_ADDR_L), TRUE ); break; case 'p': debug_send_c( motor_get_direction(MOTOR_ADDR_R), TRUE ); break; case 'd': debug_send_c( motor_get_fault(MOTOR_ADDR_L), TRUE ); break; case 'e': debug_send_c( motor_get_fault(MOTOR_ADDR_R), TRUE ); break; case 'u': motor_clear_fault( MOTOR_ADDR_L ); break; case 'v': motor_clear_fault( MOTOR_ADDR_R ); break; #endif case 'i': debug_send_c( sys_robotID, TRUE ); break; case 'j': debug_send_msg( SYS_PUBLISHER, TRUE ); break; case 'k': debug_send_msg( SYS_VERSION, TRUE ); break; case 'l': debug_send_msg( SYS_NAME, TRUE ); break; case 'M': debug_send_c( motor_test(), TRUE ); break; #if !defined(CFG_CODE_LEVEL_AVG) case 'T': tmp = monitor_read_temp(MONITOR_ADDR_1); debug_send_c_wait( tmp>>8, FALSE ); debug_send_c_wait( tmp, FALSE ); tmp = monitor_read_temp(MONITOR_ADDR_2); debug_send_c_wait( tmp>>8, FALSE ); debug_send_c_wait( tmp, TRUE ); break; case 'U': tmp = monitor_read_voltage(MONITOR_ADDR_2, MONITOR_U1); debug_send_c_wait( tmp>>8, FALSE ); debug_send_c_wait( tmp, TRUE ); break; case 'V': tmp = monitor_read_voltage(MONITOR_ADDR_2, MONITOR_U4); debug_send_c_wait( tmp>>8, FALSE ); debug_send_c_wait( tmp, TRUE ); break; case 'W': tmp = monitor_read_voltage(MONITOR_ADDR_2, MONITOR_U2); debug_send_c_wait( tmp>>8, FALSE ); debug_send_c_wait( tmp, TRUE ); break; case 'X': tmp = monitor_read_voltage(MONITOR_ADDR_2, MONITOR_U3); debug_send_c_wait( tmp>>8, FALSE ); debug_send_c_wait( tmp, TRUE ); break; case 'I': tmp = monitor_read_current(MONITOR_ADDR_1, MONITOR_I1); debug_send_c_wait( tmp>>8, FALSE ); debug_send_c_wait( tmp, TRUE ); break; case 'J': tmp = monitor_read_current(MONITOR_ADDR_1, MONITOR_I2); debug_send_c_wait( tmp>>8, FALSE ); debug_send_c_wait( tmp, TRUE ); break; case 'A': tmp = monitor_read_voltage(MONITOR_ADDR_1, MONITOR_UVCC); debug_send_c_wait( tmp>>8, FALSE ); debug_send_c_wait( tmp, FALSE ); tmp = monitor_read_voltage(MONITOR_ADDR_2, MONITOR_UVCC); debug_send_c_wait( tmp>>8, FALSE ); debug_send_c_wait( tmp, TRUE ); break; case 'R': animation_set_mode(ANIMATION_MODE_RED_PULSED); break; case 'S': animation_set_mode(ANIMATION_MODE_STROBE); break; case 'F': animation_set_mode(ANIMATION_MODE_FADE); break; case 'L': animation_set_mode(ANIMATION_MODE_LADY); break; case 'N': animation_set_mode(ANIMATION_MODE_NONE); break; #endif case '?': debug_send_help(); break; default: debug_send_c( 0xff, TRUE ); break; } } #endif /* CFG_SUART_RX */ }
void led_init(void) { // Set the direction to output for the LEDs P1DIR = RED_LED | GREEN_LED; led_all_off(); }
void App_WhiskerGW() { char pubTopic[100]; char pubMsg[250]; unsigned char msgType; int counter=0; char cntStr[20]; char commandBuffer[64]; int commandBufferPointer=0; led_all_off(); // Give the unit a little time to start up // (300 ms for GS1011 and 1000 ms for GS1500) MSTimerDelay(1000); NVSettingsLoad(&GNV_Setting); led_on(4); WIFI_init(1); // Show MAC address and Version led_on(5); WIFI_Associate(); led_on(6); DisplayLCD(LCD_LINE8, "Demo starting."); DisplayLCD(LCD_LINE3, (const uint8_t *)WifiMAC); // UART if(spiUartInitialize()!=0) { DisplayLCD(LCD_LINE7, "!! SPIUART_ERROR !!"); while(1) { led_all_on(); MSTimerDelay(250); led_all_off(); MSTimerDelay(250); } } while (1) { // Do we need to connect to the AP? if (!AtLibGs_IsNodeAssociated()) { led_off(6); WIFI_Associate(); led_on(6); } else { if(mqttConnected==0) App_ConnectMqtt(); int charCount = spiUartRxBytesAvailable(); while(charCount>0) { commandBuffer[commandBufferPointer++] = spiUartGetByte(); charCount--; if(charCount==0) commandBufferPointer=0; if(commandBufferPointer>4) { if(strstr(commandBuffer,"RMPU")==commandBuffer) { if(commandBufferPointer>24) { // process response char macStr[9]; char lenStr[5]; memcpy(macStr,&commandBuffer[6],8); macStr[8] = 0; memcpy(lenStr,&commandBuffer[4],2); lenStr[2]=0; int len = (int)strtol(lenStr,0,16); unsigned long mac = strtoul(macStr,NULL,16); WhiskerModule *wm = findModule(mac); if(wm!=0) { if(commandBufferPointer>len+16) { char rssiStr[3]; memcpy(rssiStr,&commandBuffer[commandBufferPointer-3],2); rssiStr[2]=0; int rssi = (int)strtol(rssiStr,0,16); if((rssi & 0x80) == 0x80) rssi-=256; int puMsgPointer=14; mqtt_initJsonMsg(pubMsg); mqtt_addStringValToMsg("Name",wm->Name,pubMsg,0); mqtt_addStringValToMsg("Mac",macStr,pubMsg,1); char rstr[8]; sprintf(rstr,"%d dbm",rssi); mqtt_addStringValToMsg("Rssi",rstr,pubMsg,1); sprintf(pubMsg+strlen(pubMsg),",\"Values\":{"); puMsgPointer=14; int comma=0; while(puMsgPointer < (commandBufferPointer-3)) { char cidStr[3]; memcpy(cidStr,&commandBuffer[puMsgPointer],2); puMsgPointer+=2; cidStr[2]=0; unsigned char cid=(unsigned char)strtol(cidStr,0,16); unsigned char channel = cid & 0x1f; char valStr[9]; long valInt; switch(cid) { case 0x21: //digital input memcpy(valStr,&commandBuffer[puMsgPointer],2); valStr[2]=0; puMsgPointer+=2; valInt = (int)strtol(valStr,0,16); if(valInt) mqtt_addStringValToMsg("DIN1","True",pubMsg,comma); else mqtt_addStringValToMsg("DIN1","False",pubMsg,comma); break; case 0x22: //digital input memcpy(valStr,&commandBuffer[puMsgPointer],2); valStr[2]=0; puMsgPointer+=2; valInt = (int)strtol(valStr,0,16); if(valInt) mqtt_addStringValToMsg("DIN2","True",pubMsg,comma); else mqtt_addStringValToMsg("DIN2","False",pubMsg,comma); break; case 0x43: //battery analog in memcpy(valStr,&commandBuffer[puMsgPointer],4); valStr[4]=0; puMsgPointer+=4; valInt = (int)strtol(valStr,0,16); mqtt_addIntValToMsg("Battery",valInt,pubMsg,comma); break; case 0x44: //battery analog in memcpy(valStr,&commandBuffer[puMsgPointer],4); valStr[4]=0; puMsgPointer+=4; valInt = (int)strtol(valStr,0,16); mqtt_addIntValToMsg("Temperature",valInt,pubMsg,comma); break; case 0x45: //battery analog in memcpy(valStr,&commandBuffer[puMsgPointer],4); valStr[4]=0; puMsgPointer+=4; valInt = (int)strtol(valStr,0,16); mqtt_addIntValToMsg("RH",valInt,pubMsg,comma); break; case 0x5d: //internal temperature memcpy(valStr,&commandBuffer[puMsgPointer],4); valStr[4]=0; puMsgPointer+=4; valInt = (int)strtol(valStr,0,16); mqtt_addIntValToMsg("IntTemp",valInt,pubMsg,comma); break; case 0x57: //air quality memcpy(valStr,&commandBuffer[puMsgPointer],4); valStr[4]=0; puMsgPointer+=4; valInt = (int)strtol(valStr,0,16); mqtt_addIntValToMsg("AirQual",valInt,pubMsg,comma); break; case 0x58: //air quality memcpy(valStr,&commandBuffer[puMsgPointer],4); valStr[4]=0; puMsgPointer+=4; valInt = (int)strtol(valStr,0,16); mqtt_addIntValToMsg("AirQual",valInt,pubMsg,comma); break; case 0x61: // digital counter input memcpy(valStr,&commandBuffer[puMsgPointer],4); valStr[4]=0; puMsgPointer+=4; valInt = (int)strtol(valStr,0,16); mqtt_addIntValToMsg("Count1",valInt,pubMsg,comma); break; case 0x62: // digital counter input memcpy(valStr,&commandBuffer[puMsgPointer],4); valStr[4]=0; puMsgPointer+=4; valInt = (int)strtol(valStr,0,16); mqtt_addIntValToMsg("Count2",valInt,pubMsg,comma); break; } comma=1; } sprintf(pubMsg+strlen(pubMsg),"}"); mqtt_finishJsonMsg(pubMsg); sprintf(pubTopic, "%s/%s", WIO_DOMAIN, macStr); int res=mqtt_publish(&broker, pubTopic, pubMsg,0)<0; if(res<0) mqttConnected=0; led_on(8); //spiUartResetFIFO(); } } } } } } // Send data if RSSIReading(); AtLibGs_WaitForTCPMessage(1000); led_off(7); led_off(8); if(G_receivedCount>0) { AtLibGs_ParseTCPData(G_received,G_receivedCount,&rxm); msgType = MQTTParseMessageType(rxm.message); switch(msgType) { case MQTT_MSG_SUBACK: // todo: display subscription acknowledgement break; case MQTT_MSG_PUBLISH: App_MQTTMsgPublished(); break; case MQTT_MSG_PUBACK: // todo: display publish acknowledgement break; default: break; } } counter++; sprintf(cntStr,"Counter=%d",counter); DisplayLCD(LCD_LINE6,cntStr); if(counter>30) { counter=0; sprintf(pubTopic, "%s/%s", WIO_DOMAIN, WifiMAC); mqtt_initJsonMsg(pubMsg); mqtt_addStringValToMsg("msg","status ok",pubMsg,0); mqtt_finishJsonMsg(pubMsg); int res1=mqtt_publish(&broker, pubTopic, pubMsg,0)<0; if(res1<0) mqttConnected=0; led_on(7); } } // Send data if END } }
/***************** The uNabto application logic ***************** * This is where the user implements his/her own functionality * to the device. When a Nabto message is received, this function * gets called with the message's request id and parameters. * Afterwards a user defined message can be sent back to the * requesting browser. ****************************************************************/ application_event_result application_event(application_request* request, buffer_read_t* read_buffer, buffer_write_t* write_buffer) { switch(request->queryId) { case 1: { /** Get acceleration data */ extern int16_t gAccData[3]; uint16_t acc_x; uint16_t acc_y; uint16_t acc_z; // Get accelerometer data and calculate yaw, pitch and roll with offset Accelerometer_Get(); acc_x = gAccData[0] + 0xFF; acc_y = gAccData[1] + 0xFF; acc_z = gAccData[2] + 0xFF; // Write back data if (!buffer_write_uint16(write_buffer, acc_x)) return AER_REQ_RSP_TOO_LARGE; if (!buffer_write_uint16(write_buffer, acc_y)) return AER_REQ_RSP_TOO_LARGE; if (!buffer_write_uint16(write_buffer, acc_z)) return AER_REQ_RSP_TOO_LARGE; return AER_REQ_RESPONSE_READY; } case 2: { /** Get temperature data */ uint16_t temp; temp = Temperature_Get(); // Write back data if (!buffer_write_uint16(write_buffer, temp)) return AER_REQ_RSP_TOO_LARGE; return AER_REQ_RESPONSE_READY; } case 3: { /** Get light level */ uint16_t light; light = LightSensor_Get(); // Write back data if (!buffer_write_uint16(write_buffer, light)) return AER_REQ_RSP_TOO_LARGE; return AER_REQ_RESPONSE_READY; } case 4: { /** Get potentiometer data */ uint32_t pot; pot = Potentiometer_Get(); // Write back data if (!buffer_write_uint32(write_buffer, pot)) return AER_REQ_RSP_TOO_LARGE; return AER_REQ_RESPONSE_READY; } case 5: { /** Get button status */ uint8_t button1; uint8_t button2; uint8_t button3; button1 = Switch1IsPressed(); button2 = Switch2IsPressed(); button3 = Switch3IsPressed(); // Write back data if (!buffer_write_uint8(write_buffer, button1)) return AER_REQ_RSP_TOO_LARGE; if (!buffer_write_uint8(write_buffer, button2)) return AER_REQ_RSP_TOO_LARGE; if (!buffer_write_uint8(write_buffer, button3)) return AER_REQ_RSP_TOO_LARGE; return AER_REQ_RESPONSE_READY; } case 6: { /** Get sound level */ uint32_t sound; sound = Microphone_Get(); // Write back data if (!buffer_write_uint32(write_buffer, sound)) return AER_REQ_RSP_TOO_LARGE; return AER_REQ_RESPONSE_READY; } case 7: { /** Set LED */ uint16_t led; // Read parameters in request if (!buffer_read_uint16(read_buffer, &led)) return AER_REQ_TOO_SMALL; if (led == 1) { led_all_on(); } else { led_all_off(); } // Write back data if (!buffer_write_uint16(write_buffer, led)) return AER_REQ_RSP_TOO_LARGE; return AER_REQ_RESPONSE_READY; } } return AER_REQ_INV_QUERY_ID; }