Hardware UART comms + partial v5 modules support

This commit is contained in:
Filip Ayazi 2022-09-03 22:04:28 +01:00
parent dfd4a99f1f
commit fde7a90480
10 changed files with 296 additions and 120 deletions

View file

@ -54,35 +54,35 @@ void setup_light_sensor_device()
}
else
{
Serial.println(F("No light sensor found. NB your board will start up faster if you recompile without light sensor support."));
SERIAL_PORT.println(F("No light sensor found. NB your board will start up faster if you recompile without light sensor support."));
}
}
void print_light_sensor_gain()
{
// Print the current gain value of the light sensor
Serial.print(F("light sensor gain "));
SERIAL_PORT.print(F("light sensor gain "));
tsl2591Gain_t gain = tsl.getGain();
switch (gain)
{
case TSL2591_GAIN_LOW:
Serial.println(F("1x (Low)"));
SERIAL_PORT.println(F("1x (Low)"));
break;
case TSL2591_GAIN_MED:
Serial.println(F("25x (Medium)"));
SERIAL_PORT.println(F("25x (Medium)"));
break;
case TSL2591_GAIN_HIGH:
Serial.println(F("428x (High)"));
SERIAL_PORT.println(F("428x (High)"));
break;
case TSL2591_GAIN_MAX:
Serial.println(F("9876x (Max)"));
SERIAL_PORT.println(F("9876x (Max)"));
break;
}
}
void light_sensor_gain_values(String command)
{
// Print the allowable gain values of the light sensor
Serial.println(F("light sensor gains: 1x, 25x, 428x, 9876x"));
SERIAL_PORT.println(F("light sensor gains: 1x, 25x, 428x, 9876x"));
}
void set_light_sensor_gain(int newgain)
@ -103,7 +103,7 @@ void set_light_sensor_gain(int newgain)
tsl.setGain(TSL2591_GAIN_MAX);
break;
default:
Serial.println(F("Error: gain may only be 1, 25, 428, or 9876."));
SERIAL_PORT.println(F("Error: gain may only be 1, 25, 428, or 9876."));
return;
}
print_light_sensor_gain();
@ -112,16 +112,16 @@ void set_light_sensor_gain(int newgain)
void light_sensor_integration_time(String command)
{
// Print the current integration time in milliseconds.
Serial.print(F("light sensor integration time "));
Serial.print((tsl.getTiming() + 1) * 100, DEC);
Serial.println(F(" ms"));
SERIAL_PORT.print(F("light sensor integration time "));
SERIAL_PORT.print((tsl.getTiming() + 1) * 100, DEC);
SERIAL_PORT.println(F(" ms"));
}
void light_sensor_intensity(String command)
{
// Print the current light value
uint16_t x = tsl.getLuminosity(TSL2591_FULLSPECTRUM);
Serial.println(x, DEC);
SERIAL_PORT.println(x, DEC);
}
#endif // ADAFRUIT_TSL2591
@ -137,34 +137,34 @@ void setup_light_sensor_device()
void print_light_sensor_gain()
{
// Print the current gain value of the light sensor
Serial.print(F("light sensor gain "));
SERIAL_PORT.print(F("light sensor gain "));
adsGain_t gain = ads.getGain();
switch (gain)
{
case GAIN_TWOTHIRDS:
Serial.println(F("0.66x (specify 0)"));
SERIAL_PORT.println(F("0.66x (specify 0)"));
break;
case GAIN_ONE:
Serial.println(F("1x"));
SERIAL_PORT.println(F("1x"));
break;
case GAIN_TWO:
Serial.println(F("2x"));
SERIAL_PORT.println(F("2x"));
break;
case GAIN_FOUR:
Serial.println(F("4x"));
SERIAL_PORT.println(F("4x"));
break;
case GAIN_EIGHT:
Serial.println(F("8x"));
SERIAL_PORT.println(F("8x"));
break;
case GAIN_SIXTEEN:
Serial.println(F("16x"));
SERIAL_PORT.println(F("16x"));
break;
}
}
void light_sensor_gain_values(String command)
{
// Print the allowable gain values of the light sensor
Serial.println(F("light sensor gains: 0.66x (specify 0), 1x, 2x, 4x, 8x, 16x"));
SERIAL_PORT.println(F("light sensor gains: 0.66x (specify 0), 1x, 2x, 4x, 8x, 16x"));
}
void set_light_sensor_gain(int newgain)
@ -191,7 +191,7 @@ void set_light_sensor_gain(int newgain)
ads.setGain(GAIN_SIXTEEN);
break;
default:
Serial.println(F("Error: gain may only be 0, 1, 2, 4, 8, 16 (0 means 2/3)."));
SERIAL_PORT.println(F("Error: gain may only be 0, 1, 2, 4, 8, 16 (0 means 2/3)."));
return;
}
print_light_sensor_gain();
@ -200,15 +200,22 @@ void set_light_sensor_gain(int newgain)
void light_sensor_integration_time(String command)
{
// Print the current integration time in milliseconds.
Serial.println(F("integration time not supported for ADS1115"));
SERIAL_PORT.println(F("integration time not supported for ADS1115"));
}
void light_sensor_intensity(String command)
{
int ch;
char *args[1];
parse_arguments(args, command, 1);
ch = atoi(args[0]);
free(args[0]);
// Print the current light value
// uint16_t x = ads.readADC_SingleEnded(0); //single ended measurement on pin 0
uint16_t x = ads.readADC_Differential_0_1(); //differential measurement on pins 0,1
Serial.println(x, DEC);
uint16_t x = ads.readADC_SingleEnded(ch); //single ended measurement on pin ch (0-3)
//uint16_t x = ads.readADC_Differential_0_1(); //differential measurement on pins 0,1
SERIAL_PORT.println(x, DEC);
}
#endif // ADAFRUIT_ADS1115
#endif