コード例 #1
0
ファイル: ConfEH.cpp プロジェクト: mpfusion/sentio-framework
void CONFEH::getMeasurements( float &storageVoltage, float &solarVoltage, float &solarCurrent )
{
	// Configure LTC2990 for Current-Voltage-Voltage measurement (using 1 ohm sense resistor)
	setLTC_Config( celsius, single, V1_V2V3V4, 1, 0 );
	triggerConversion();

	// Read the storage voltage
	if ( storageType == DLC )
		readVoltage( storageVoltage, Voltage_V3 );
	else if ( storageType == BAT )
		readVoltage( storageVoltage, Voltage_V4 );

	// Read the solar current
	readCurrent( solarCurrent, Current_V12 );

	// Check for LTC3105 reset condition
	if ( solarCurrent < 0.001 )
	{
		// Reset LTC3105
		setLTC3105_EN( false );
		setLTC3105_EN( true );
	}

	// Re-configure LTC2990 for pure voltage measurement
	setLTC_Config( celsius, single, V1V2V3V4, 1, 0 );
	triggerConversion();
	// Read the solar voltage
	readVoltage( solarVoltage, Voltage_V1 );
}
コード例 #2
0
float getVoltage(int id) {
  float voltage = readVoltage(id);
 
  // Substract voltages from previous batteries (if any) in the serial bank
  
  if (id > 0) {
    return voltage - readVoltage(id-1);
  } else {
    return voltage;
  }
}
コード例 #3
0
ファイル: SuperIOFamily.cpp プロジェクト: Beshuta/HWSensors
bool SuperIOMonitor::updateSensor(const char *key, const char *type, unsigned char size, SuperIOSensorGroup group, unsigned long index)
{
	long value = 0;
	
	switch (group) {
		case kSuperIOTemperatureSensor:
			value = readTemperature(index);
			break;
		case kSuperIOVoltageSensor:
			value = readVoltage(index);
			break;
		case kSuperIOTachometerSensor:
			value = readTachometer(index);
			break;
		default:
			break;
	}

	if (strcmp(type, TYPE_FP2E) == 0) {
		value = encode_fp2e(value);
	}
	else if (strcmp(type, TYPE_FPE2) == 0) {
		value = encode_fpe2(value);
	}
	
	if (kIOReturnSuccess != fakeSMC->callPlatformFunction(kFakeSMCSetKeyValue, true, (void*)key, (void*)size, (void*)&value, 0))
		return false;
	
	return true;
}
コード例 #4
0
bool LPCSensors::willReadSensorValue(FakeSMCSensor *sensor, float *outValue)
{
    if (sensor) {
        switch (sensor->getGroup()) {
            case kFakeSMCTemperatureSensor:
                *outValue = sensor->getOffset() + readTemperature(sensor->getIndex());
                break;

            case kFakeSMCVoltageSensor: {
                float v = readVoltage(sensor->getIndex());
                *outValue = sensor->getOffset() + v + (v - sensor->getReference()) * sensor->getGain();
                break;
            }

            case kFakeSMCTachometerSensor:
                *outValue = readTachometer(sensor->getIndex());
                break;

            case kLPCSensorsFanManualSwitch:
            case kLPCSensorsFanMinController:
            case kLPCSensorsFanTargetController:
            default:
                // Just return stored key value
                return false;
        }

        return true;
    }

	return false;
}
コード例 #5
0
/******************************************************************************
 * @fn          sendReport
 *
 * @brief       Send sensor report
 *
 * @param       none
 *              
 * @return      none
 */
