Skip to content
This repository was archived by the owner on Mar 31, 2023. It is now read-only.

Commit baf5553

Browse files
ridhaosWi6labsVVESTM
authored andcommitted
Update Capacitive sensor library for STM8 architecture
1 parent d48fbc5 commit baf5553

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

libraries/CapacitiveSensor-0.5.1/CapacitiveSensor.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,15 @@ CapacitiveSensor::CapacitiveSensor(uint8_t sendPin, uint8_t receivePin)
2323
error = 1;
2424
loopTimingFactor = 310; // determined empirically - a hack
2525

26-
CS_Timeout_Millis = (2000 * (float)loopTimingFactor * (float)F_CPU) / 16000000;
26+
CS_Timeout_Millis = (unsigned long)((2000 * (float)loopTimingFactor * (float)F_CPU) / 16000000);
2727
CS_AutocaL_Millis = 20000;
2828

2929
// get pin mapping and port for send Pin - from PinMode function in core
3030
if ((sendPin >= NUM_DIGITAL_PINS) || (receivePin >= NUM_DIGITAL_PINS)) {
3131
error = -1;
3232
return;
3333
}
34-
34+
3535
rPin = receivePin;
3636
sPin = sendPin;
3737

@@ -61,7 +61,12 @@ long CapacitiveSensor::capacitiveSensor(uint8_t samples)
6161
// only calibrate if time is greater than CS_AutocaL_Millis and total is less than 10% of baseline
6262
// this is an attempt to keep from calibrating when the sensor is seeing a "touched" signal
6363

64+
#ifdef __CSMC__
65+
if ( (millis() - lastCal > CS_AutocaL_Millis))
66+
if (abs(total - leastTotal) < (int)(.10 * (float)leastTotal) ) {
67+
#else
6468
if ( (millis() - lastCal > CS_AutocaL_Millis) && abs(total - leastTotal) < (int)(.10 * (float)leastTotal) ) {
69+
#endif
6570

6671
// Serial.println(); // debugging
6772
// Serial.println("auto-calibrate");
@@ -115,7 +120,7 @@ void CapacitiveSensor::set_CS_AutocaL_Millis(unsigned long autoCal_millis){
115120
}
116121

117122
void CapacitiveSensor::set_CS_Timeout_Millis(unsigned long timeout_millis){
118-
CS_Timeout_Millis = (timeout_millis * (float)loopTimingFactor * (float)F_CPU) / 16000000; // floats to deal with large numbers
123+
CS_Timeout_Millis = (unsigned long)((timeout_millis * (float)loopTimingFactor * (float)F_CPU) / 16000000); // floats to deal with large numbers
119124
}
120125

121126
// Private Methods /////////////////////////////////////////////////////////////

libraries/CapacitiveSensor-0.5.1/library.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@ sentence=Create capacitive sensors that can detect touch or proximity.
66
paragraph=The capacitiveSensor library turns two or more Arduino pins into a capacitive sensor, which can sense the electrical capacitance of the human body. All the sensor setup requires is a medium to high value resistor and a piece of wire and a small (to large) piece of aluminum foil on the end. At its most sensitive, the sensor will start to sense a hand or body inches away from the sensor.
77
category=Sensors
88
url=http://playground.arduino.cc/Main/CapacitiveSensor
9-
architectures=stm32
9+
architectures=stm8

0 commit comments

Comments
 (0)