Skip to content
Snippets Groups Projects
Commit a0a1c1c8 authored by Bernhard Heinloth's avatar Bernhard Heinloth
Browse files

fix off by one bug

parent 6275b157
No related branches found
No related tags found
No related merge requests found
...@@ -46,8 +46,8 @@ ...@@ -46,8 +46,8 @@
#define TIMELOG_THRESHOLD 500 #define TIMELOG_THRESHOLD 500
// Interrupt Ping fuer Beschleunigungssensor // Interrupt Pin fuer Beschleunigungssensor
#define ACCEL_INT_PIN GPIO_NUM_21 #define ACCEL_INT_PIN GPIO_NUM_27
// Grenzwert fuer die Klickerkennung // Grenzwert fuer die Klickerkennung
#define ACCEL_CLICK_THS 80 #define ACCEL_CLICK_THS 80
// SPI Cable Select Pin fuer Beschleunigungssensor // SPI Cable Select Pin fuer Beschleunigungssensor
......
...@@ -25,7 +25,6 @@ const char* wlan_ssid = WLAN_SSID; ...@@ -25,7 +25,6 @@ const char* wlan_ssid = WLAN_SSID;
const char* sync_http_host = SYNC_HTTP_HOST; const char* sync_http_host = SYNC_HTTP_HOST;
const uint8_t side_translate[6] = SIDE_MAPPING; const uint8_t side_translate[6] = SIDE_MAPPING;
RTC_DATA_ATTR uint8_t side_last = 0;
RTC_DATA_ATTR uint8_t timelog_entry = 0; RTC_DATA_ATTR uint8_t timelog_entry = 0;
RTC_DATA_ATTR time_t timelog[TIMELOG_MAX]; RTC_DATA_ATTR time_t timelog[TIMELOG_MAX];
RTC_DATA_ATTR time_t wakeup = SYNC_INTERVAL; RTC_DATA_ATTR time_t wakeup = SYNC_INTERVAL;
...@@ -62,10 +61,7 @@ static uint8_t getSide(){ ...@@ -62,10 +61,7 @@ static uint8_t getSide(){
static uint8_t getStableSide(){ static uint8_t getStableSide(){
// Get current side // Get current side
uint8_t side = getSide(); uint8_t side_last = getSide();
// If changed, wait for stable side
if (side != side_last) {
side_last = side;
// try to save power during sleep // try to save power during sleep
esp_sleep_enable_timer_wakeup(SIDE_DELAY * 1000); esp_sleep_enable_timer_wakeup(SIDE_DELAY * 1000);
// we need SIDE_COUNT stable reads // we need SIDE_COUNT stable reads
...@@ -76,15 +72,15 @@ static uint8_t getStableSide(){ ...@@ -76,15 +72,15 @@ static uint8_t getStableSide(){
delay(SIDE_DELAY); delay(SIDE_DELAY);
} }
// Update Side // Update Side
side = getSide(); uint8_t side = getSide();
// check if stable or reset // check if stable or reset
if (side_last != side){ if (side_last != side){
side_last = side; side_last = side;
n = 0; n = 0;
} }
} }
} return side_last;
return side;
} }
...@@ -207,8 +203,6 @@ static bool uploadData(){ ...@@ -207,8 +203,6 @@ static bool uploadData(){
SDBGLN(voltage); SDBGLN(voltage);
SDBG("time: "); SDBG("time: ");
SDBGLN(now); SDBGLN(now);
SDBG("side: ");
SDBGLN(side_last);
SDBGLN("data:"); SDBGLN("data:");
for (int i = 0; i < timelog_entry; i++){ for (int i = 0; i < timelog_entry; i++){
SDBG("\t"); SDBG("\t");
...@@ -231,7 +225,7 @@ static bool uploadData(){ ...@@ -231,7 +225,7 @@ static bool uploadData(){
client.print("/upload HTTP/1.1\r\nHost: "); client.print("/upload HTTP/1.1\r\nHost: ");
client.print(sync_http_host); client.print(sync_http_host);
client.print("\r\nUser-Agent: i4Zeitwuerfel\r\nContent-Type: application/x-www-form-urlencoded\r\nContent-Length: "); client.print("\r\nUser-Agent: i4Zeitwuerfel\r\nContent-Type: application/x-www-form-urlencoded\r\nContent-Length: ");
client.print(timelog_entry == 0 ? 15 : (17 + (timelog_entry - 1) * 9)); client.print(timelog_entry == 0 ? 15 : (17 + timelog_entry * 9));
client.print("\r\n\r\n"); client.print("\r\n\r\n");
client.printf("v=%02X", voltage); client.printf("v=%02X", voltage);
client.printf("&t=%08X", now); client.printf("&t=%08X", now);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment