update rfid firmware

This commit is contained in:
2021-10-17 13:26:15 +02:00
parent 8518f17ab0
commit b1703cde41
10 changed files with 63 additions and 38 deletions

View File

@@ -2,7 +2,6 @@
#include "math.h"
uint32_t last_hall_read;
uint16_t last_hall_sample;
uint8_t hall_idle_count;
@@ -10,50 +9,51 @@ bool hall_is_Idle = true;
void initGame(void)
{
printlnI("Game: init");
pinMode(HALL_INPUT, ANALOG);
//analogReadResolution(10);
analogSetAttenuation(ADC_11db);
printlnI("Game: init: done");
}
void handleGame(void)
{
uint32_t timeNow = millis();
if(timeNow - last_hall_read > HALLINTERVAL)
if (timeNow - last_hall_read > HALLINTERVAL)
{
uint16_t hall_sample = analogRead(HALL_INPUT);
uint16_t hall_delta = (last_hall_sample > hall_sample)? (last_hall_sample - hall_sample) : (hall_sample - last_hall_sample);
if(hall_delta > HALLIDLETHRESHOLD)
uint16_t hall_sample = analogRead(HALL_INPUT);
uint16_t hall_delta = (last_hall_sample > hall_sample) ? (last_hall_sample - hall_sample) : (hall_sample - last_hall_sample);
if (hall_delta > HALLIDLETHRESHOLD)
{
if (hall_idle_count > HALLIDLESAMPLES)
{
if(hall_idle_count > HALLIDLESAMPLES)
{
hall_is_Idle = false;
hall_idle_count = 8;
}
else
{
hall_idle_count++;
}
hall_is_Idle = false;
hall_idle_count = 8;
}
else
{
if(hall_idle_count == 0)
{
hall_is_Idle = true;
}
else
{
hall_idle_count--;
}
hall_idle_count++;
}
Serial.printf("HallSensor: val=%d, delta=%d, count=%d, idle=%s\n",
hall_sample,
hall_delta,
hall_idle_count,
(hall_is_Idle? "yes":"no"));
last_hall_sample = hall_sample;
last_hall_read = timeNow;
}
else
{
if (hall_idle_count == 0)
{
hall_is_Idle = true;
printlnI("Game: Idle");
}
else
{
hall_idle_count--;
}
}
// debugD("HallSensor: val=%d, delta=%d, count=%d, idle=%s\n",
// hall_sample,
// hall_delta,
// hall_idle_count,
// (hall_is_Idle? "yes":"no"));
last_hall_sample = hall_sample;
last_hall_read = timeNow;
}
}