@@ -27,6 +27,7 @@ ScienceKitCarrier::ScienceKitCarrier(){
2727 inputB_pin = INPUTB_PIN;
2828 inputA=0 ;
2929 inputB=0 ;
30+ timer_inputA = 0 ;
3031
3132 apds9960 = new APDS9960 (Wire,INT_APDS9960);
3233 proximity=0 ;
@@ -73,9 +74,14 @@ ScienceKitCarrier::ScienceKitCarrier(){
7374 travel_time=0.0 ;
7475 ultrasonic_is_connected=false ;
7576
77+ external_temperature=EXTERNAL_TEMPERATURE_DISABLED;
78+ external_temperature_is_connected=false ;
79+
80+ round_robin_index = 0 ;
7681
7782 thread_activity_led = new rtos::Thread ();
7883 thread_update_bme = new rtos::Thread ();
84+ thread_external_temperature = new rtos::Thread ();
7985
8086 activity_led_state = ACTIVITY_LED_OFF;
8187}
@@ -84,6 +90,10 @@ ScienceKitCarrier::ScienceKitCarrier(){
8490
8591
8692
93+ /* *******************************************************************/
94+ /* Begin */
95+ /* *******************************************************************/
96+
8797int ScienceKitCarrier::begin (const bool auxiliary_threads){
8898 pinMode (LEDR,OUTPUT);
8999 digitalWrite (LEDR,LOW);
@@ -97,7 +107,7 @@ int ScienceKitCarrier::begin(const bool auxiliary_threads){
97107
98108 // most of begin functions return always 0, it is a code-style or future implementation
99109
100- // let's start apds89960
110+ // let's start apds9960
101111 if (beginAPDS ()!=0 ){
102112 return ERR_BEGIN_APDS;
103113 }
@@ -128,7 +138,7 @@ int ScienceKitCarrier::begin(const bool auxiliary_threads){
128138 }
129139
130140
131- // let's start activity led and bme688
141+ // let's start bme688 and external ds18b20 probe
132142 if (auxiliary_threads){
133143 startAuxiliaryThreads ();
134144 }
@@ -149,27 +159,29 @@ void ScienceKitCarrier::update(const bool roundrobin){
149159 updateINA ();
150160 updateResistance ();
151161 updateIMU ();
162+ updateFrequencyGeneratorData ();
152163
153164 // update external
154165 updateUltrasonic ();
155166 }
156167 else {
157168 switch (round_robin_index){
158169 case 0 :
159- updateAnalogInput (); // it is very fast (about 2ms )
160- updateUltrasonic (); // requires about 5ms when not connected
170+ // updateAnalogInput(); // it is very fast (about 1ms )
171+ updateFrequencyGeneratorData (); // less than 1ms
161172 break ;
162173 case 1 :
163- updateAPDS ();
174+ updateAPDS (); // about 5ms
164175 break ;
165176 case 2 :
166- updateINA ();
177+ updateINA (); // about 3ms
167178 break ;
168179 case 3 :
169- updateResistance ();
180+ updateResistance (); // about 1ms
181+ updateUltrasonic (); // requires about 5ms when not connected
170182 break ;
171183 case 4 :
172- updateIMU ();
184+ updateIMU (); // heavy task, 13ms
173185 break ;
174186 default :
175187 break ;
@@ -189,13 +201,20 @@ void ScienceKitCarrier::update(const bool roundrobin){
189201/* *******************************************************************/
190202
191203int ScienceKitCarrier::beginAnalogInput (){
204+ /*
192205 pinMode(inputA_pin, INPUT);
193206 pinMode(inputB_pin, INPUT);
207+ */
194208 return 0 ;
195209}
196210
197211void ScienceKitCarrier::updateAnalogInput (){
198- inputA=analogRead (inputA_pin);
212+ if (!getExternalTemperatureIsConnected ()){
213+ inputA=analogRead (inputA_pin);
214+ }
215+ else {
216+ inputA=ANALOGIN_DISABLED;
217+ }
199218 inputB=analogRead (inputB_pin);
200219}
201220
@@ -397,7 +416,7 @@ float ScienceKitCarrier::getAirQuality(){
397416
398417void ScienceKitCarrier::threadBME688 (){
399418 beginBME688 ();
400- while (true ){
419+ while (1 ){
401420 updateBME688 ();
402421 rtos::ThisThread::sleep_for (1000 );
403422 }
@@ -656,7 +675,9 @@ bool ScienceKitCarrier::getUltrasonicIsConnected(){
656675/* *******************************************************************/
657676
658677int ScienceKitCarrier::beginExternalTemperature (){
659-
678+ new (&ow) OneWireNg_CurrentPlatform (OW_PIN, false );
679+ DSTherm drv (ow);
680+ return 0 ;
660681}
661682
662683void ScienceKitCarrier::updateExternalTemperature (){
@@ -670,8 +691,10 @@ void ScienceKitCarrier::updateExternalTemperature(){
670691 if (ec == OneWireNg::EC_SUCCESS) {
671692 if (scrpd->getAddr ()!=15 ){
672693 external_temperature_is_connected=false ;
694+ external_temperature = EXTERNAL_TEMPERATURE_DISABLED;
673695 }
674696 else {
697+ external_temperature_is_connected=true ;
675698 long temp = scrpd->getTemp ();
676699 int sign=1 ;
677700 if (temp < 0 ) {
@@ -680,21 +703,27 @@ void ScienceKitCarrier::updateExternalTemperature(){
680703 }
681704 temperature = (temp/1000 )+(temp%1000 )*0.001 ;
682705 external_temperature = sign*temperature;
683- external_temperature_is_connected=true ;
684706 }
685707 }
686708}
687709
688710float ScienceKitCarrier::getExternalTemperature (){
689-
711+ return external_temperature;
690712}
691713
692714bool ScienceKitCarrier::getExternalTemperatureIsConnected (){
693-
715+ return external_temperature_is_connected;
694716}
695717
696718void ScienceKitCarrier::threadExternalTemperature (){
697-
719+ beginExternalTemperature ();
720+ while (1 ){
721+ updateAnalogInput ();
722+ digitalWrite (2 ,HIGH);
723+ updateExternalTemperature ();
724+ digitalWrite (2 ,LOW);
725+ rtos::ThisThread::sleep_for (1000 );
726+ }
698727}
699728
700729
@@ -708,4 +737,5 @@ void ScienceKitCarrier::threadExternalTemperature(){
708737void ScienceKitCarrier::startAuxiliaryThreads (){
709738 // thread_activity_led->start(mbed::callback(this, &ScienceKitCarrier::threadActivityLed));
710739 thread_update_bme->start (mbed::callback (this , &ScienceKitCarrier::threadBME688));
740+ thread_external_temperature->start (mbed::callback (this , &ScienceKitCarrier::threadExternalTemperature));
711741}
0 commit comments