mirror of
				https://github.com/eclipse/upm.git
				synced 2025-11-04 00:54:21 +03:00 
			
		
		
		
	Added Initial interface implementations
This commit is contained in:
		
				
					committed by
					
						
						Stefan Andritoiu
					
				
			
			
				
	
			
			
			
						parent
						
							6228498147
						
					
				
				
					commit
					3572a176c2
				
			
							
								
								
									
										28
									
								
								examples/c++/iLight-sample.cxx
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										28
									
								
								examples/c++/iLight-sample.cxx
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,28 @@
 | 
			
		||||
#include <iostream>
 | 
			
		||||
#include <vector>
 | 
			
		||||
#include <memory>
 | 
			
		||||
 | 
			
		||||
#include "apds9002.hpp"
 | 
			
		||||
#include "bh1750.hpp"
 | 
			
		||||
#include "max44009.hpp"
 | 
			
		||||
 | 
			
		||||
using namespace std;
 | 
			
		||||
using namespace upm;
 | 
			
		||||
 | 
			
		||||
int
 | 
			
		||||
main()
 | 
			
		||||
{
 | 
			
		||||
  vector<unique_ptr<iLight>> lightSensors;
 | 
			
		||||
 | 
			
		||||
  // Populate list of light sensors
 | 
			
		||||
  lightSensors.push_back(unique_ptr<iLight>(new APDS9002(0)));
 | 
			
		||||
  lightSensors.push_back(unique_ptr<iLight>(new BH1750()));
 | 
			
		||||
  lightSensors.push_back(unique_ptr<iLight>(new MAX44009(1)));
 | 
			
		||||
 | 
			
		||||
  // Measure luminance level from all 3 individual sensors
 | 
			
		||||
  for (auto& sensor : lightSensors) {
 | 
			
		||||
    sensor->getLuminance();
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  return 0;
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										26
									
								
								examples/c++/iTemperature-sample.cxx
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										26
									
								
								examples/c++/iTemperature-sample.cxx
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,26 @@
 | 
			
		||||
#include <iostream>
 | 
			
		||||
#include <vector>
 | 
			
		||||
 | 
			
		||||
#include "lm35.hpp"
 | 
			
		||||
#include "abp.hpp"
 | 
			
		||||
 | 
			
		||||
using namespace std;
 | 
			
		||||
using namespace upm;
 | 
			
		||||
 | 
			
		||||
int
 | 
			
		||||
main()
 | 
			
		||||
{
 | 
			
		||||
  vector<iTemperature*> tempSensors {new LM35(0), new ABP(0, ABP_DEFAULT_ADDRESS)};
 | 
			
		||||
 | 
			
		||||
  for (auto sensor : tempSensors) {
 | 
			
		||||
    cout << sensor->getTemperature() << endl;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  for (iTemperature* sensor : tempSensors) {
 | 
			
		||||
    delete sensor;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  tempSensors.clear();
 | 
			
		||||
 | 
			
		||||
  return 0;
 | 
			
		||||
}
 | 
			
		||||
@@ -62,7 +62,7 @@ getLightSensor()
 | 
			
		||||
int
 | 
			
		||||
main()
 | 
			
		||||
{
 | 
			
		||||
    upm::ILightSensor* lightSensor = getLightSensor();
 | 
			
		||||
    /*upm::ILightSensor* lightSensor = getLightSensor();
 | 
			
		||||
    if (lightSensor == NULL) {
 | 
			
		||||
        std::cout << "Light sensor not detected" << std::endl;
 | 
			
		||||
        return 1;
 | 
			
		||||
@@ -77,7 +77,7 @@ main()
 | 
			
		||||
        }
 | 
			
		||||
        upm_delay(1);
 | 
			
		||||
    }
 | 
			
		||||
    delete lightSensor;
 | 
			
		||||
    delete lightSensor;*/
 | 
			
		||||
    return 0;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -48,12 +48,12 @@ main()
 | 
			
		||||
 | 
			
		||||
    // Instantiate a LM35 on analog pin A0, with a default analog
 | 
			
		||||
    // reference voltage of 5.0
 | 
			
		||||
    upm::LM35 sensor(0);
 | 
			
		||||
    upm::iTemperature* sensor = new upm::LM35(0);
 | 
			
		||||
 | 
			
		||||
    // Every half second, sample the sensor and output the temperature
 | 
			
		||||
 | 
			
		||||
    while (shouldRun) {
 | 
			
		||||
        cout << "Temperature: " << sensor.getTemperature() << " C" << endl;
 | 
			
		||||
        cout << "Temperature: " << sensor->getTemperature() << " C" << endl;
 | 
			
		||||
 | 
			
		||||
        upm_delay_us(500000);
 | 
			
		||||
    }
 | 
			
		||||
@@ -61,6 +61,7 @@ main()
 | 
			
		||||
    //! [Interesting]
 | 
			
		||||
 | 
			
		||||
    cout << "Exiting" << endl;
 | 
			
		||||
    delete sensor;
 | 
			
		||||
 | 
			
		||||
    return 0;
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user