static void sendReport(void)
{
  uint8 pData[SENSOR_REPORT_LENGTH];
  static uint8 reportNr=0;
  uint8 txOptions;
  
  // Read and report temperature value
  pData[SENSOR_TEMP_OFFSET] =  readTemp();
  
  // Read and report voltage value
  pData[SENSOR_VOLTAGE_OFFSET] = readVoltage(); 
    
  pData[SENSOR_PARENT_OFFSET] =  HI_UINT16(parentShortAddr);
  pData[SENSOR_PARENT_OFFSET + 1] =  LO_UINT16(parentShortAddr);
  
  // Set ACK request on each ACK_INTERVAL report
  // If a report failed, set ACK request on next report
  if ( ++reportNr<ACK_REQ_INTERVAL && reportFailureNr==0 ) 
  {
    txOptions = AF_TX_OPTIONS_NONE;
  }
  else 
  {
    txOptions = AF_MSG_ACK_REQUEST;
    reportNr = 0;
  }
  // Destination address 0xFFFE: Destination address is sent to previously
  // established binding for the commandId.
  zb_SendDataRequest( 0xFFFE, SENSOR_REPORT_CMD_ID, SENSOR_REPORT_LENGTH, pData, 0, txOptions, 0 );
}
コード例 #6
0
ファイル: Battery.cpp プロジェクト: nanoflite/open-altimeter
void Battery::test()
{
  printMessage(BATTERY_TEST_MESSAGE);
  printMessage(BATTERY_MESSAGE);
  float v = readVoltage();
  Serial.println(v);
  // the voltage must be between 4.8 and 5.1 to pass the test
  if (v < 5.08 && v > 4.92) printMessage(TEST_PASS_MESSAGE);
  else printMessage(TEST_FAIL_MESSAGE);
}
コード例 #7
0
void displayVoltages2(){
  char buffer[BUFSIZE];

  lcd.setCursor(0, 0);
  
  for (int i=0; i < countVoltagePins; i++) {
    ftoa(buffer, readVoltage(i), 1);
    lcd.print(buffer);
    lcd.print(" ");
  }
}
コード例 #8
0
ファイル: slave.c プロジェクト: athind94/sunswift.battery
int main (void) {
	int on=0, ID, calb;
	
	int batt_voltage = 0;    
	
	//init();
	//ID = readID();
	//calb = readCalibration();
	//	GPIO_SetValue(RED_LED_PORT, RED_LED_BIT,1);

	int i = 0; /* Used in main loop */
	uint32_t value = 0xaa;
	setup_ports();
	
	sc_time_t one_sec_timer = sc_get_timer(); /* Initialise the timer variable */
	sc_time_t test_in_timer = sc_get_timer(); /* Initialise the timer variable */

	
	/* Set LEDs to known states, i.e. on */
	red_led(ON);
	yellow_led(ON);
	
	
	
	GPIO_SetValue(CAN_EN_PORT, CAN_EN_BIT, ON);
	
	scandal_register_in_channel_handler(0, &in_channel_0_handler);
	

	/* This is the main loop, go for ever! */
	while (1) {
		/* This checks whether there are pending requests from CAN, and sends a heartbeat message.
		* The heartbeat message encodes some data in the first 4 bytes of the CAN message, such as
		* the number of errors and the version of scandal */
		handle_scandal();
		/*
		 * scandal_send_channel(TELEM_LOW, ID_VOLT, readVoltage());
		 * scandal_send_channel(TELEM_LOW, ID_TEMP, readTemperature());
		 * scandal_send_channel(TELEM_LOW, ID_VOLT, readVoltage());
		 */
		
		if(sc_get_timer() >= one_sec_timer + 1000) {
			toggle_red_led();
			toggle_yellow_led();
			one_sec_timer = sc_get_timer();
			batt_voltage = readVoltage();
			scandal_send_channel(TELEM_LOW, // priority 
							0,      // channel num 
							batt_voltage    // value 
							);
		}
	}
}
コード例 #9
0
ファイル: Battery.cpp プロジェクト: nanoflite/open-altimeter
void Battery::setup(BatteryType batteryType, float batteryMonitorCalibration, float threshold)
{
  _isLow = false;
  _batteryType = batteryType;
  _calibration = batteryMonitorCalibration;
  _threshold = threshold;
  if (batteryType == BATTERY_TYPE_LIPO)
  {
    // measure the LIPO voltage and work out the number of cells
    float v = readVoltage();
    _numberOfCells = ((v < LIPO_CELL_DETECT_THRESHOLD) ? 2 : 3);
  }
}
コード例 #10
0
ファイル: DemoSensor.c プロジェクト: hylcos/WTSN
/******************************************************************************
 * @fn          sendReport
 *
 * @brief       Send sensor report
 *
 * @param       none
 *
 * @return      none
 */
