void setDCState_command(char *property, mico_Context_t * const inContext)
{
  if(0==strcmp(property, "DC 1")){//直流电机转动
    dc_motor_set(1);
  }else if(0==strcmp(property, "DC 0")){
    dc_motor_set(0);
  } 
}
void setDCState_command(char *property, app_context_t * const inContext)
{
  if(0==strcmp(property, "DC 1")){  // dc motor on
    dc_motor_set(1);
  }else if(0==strcmp(property, "DC 0")){
    dc_motor_set(0);
  } 
}
예제 #3
0
파일: user_main.c 프로젝트: wangeshen/MICO
OSStatus user_modules_init(void)
{
  OSStatus err = kUnknownErr;
  
  // init DC Motor(GPIO)
  dc_motor_init();
  dc_motor_set(0);   // off
  
  // init RGB LED(P9813)
  hsb2rgb_led_init();
  hsb2rgb_led_open(0, 0, 0);  // off
  
  // init OLED
  OLED_Init();
  //OLED_Clear();
  LCD_Clear(0x00);
  OLED_ShowString(20,0,"M X C H I P");
  OLED_ShowString(20,3,(uint8_t*)DEFAULT_DEVICE_NAME); 
  OLED_ShowString(0,6,"T: 0C  H: 0%");
  
  // init Light sensor(ADC)
  light_sensor_init();
  
  // init infrared sensor(ADC)
  infrared_reflective_init();
  
  // init user key1 && key2
  user_key1_init();
  user_key2_init();
  
  err = kNoErr;
 
  return err;
}
예제 #4
0
void init_platform( void )
{
  button_init_t init;

  MicoGpioInitialize( (mico_gpio_t)MICO_SYS_LED, OUTPUT_PUSH_PULL );
  MicoGpioOutputLow( (mico_gpio_t)MICO_SYS_LED );
  MicoGpioInitialize( (mico_gpio_t)MICO_RF_LED, OUTPUT_OPEN_DRAIN_NO_PULL );
  MicoGpioOutputHigh( (mico_gpio_t)MICO_RF_LED );
  
  MicoGpioInitialize((mico_gpio_t)BOOT_SEL, INPUT_PULL_UP);
  MicoGpioInitialize((mico_gpio_t)MFG_SEL, INPUT_PULL_UP);

  init.gpio = EasyLink_BUTTON;
  init.pressed_func = PlatformEasyLinkButtonClickedCallback;
  init.long_pressed_func = PlatformEasyLinkButtonLongPressedCallback;
  init.long_pressed_timeout = 5000;

  button_init( IOBUTTON_EASYLINK, init );
  
#ifdef USE_MiCOKit_EXT
  dc_motor_init( );
  dc_motor_set( 0 );
  
  rgb_led_init();
  rgb_led_open(0, 0, 0);
#endif
}
예제 #5
0
void init_platform( void )
{
  MicoGpioInitialize( (mico_gpio_t)MICO_SYS_LED, OUTPUT_PUSH_PULL );
  MicoGpioOutputLow( (mico_gpio_t)MICO_SYS_LED );
  MicoGpioInitialize( (mico_gpio_t)MICO_RF_LED, OUTPUT_OPEN_DRAIN_NO_PULL );
  MicoGpioOutputHigh( (mico_gpio_t)MICO_RF_LED );
  
 // MicoGpioInitialize((mico_gpio_t)BOOT_SEL, INPUT_PULL_UP);
  //MicoGpioInitialize((mico_gpio_t)MFG_SEL, INPUT_PULL_UP);
  
  //  Initialise EasyLink buttons
  MicoGpioInitialize( (mico_gpio_t)EasyLink_BUTTON, INPUT_PULL_UP );
  mico_init_timer(&_button_EL_timer, RestoreDefault_TimeOut, _button_EL_Timeout_handler, NULL);
  MicoGpioEnableIRQ( (mico_gpio_t)EasyLink_BUTTON, IRQ_TRIGGER_BOTH_EDGES, _button_EL_irq_handler, NULL );

  //MicoFlashInitialize( MICO_SPI_FLASH );
  
#ifdef USE_MiCOKit_EXT
  dc_motor_init( );
  dc_motor_set( 0 );
  
  rgb_led_init();
  rgb_led_open(0, 0, 0);
#endif
}
예제 #6
0
파일: user_main.c 프로젝트: wangeshen/MICO
void user_key2_long_pressed_callback(void)
{
  user_log_trace();
  
  user_log("user_key2_long_pressed_callback");
  dc_motor_set(1);   // dc motor test
  
  return;
}
예제 #7
0
파일: user_main.c 프로젝트: wangeshen/MICO
// Key2 callback: do DC Motor test
void user_key2_clicked_callback(void)
{
  user_log_trace();
  
  user_log("user_key2_clicked_callback");
  dc_motor_set(0);  // dc motor test
  
  return;
}
예제 #8
0
// set function: set dc motor switch value 
int dc_motor_switch_set(struct mico_prop_t *prop, void *arg, void *val, uint32_t val_len)
{
  int value = 0;
  
  value = *((int*)val);
  dc_motor_set(value);

  return 0;  // set ok
}
예제 #9
0
void init_platform( void )
{
    MicoGpioInitialize( (mico_gpio_t)MICO_SYS_LED, OUTPUT_PUSH_PULL );
    MicoGpioOutputLow( (mico_gpio_t)MICO_SYS_LED );
    MicoGpioInitialize( (mico_gpio_t)MICO_RF_LED, OUTPUT_OPEN_DRAIN_NO_PULL );
    MicoGpioOutputHigh( (mico_gpio_t)MICO_RF_LED );

    //  Initialise EasyLink buttons
    MicoGpioInitialize( (mico_gpio_t)EasyLink_BUTTON, INPUT_HIGH_IMPEDANCE );
    mico_init_timer(&_button_EL_timer, RestoreDefault_TimeOut, _button_EL_Timeout_handler, NULL);
    MicoGpioEnableIRQ( (mico_gpio_t)EasyLink_BUTTON, IRQ_TRIGGER_BOTH_EDGES, _button_EL_irq_handler, NULL );

#ifdef USE_MiCOKit_EXT
    dc_motor_init( );
    dc_motor_set( 0 );
#endif
}
/** Handle a command specific to the specification for this device */
void handleSpecificationCommand(byte* payload, unsigned int length) {
  ArduinoCustom__Header header;
  
  memset(buffer,0,300);
  ArduinoCustom_testData testEvents;
  
  pb_istream_t stream = pb_istream_from_buffer(payload, length);
  if (pb_decode_delimited(&stream, ArduinoCustom__Header_fields, &header)) {
    baseEvents_log("Decoded header for custom command.");
    if (header.command == ArduinoCustom_Command_RGB_LED) {
      if (pb_decode_delimited(&stream, ArduinoCustom_RGB_fields, &RGB_LED)) {
        baseEvents_log("Command: RGB_LED set(h=%d, s=%d, b=%d)", 
                       RGB_LED.rgbled_h, RGB_LED.rgbled_s, RGB_LED.rgbled_b);
        hsb2rgb_led_open(RGB_LED.rgbled_h, RGB_LED.rgbled_s, RGB_LED.rgbled_b);
      }
    }
    else if (header.command == ArduinoCustom_Command_DC_MOTOR) {
      ArduinoCustom_DC_MOTOR dc_motor;
      if (pb_decode_delimited(&stream, ArduinoCustom__Header_fields, &dc_motor)) {
        baseEvents_log("Command: DC_MOTOR set: %d", dc_motor.motor_sw);
        dc_motor_set(dc_motor.motor_sw);
      }
    }
    else if (header.command == ArduinoCustom_Command_PING) {
      ArduinoCustom_ping ping;
      if (pb_decode_delimited(&stream, ArduinoCustom_ping_fields, &ping)) {
        handlePing(ping, header.originator);
      }
    } 
    else if (header.command == ArduinoCustom_Command_TESTEVENTS) {
      if (pb_decode_delimited(&stream, ArduinoCustom_testEvents_fields, &testEvents)) {
         handleTestEvents(testEvents, header.originator);
      }
    } 
    else if (header.command == ArduinoCustom_Command_SERIALPRINTLN) {
      ArduinoCustom_serialPrintln serialPrintln;
      if (pb_decode_delimited(&stream, ArduinoCustom_serialPrintln_fields, &serialPrintln)) {
        handleSerialPrintln(serialPrintln,header.originator);
      }
    }
    else {
      baseEvents_log("Unknown command.");
    }
  }
}
예제 #11
0
void init_platform_bootloader( void )
{
    MicoGpioInitialize( (mico_gpio_t)MICO_SYS_LED, OUTPUT_PUSH_PULL );
    MicoGpioOutputLow( (mico_gpio_t)MICO_SYS_LED );
    MicoGpioInitialize( (mico_gpio_t)MICO_RF_LED, OUTPUT_OPEN_DRAIN_NO_PULL );
    MicoGpioOutputHigh( (mico_gpio_t)MICO_RF_LED );

    MicoGpioInitialize((mico_gpio_t)BOOT_SEL, INPUT_PULL_UP);
    MicoGpioInitialize((mico_gpio_t)MFG_SEL, INPUT_HIGH_IMPEDANCE);

#ifdef USE_MiCOKit_EXT
    dc_motor_init( );
    dc_motor_set( 0 );

    rgb_led_init();
    rgb_led_open(0, 0, 0);
#endif
}
예제 #12
0
//------------------------------------- API ------------------------------------
OSStatus user_modules_init(void)
{
  OSStatus err = kUnknownErr;
  char oled_show_line[16] = {'\0'};   // max char each line
  
  // init DC Motor(GPIO)
  dc_motor_init();
  dc_motor_set(0);   // off
  
  // init RGB LED(P9813)
  rgb_led_init();
  rgb_led_open(0, 0, 0);  // off
  
  // init OLED
  OLED_Init();
  OLED_Clear();
  snprintf(oled_show_line, 16, "%s", (uint8_t*)DEV_KIT_MANUFACTURER);
  OLED_ShowString(0,0,(uint8_t*)oled_show_line);
  memset(oled_show_line, '\0', 16);
  snprintf(oled_show_line, 16, "%s", (uint8_t*)DEV_KIT_NAME);
  OLED_ShowString(0,3,(uint8_t*)oled_show_line);
  OLED_ShowString(0,6,"Starting...     ");
  
  // init Light sensor(ADC)
  light_sensor_init();
  
  // init infrared sensor(ADC)
  infrared_reflective_init();
  
  // init user key1 && key2
  user_key1_init();
  user_key2_init();
  
  err = temp_hum_sensor_init();
  
  return err;
}
예제 #13
0
void micokit_ext_mfg_test(mico_Context_t *inContext)
{
  OSStatus err = kUnknownErr;
  char str[64] = {'\0'};
  char mac[6];
  
  int rgb_led_hue = 0;
  
  uint8_t dht11_ret = 0;
  uint8_t dht11_temp_data = 0;
  uint8_t dht11_hum_data = 0;
  
  int light_ret = 0;
  uint16_t light_sensor_data = 0;
  
  int infrared_ret = 0;
  uint16_t infrared_reflective_data = 0;
  
  int32_t bme280_temp = 0;
  uint32_t bme280_hum = 0;
  uint32_t bme280_press = 0;
  
  UNUSED_PARAMETER(inContext);
  
  mico_rtos_init_semaphore(&mfg_test_state_change_sem, 1); 
  err = MICOAddNotification( mico_notify_WIFI_SCAN_COMPLETED, (void *)mico_notify_WifiScanCompleteHandler );
  require_noerr( err, exit );
  
  while(1){
    switch(mfg_test_module_number){
    case 0:  // mfg mode start
      {
        sprintf(str, "%s\r\nStart:\r\n%s\r\n%s", "TEST MODE", "  next: Key2", "  prev: Key1");
        mf_printf(str);
        while(kNoErr != mico_rtos_get_semaphore(&mfg_test_state_change_sem, MICO_WAIT_FOREVER));
        break;
      }
    case 1:  // OLED
      {
        while(kNoErr != mico_rtos_get_semaphore(&mfg_test_state_change_sem, 0))
        {
          sprintf(str, "%s OLED\r\n", OLED_MFG_TEST_PREFIX);
          mf_printf(str);
          mico_thread_msleep(300);
          
          mf_printf(mfg_test_oled_test_string);
          mico_thread_msleep(300);
        }
        OLED_Clear();
        break;
      }
    case 2:  // RGB_LED
      {
        sprintf(str, "%s RGB LED\r\nBlink: \r\n      R=>G=>B", OLED_MFG_TEST_PREFIX);
        mf_printf(str);
        
        while(kNoErr != mico_rtos_get_semaphore(&mfg_test_state_change_sem, 0))
        {
          hsb2rgb_led_open(rgb_led_hue, 100, 50);
          rgb_led_hue += 120;
          if(rgb_led_hue >= 360){
            rgb_led_hue = 0;
          }
          mico_thread_msleep(300);
        }
        hsb2rgb_led_open(0, 0, 0);
        break;
      }
    case 3: // infrared sensor
      {
        while(kNoErr != mico_rtos_get_semaphore(&mfg_test_state_change_sem, 0))
        {
          infrared_ret = infrared_reflective_read(&infrared_reflective_data);
          if(0 == infrared_ret){ 
            sprintf(str, "%s Infrared\r\nInfrared: %d", OLED_MFG_TEST_PREFIX,
                    infrared_reflective_data);
            mf_printf(str);
          }
          mico_thread_msleep(300);
        }
        break;
      }
    case 4: // DC Motor
      {
        sprintf(str, "%s DC Motor\r\nRun:\r\n     on : 500ms\r\n     off: 500ms", OLED_MFG_TEST_PREFIX);
        mf_printf(str);
        
        while(kNoErr != mico_rtos_get_semaphore(&mfg_test_state_change_sem, 0))
        {
          dc_motor_set(1);
          mico_thread_msleep(500);
          dc_motor_set(0);
          mico_thread_msleep(500);
        }
        dc_motor_set(0);
        break;
      }
    case 5: // BME280
      {
        while(kNoErr != mico_rtos_get_semaphore(&mfg_test_state_change_sem, 0))
        {
          err = bme280_sensor_init();
          if(kNoErr != err){
            sprintf(str, "%s BME280\r\nMoule not found!", OLED_MFG_TEST_PREFIX);
            mf_printf(str);
            // goto next mdoule
            mico_thread_msleep(500);
            mfg_test_module_number = (mfg_test_module_number+1)%(MFG_TEST_MAX_MODULE_NUM+1);
            break;
          }
          else{
            err = bme280_data_readout(&bme280_temp, &bme280_press, &bme280_hum);
            if(kNoErr == err){
              sprintf(str, "%s BME280\r\nT: %3.1fC\r\nH: %3.1f%%\r\nP: %5.2fkPa", OLED_MFG_TEST_PREFIX,
                      (float)bme280_temp/100, (float)bme280_hum/1024, (float)bme280_press/1000);
              mf_printf(str);
            }
            else{
              sprintf(str, "%s BME280\r\nRead error!", OLED_MFG_TEST_PREFIX);
              mf_printf(str);
            }
          }
          mico_thread_msleep(500);
        }
        break;
      }
    case 6: // DHT11
      {
        while(kNoErr != mico_rtos_get_semaphore(&mfg_test_state_change_sem, 0))
        {
          dht11_ret = DHT11_Read_Data(&dht11_temp_data, &dht11_hum_data);
          if(0 == dht11_ret){
            sprintf(str, "%s DHT11\r\nT: %3.1fC\r\nH: %3.1f%%", OLED_MFG_TEST_PREFIX,
                    (float)dht11_temp_data, (float)dht11_hum_data);
            mf_printf(str);
          }
          mico_thread_sleep(1);   // DHT11 must >= 1s
        }
        break;
      }
    case 7:   // Light sensor
      {
        while(kNoErr != mico_rtos_get_semaphore(&mfg_test_state_change_sem, 0))
        {
          light_ret = light_sensor_read(&light_sensor_data);
          if(0 == light_ret){
            sprintf(str, "%s Light\r\nLight: %d", OLED_MFG_TEST_PREFIX,
                    light_sensor_data);
            mf_printf(str);
          }
          mico_thread_msleep(300);
        }
        break;
      }
    case 8: // wifi
      {
        wlan_get_mac_address(mac);
        sprintf(str, "%s Wi-Fi\r\nMAC:\r\n    %02X%02X%02X%02X%02X%02X", OLED_MFG_TEST_PREFIX,
                mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
        mf_printf(str);
        //mico_thread_msleep(500);
        
        scanap_done = false;
        micoWlanStartScan();
        while((!scanap_done) || (kNoErr != mico_rtos_get_semaphore(&mfg_test_state_change_sem, MICO_WAIT_FOREVER)));
        break;
      }
    default:
      goto exit;  // error
      break;
    }
  }
  
exit:
  mico_thread_sleep(MICO_NEVER_TIMEOUT);
}
예제 #14
0
void init_platform_bootloader( void )
{
  CRC8_Context crc;
  OSStatus err = kNoErr;
  mico_logic_partition_t *rf_partition = MicoFlashGetInfo( MICO_PARTITION_RF_FIRMWARE );
  
  MicoGpioInitialize( (mico_gpio_t)MICO_SYS_LED, OUTPUT_PUSH_PULL );
  MicoGpioOutputLow( (mico_gpio_t)MICO_SYS_LED );
  MicoGpioInitialize( (mico_gpio_t)MICO_RF_LED, OUTPUT_OPEN_DRAIN_NO_PULL );
  MicoGpioOutputHigh( (mico_gpio_t)MICO_RF_LED );
  
  MicoGpioInitialize((mico_gpio_t)BOOT_SEL, INPUT_PULL_UP);
  MicoGpioInitialize((mico_gpio_t)MFG_SEL, INPUT_PULL_UP);
  
#ifdef USE_MiCOKit_EXT
  dc_motor_init( );
  dc_motor_set( 0 );
  
  rgb_led_init();
  rgb_led_open(0, 0, 0);
#endif
  
  /* Specific operations used in EMW3165 production */
#define NEED_RF_DRIVER_COPY_BASE    ((uint32_t)0x08008000)
#define TEMP_RF_DRIVER_BASE         ((uint32_t)0x08040000)
#define TEMP_RF_DRIVER_END          ((uint32_t)0x0807FFFF)
  
  const uint8_t isDriverNeedCopy = *(uint8_t *)(NEED_RF_DRIVER_COPY_BASE);
  const uint32_t totalLength = rf_partition->partition_length;
  const uint8_t crcResult = *(uint8_t *)(TEMP_RF_DRIVER_END);
  uint8_t targetCrcResult = 0;
  
  uint32_t copyLength;
  uint32_t destStartAddress_tmp = rf_partition->partition_start_addr;
  uint32_t sourceStartAddress_tmp = TEMP_RF_DRIVER_BASE;
  uint32_t i;
  
  if ( isDriverNeedCopy != 0x0 )
    return;
  
  platform_log( "Bootloader start to copy RF driver..." );
  /* Copy RF driver to SPI flash */

  err = platform_flash_init( &platform_flash_peripherals[ MICO_FLASH_SPI ] );
  require_noerr(err, exit);
  err = platform_flash_init( &platform_flash_peripherals[ MICO_FLASH_EMBEDDED ] );
  require_noerr(err, exit);
  err = platform_flash_erase( &platform_flash_peripherals[ MICO_FLASH_SPI ], 
    rf_partition->partition_start_addr, rf_partition->partition_start_addr + rf_partition->partition_length - 1 );
  require_noerr(err, exit);
  platform_log( "Time: %d", mico_get_time_no_os() );
  
  for(i = 0; i <= totalLength/SizePerRW; i++){
    if( i == totalLength/SizePerRW ){
      if(totalLength%SizePerRW)
        copyLength = totalLength%SizePerRW;
      else
        break;
    }else{
      copyLength = SizePerRW;
    }
    printf(".");
    err = platform_flash_read( &platform_flash_peripherals[ MICO_FLASH_EMBEDDED ], &sourceStartAddress_tmp, data , copyLength );
    require_noerr( err, exit );
    err = platform_flash_write( &platform_flash_peripherals[ MICO_FLASH_SPI ], &destStartAddress_tmp, data, copyLength );
    require_noerr(err, exit);
  }
  
  printf("\r\n");
  /* Check CRC-8 check-sum */
  platform_log( "Bootloader start to verify RF driver..." );
  sourceStartAddress_tmp = TEMP_RF_DRIVER_BASE;
  destStartAddress_tmp = rf_partition->partition_start_addr;
  
  CRC8_Init( &crc );
  for(i = 0; i <= totalLength/SizePerRW; i++){
    if( i == totalLength/SizePerRW ){
      if(totalLength%SizePerRW)
        copyLength = totalLength%SizePerRW;
      else
        break;
    }else{
      copyLength = SizePerRW;
    }
    printf(".");
    err = platform_flash_read( &platform_flash_peripherals[ MICO_FLASH_SPI ], &destStartAddress_tmp, data, copyLength );
    require_noerr( err, exit );   
      
    CRC8_Update( &crc, data, copyLength);
  }
  CRC8_Final( &crc, &targetCrcResult );
  
  printf("\r\n");
  //require_string( crcResult == targetCrcResult, exit, "Check-sum error" ); 
  if( crcResult != targetCrcResult ){
    platform_log("Check-sum error");
    while(1);
  }
  /* Clear RF driver from temperary storage */
  platform_log("Bootloader start to clear RF driver temporary storage...");
  
  /* Clear copy tag */
  err = platform_flash_erase( &platform_flash_peripherals[ MICO_FLASH_EMBEDDED ], NEED_RF_DRIVER_COPY_BASE, NEED_RF_DRIVER_COPY_BASE);
  require_noerr(err, exit);
  
exit:
  return;
}
//------------------------------------- API ------------------------------------
OSStatus micokit_STmems_init(void)
{
  OSStatus err = kUnknownErr;
#if defined(MICOKIT_STMEMS_KEY1)||defined(MICOKIT_STMEMS_KEY2)
  button_init_t init;
#endif

  //init RGB LED(P9813)
  rgb_led_init();
  rgb_led_close();  // off
  
  dc_motor_init();
  dc_motor_set(0);   // off
  
  // init OLED
  OLED_Init();

  OLED_ShowString(OLED_DISPLAY_COLUMN_START, OLED_DISPLAY_ROW_1,  (uint8_t*)MODEL);
  OLED_ShowString(OLED_DISPLAY_COLUMN_START, OLED_DISPLAY_ROW_2, (uint8_t*)"MiCO            ");
  OLED_ShowString(OLED_DISPLAY_COLUMN_START, OLED_DISPLAY_ROW_3, (uint8_t*)"   Starting... ");
  OLED_ShowString(OLED_DISPLAY_COLUMN_START, OLED_DISPLAY_ROW_4, (uint8_t*)"                ");

#ifdef MICOKIT_STMEMS_KEY1
  init.gpio = MICOKIT_STMEMS_KEY1;
  init.pressed_func = micokit_STmems_key1_clicked_callback;
  init.long_pressed_func = NULL;
  init.long_pressed_timeout = 5000;
  button_init( IOBUTTON_USER_1, init);
#endif

#ifdef MICOKIT_STMEMS_KEY2
  init.gpio = MICOKIT_STMEMS_KEY2;
  init.pressed_func = micokit_STmems_key2_clicked_callback;
  init.long_pressed_func = NULL;
  init.long_pressed_timeout = 5000;
  button_init( IOBUTTON_USER_2, init);
#endif
    
  /*init HTS221 */
  err = hts221_sensor_init();
  require_noerr_string( err, exit, "ERROR: Unable to Init HTS221" );
  
  /*init UVIS25 */
  err = uvis25_sensor_init();
  require_noerr_string( err, exit, "ERROR: Unable to Init UVIS25" );
  
  /*init LSM9DS1_ACC_GYR */
  err = lsm9ds1_acc_gyr_sensor_init();
  require_noerr_string( err, exit, "ERROR: Unable to Init LSM9DS1_ACC_GYR" );
  
  err = lsm9ds1_mag_sensor_init();
  require_noerr_string( err, exit, "ERROR: Unable to Init LSM9DS1_MAG" );
  
  /*init LPS25HB */
  err = lps25hb_sensor_init();
  require_noerr_string( err, exit, "ERROR: Unable to Init LPS25HB" );
  
  light_sensor_init();
   
exit:
  return err;
}