static void sendReport(void)
{
  uint8 pData[SENSOR_REPORT_LENGTH];
  static uint8 reportNr = 0;
  uint8 txOptions;

  // Read and report temperature value
  pData[SENSOR_TEMP_OFFSET] = readTemp();

  // Read and report voltage value
  pData[SENSOR_VOLTAGE_OFFSET] = readVoltage();

  pData[SENSOR_PARENT_OFFSET] =  HI_UINT16(parentShortAddr);
  pData[SENSOR_PARENT_OFFSET + 1] =  LO_UINT16(parentShortAddr);
  pData[BUTTON_PARENT_OFFSET+1] = MCU_IO_GET(0,1);
 // HalUARTWrite(HAL_UART_PORT_0,pData,SENSOR_REPORT_LENGTH);
 // HalUARTWrite(HAL_UART_PORT_1,pData,SENSOR_REPORT_LENGTH);
  int test = MCU_IO_GET(0,1);
  if( MCU_IO_GET(0,1) > 0){
    MCU_IO_SET_LOW(0, 0);
  } else {
    MCU_IO_SET_HIGH(0, 0);
  }
  MCU_IO_SET_LOW(0, 1);
  // Set ACK request on each ACK_INTERVAL report
  // If a report failed, set ACK request on next report
  if ( ++reportNr<ACK_REQ_INTERVAL && reportFailureNr == 0 )
  {
    txOptions = AF_TX_OPTIONS_NONE;
  }
  else
  {
    txOptions = AF_MSG_ACK_REQUEST;
    reportNr = 0;
  }
  // Destination address 0xFFFE: Destination address is sent to previously
  // established binding for the commandId.
  //printf("%i %i",pData[SENSOR_TEMP_OFFSET],oldValue);
  if(timeDone >= 60000){
     timeDone += 1;
  }
  if(pData[SENSOR_TEMP_OFFSET] != oldValue && timeDone >= 60000){
    oldValue = pData[SENSOR_TEMP_OFFSET];
    zb_SendDataRequest( 0xFFFE, SENSOR_REPORT_CMD_ID, SENSOR_REPORT_LENGTH, pData, 0, txOptions, 0 );
    timeDone = 0;
  } else {
    timeDone += myReportPeriod;
  }
}
コード例 #11
0
ファイル: Battery.cpp プロジェクト: nanoflite/open-altimeter
// There is a small amount of hysteresis in this function to stop the alarm from
// intermittently switching on and off near the voltage threshold.
boolean Battery::isLow()
{
  if (_batteryType == BATTERY_TYPE_NONE) return false;
  // TODO: would be better to abstract the hysteresis calculation here
  boolean low;
  double v = readVoltage();
  if (_batteryType == BATTERY_TYPE_LIPO)
  {
    if (_isLow) low = ((v / _numberOfCells) < (_threshold + BATTERY_MONITOR_HYSTERESIS));
    else low = ((v / _numberOfCells) < _threshold);
  }
  if (_batteryType == BATTERY_TYPE_NIMH)
  {
    if (_isLow) low = (v < (_threshold + BATTERY_MONITOR_HYSTERESIS));
    else low = (v < _threshold);
  }
  _isLow = low;
  return low;
}
コード例 #12
0
static msg_t Thread2(void *arg) {

  (void)arg;
  chRegSetThreadName("ADC blinker");
  while (TRUE) {
#ifdef DEBUG_TO_SERIAL
  chprintf( (BaseSequentialStream *)&SD2, "\r\nADC sampling", NULL );
#endif
  if (console == 1)
  {
	  gwinPrintf(ghc, "\r\nADC sampling");
  }
  palTogglePad(GPIOD, GPIOD_LED4);       /* Orange.  */
  chSysLockFromIsr();
    readADC();
    readVoltage();
    readICU();
  chSysUnlockFromIsr();
  chThdSleepMilliseconds(1000);
  }
  return 0;
}
コード例 #13
0
ファイル: SuperIOPlugin.cpp プロジェクト: alexleigh/HWSensors
float SuperIOPlugin::getSensorValue(FakeSMCSensor *sensor)
{
    float value = 0;
    
    if (sensor) {
        switch (sensor->getGroup()) {
            case kFakeSMCTemperatureSensor:
                value = sensor->getOffset() + readTemperature(sensor->getIndex());
                break;
                
            case kFakeSMCVoltageSensor:
                value = readVoltage(sensor->getIndex());
                value = sensor->getOffset() + value + (value - sensor->getReference()) * sensor->getGain();
                break;
                
            case kFakeSMCTachometerSensor:
                value = readTachometer(sensor->getIndex());
                break;
        }
    }
    
	return value;
}
コード例 #14
0
ファイル: main.c プロジェクト: KuanYuChen/mansos
int main(void)
{
    // Make sure all interrupts are disabled.
    // This must be the first step, because in some cases interupt vectors are totally wrong
    // (e.g. when we get here after a soft reboot from another application)
    msp430ClearAllInterruptsNosave();

    msp430WatchdogStop();

    ledsInit();

    flashLeds(LEDS_BOOTLOADER_START);

    BootParams_t bootParams;
    intFlashRead(BOOT_PARAMS_ADDRESS, &bootParams, sizeof(bootParams));

    ++bootParams.bootRetryCount;
    if (bootParams.bootRetryCount > MAX_RETRY_COUNT) {
        bootParams.bootRetryCount = 0;
        bootParams.extFlashAddress = GOLDEN_IMAGE_ADDRESS;
        bootParams.doReprogramming = 1;
    }

    // make sure internal flash address is sane
    if (bootParams.intFlashAddress == 0xffff || bootParams.intFlashAddress < BOOTLOADER_END) {
        bootParams.intFlashAddress = SYSTEM_CODE_START;
    }

    // read voltage, and quit if not enough for writing in flash
    if (readVoltage() < THRESHOLD_VOLTAGE) {
        flashLeds(LEDS_LOW_BATTERY);
        goto exec;
    }

    // write the updated info back in flash
    intFlashErase(BOOT_PARAMS_ADDRESS, sizeof(bootParams));
    intFlashWrite(BOOT_PARAMS_ADDRESS, &bootParams, sizeof(bootParams));

    if (bootParams.doReprogramming) {
        redLedOn();

        // will be using external flash
        extFlashInit();
        extFlashWake();

        uint32_t extAddress = bootParams.extFlashAddress;

        // read number of blocks
        uint16_t imageBlockCount;
        extFlashRead(extAddress, &imageBlockCount, sizeof(uint16_t));
        extAddress += 2;

        while (imageBlockCount) {
            // read a block from external flash
            ExternalFlashBlock_t block;
            extFlashRead(extAddress, &block, sizeof(block));

            if (block.crc != crc16((uint8_t *)&block, sizeof(block) - 2)) {
                // the best we can do is to reboot now;
                // after a few tries the golden image will be loaded
                flashLeds(LEDS_CRC_ERROR);
                // no need to disable all of the interrupts (they already are),
                // just write in watchdog timer wihout password, it will generate reset.
                watchdogRebootSimple();
            }

            bool firstBlockInChunk = block.address & 0x1;
            block.address &= ~0x1;
            if (firstBlockInChunk) {
                // prepare internal flash to be written
                intFlashErase(block.address, INT_FLASH_SEGMENT_SIZE);
            }

            // program internal flash
            COMPILE_TIME_ASSERT(sizeof(block.data) == INT_FLASH_BLOCK_SIZE, ifs);
            intFlashWriteBlock(block.address, block.data, INT_FLASH_BLOCK_SIZE);

            --imageBlockCount;
            extAddress += sizeof(ExternalFlashBlock_t);
        }

        extFlashSleep();
        redLedOff();
    }

#if ENABLE_BOOT_DELAY
    // delay for a second or so to allow the user to interrupt booting (by pressing the reset button)
    flashLeds(LEDS_BOOTLOADER_END);
#endif

    // execute the program
  exec:
    ((ApplicationStartExec)bootParams.intFlashAddress)();
}
コード例 #15
0
ファイル: HC401.cpp プロジェクト: lersen/yun-prototype
float HC401::readPascal() {
  return max(0, (readVoltage() - 0.5) / 0.015);
}
コード例 #16
0
float MCP9700A::tempReadCelcius(){
   float base = readVoltage();
   return (base - .5) / .01 ;
}