Compare commits
19 Commits
6dca8972e3
...
30db59d4a8
| Author | SHA1 | Date | |
|---|---|---|---|
| 30db59d4a8 | |||
| 16995b67ef | |||
| 8b4c00bc7f | |||
| 02a4ff420d | |||
| 1fde3347c8 | |||
| 0e02abd9c9 | |||
| f45809690e | |||
| 8e07b6151f | |||
| a27853297f | |||
| ab15d1ce3f | |||
| 5257cf9a31 | |||
| bde3daae53 | |||
| ae2dde8e63 | |||
| 01be1b6a93 | |||
| 0828ced6d1 | |||
| 59d6eb8dc2 | |||
| 53fbd0ebfa | |||
| fd34ac13ca | |||
| 59519e4f55 |
30
.gitmodules
vendored
30
.gitmodules
vendored
@@ -1,35 +1,37 @@
|
||||
[submodule "FW/leo_muziekdoos_esp32/lib/ESP8266Audio"]
|
||||
path = FW/leo_muziekdoos_esp32/lib/ESP8266Audio
|
||||
url = http://debianvm.local:3000/libs/ESP8266Audio.git
|
||||
url = http://git.oldemans.nl/libs/ESP8266Audio.git
|
||||
branch = master
|
||||
[submodule "FW/leo_muziekdoos_esp32/lib/littleFS_esp32"]
|
||||
path = FW/leo_muziekdoos_esp32/lib/littleFS_esp32
|
||||
url = http://debianvm.local:3000/libs/LittleFS_esp32
|
||||
branch = master
|
||||
url = http://git.oldemans.nl/libs/LittleFS_esp32
|
||||
[submodule "FW/leo_muziekdoos_esp32/lib/JCButton"]
|
||||
path = FW/leo_muziekdoos_esp32/lib/JCButton
|
||||
url = http://debianvm.local:3000/libs/JCButton.git
|
||||
url = http://git.oldemans.nl/libs/JCButton.git
|
||||
branch = master
|
||||
[submodule "FW/leo_muziekdoos_esp32/lib/NDEF"]
|
||||
path = FW/leo_muziekdoos_esp32/lib/NDEF
|
||||
url = http://debianvm.local:3000/libs/rfid.NDEF.git
|
||||
url = http://git.oldemans.nl/libs/rfid.NDEF.git
|
||||
[submodule "FW/leo_muziekdoos_esp32/lib/PN532"]
|
||||
path = FW/leo_muziekdoos_esp32/lib/PN532
|
||||
url = http://debianvm.local:3000/libs/rfid.PN532.git
|
||||
url = http://git.oldemans.nl/libs/rfid.PN532.git
|
||||
branch = master
|
||||
[submodule "FW/leo_muziekdoos_esp32/lib/PN532_SPI"]
|
||||
path = FW/leo_muziekdoos_esp32/lib/PN532_SPI
|
||||
url = http://debianvm.local:3000/libs/rfid.PN532_SPI.git
|
||||
branch = master
|
||||
[submodule "FW/leo_muziekdoos_esp32/lib/ADC_ADS1x15"]
|
||||
path = FW/leo_muziekdoos_esp32/lib/ADC_ADS1x15
|
||||
url = http://debianvm.local:3000/libs/ADC_ADS1X15.git
|
||||
branch = master
|
||||
url = http://git.oldemans.nl/libs/rfid.PN532_SPI.git
|
||||
[submodule "FW/leo_muziekdoos_esp32/lib/BatterySense"]
|
||||
path = FW/leo_muziekdoos_esp32/lib/BatterySense
|
||||
url = http://debianvm.local:3000/libs/BatterySense.git
|
||||
url = http://git.oldemans.nl/libs/BatterySense.git
|
||||
branch = master
|
||||
[submodule "CAD"]
|
||||
path = CAD
|
||||
url = http://debianvm.local:3000/projects_leo/muziekdooos_hardware.git
|
||||
url = http://git.oldemans.nl/projects_leo/muziekdooos_hardware.git
|
||||
branch = master
|
||||
[submodule "FW/leo_muziekdoos_esp32/lib/ADC_ADS1x15"]
|
||||
path = FW/leo_muziekdoos_esp32/lib/ADC_ADS1x15
|
||||
url = http://git.oldemans.nl/libs/ADC_ADS1X15.git
|
||||
branch = master
|
||||
[submodule "CAD"]
|
||||
path = CAD
|
||||
url = http://git.oldemans.nl/projects_leo/muziekdooos_hardware.git
|
||||
branch = master
|
||||
|
||||
1
CAD
1
CAD
Submodule CAD deleted from 04fb595533
24748
CAD/datasheet/AS5600_DS000365_5-00.pdf
Normal file
24748
CAD/datasheet/AS5600_DS000365_5-00.pdf
Normal file
File diff suppressed because one or more lines are too long
@@ -1,16 +1,17 @@
|
||||
{
|
||||
"tags": [{
|
||||
"TagUID" : "B3 26 D0 15",
|
||||
"audiofile" : "/Billy-Jean.mp3"
|
||||
},
|
||||
{
|
||||
"TagUID" : "1F E8 20 00",
|
||||
"audiofile" : "/Let_it_be.mp3"
|
||||
},
|
||||
{
|
||||
"TagUID" : "23 0E 2C 19",
|
||||
"audiofile" : "/ringoffire.mp3"
|
||||
}],
|
||||
"tags": [
|
||||
{
|
||||
"TagUID" : "B3 26 D0 15",
|
||||
"audiofile" : "/Billy-Jean.mp3"
|
||||
},
|
||||
{
|
||||
"TagUID" : "1F E8 20 00",
|
||||
"audiofile" : "/Let_it_be.mp3"
|
||||
},
|
||||
{
|
||||
"TagUID" : "23 0E 2C 19",
|
||||
"audiofile" : "/ringoffire.mp3"
|
||||
}],
|
||||
"WiFi": [
|
||||
{
|
||||
"ssid": "poes",
|
||||
@@ -19,6 +20,13 @@
|
||||
{
|
||||
"ssid": "wifi2",
|
||||
"psk": "pass2"
|
||||
}
|
||||
]
|
||||
}],
|
||||
|
||||
"AudioGain": 0.5,
|
||||
"ScanTimeout": 50,
|
||||
"HardwareVersion": 2,
|
||||
"GameTimeout": 10000,
|
||||
"PowerTimeout": 420000,
|
||||
"PowerOTADelay": 4000,
|
||||
"Brightness": 20
|
||||
}
|
||||
Submodule FW/leo_muziekdoos_esp32/lib/PN532 updated: 47ec860298...e88576ed93
@@ -8,18 +8,30 @@
|
||||
; Please visit documentation for the other options and examples
|
||||
; https://docs.platformio.org/page/projectconf.html
|
||||
|
||||
[env]
|
||||
src_filter = +<*> -<.git/> -<.svn/> -<example/> -<examples/> -<test/> -<tests/>
|
||||
|
||||
|
||||
[env:esp32-pico]
|
||||
platform = espressif32
|
||||
board = m5stack-atom
|
||||
#board = m5stack-atom
|
||||
board = pico32
|
||||
framework = arduino
|
||||
lib_deps =
|
||||
bblanchon/ArduinoJson@^6.18.5
|
||||
fastled/FastLED@^3.4.0
|
||||
monitor_speed = 115200
|
||||
bblanchon/ArduinoJson@^6.20.0
|
||||
fastled/FastLED@^3.5.0
|
||||
#robtillaart/AS5600 @ ^0.3.4
|
||||
robtillaart/AS5600 @ ^0.3.6
|
||||
src_filter = ${env.build_src_filter}
|
||||
lib_ldf_mode = deep+
|
||||
extra_scripts = ./littlefsbuilder.py
|
||||
build_flags =
|
||||
-DHARDWARE=2
|
||||
-DCORE_DEBUG_LEVEL=4
|
||||
-DCORE_DEBUG_LEVEL=3
|
||||
-DNDEF_DEBUG=1
|
||||
extra_scripts = ./littlefsbuilder.py
|
||||
board_build.filesystem = littlefs
|
||||
|
||||
monitor_speed = 115200
|
||||
#upload_protocol = esptool
|
||||
upload_protocol = espota
|
||||
upload_port = muziekdoos.local
|
||||
|
||||
@@ -10,7 +10,6 @@ String nextAudioFile = "";
|
||||
uint8_t n = 0;
|
||||
|
||||
bool audioState = false;
|
||||
|
||||
bool audioInitOk = false;
|
||||
|
||||
const char *waveFile[] =
|
||||
@@ -82,7 +81,7 @@ void playSong(String filename)
|
||||
}
|
||||
else
|
||||
{
|
||||
log_e("no filenae specified");
|
||||
log_e("no filename specified");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -93,7 +92,7 @@ void initAudio()
|
||||
delay(500);
|
||||
out = new AudioOutputI2S();
|
||||
out->SetPinout(I2S_BCLK, I2S_WCLK, I2S_DATA); // bclk, wclk, data
|
||||
out->SetGain(AUDIOGAIN);
|
||||
out->SetGain(getFloatParam("AudioGain", AUDIOGAIN));
|
||||
pinMode(DAC_SDMODE, OUTPUT);
|
||||
setAudioState(false);
|
||||
mp3 = new AudioGeneratorMP3();
|
||||
@@ -103,6 +102,8 @@ void initAudio()
|
||||
|
||||
void setAudioState(bool state)
|
||||
{
|
||||
if(state == audioState) return;
|
||||
|
||||
audioState = state;
|
||||
if (state)
|
||||
{
|
||||
|
||||
@@ -8,12 +8,9 @@
|
||||
#include "AudioOutputI2S.h"
|
||||
|
||||
#include "game.h"
|
||||
#include "config.h"
|
||||
|
||||
#define AUDIOGAIN 0.5
|
||||
#define AUDIONSONGS 3
|
||||
#define AUDIOREPEATS 3
|
||||
|
||||
|
||||
|
||||
void initAudio(void);
|
||||
void handleAudio(void);
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
#include "ArduinoJson.h"
|
||||
|
||||
const char *tagConfigfile = "/settings.json";
|
||||
DynamicJsonDocument settingsDoc(512);
|
||||
DynamicJsonDocument settingsDoc(1024);
|
||||
|
||||
bool configInitOK = false;
|
||||
struct tagConfig
|
||||
@@ -48,6 +48,41 @@ String GetWifiPassword(String ssid)
|
||||
return "";
|
||||
}
|
||||
|
||||
|
||||
int GetIntparam(String param, int def)
|
||||
{
|
||||
|
||||
log_i("Get param %s",param );
|
||||
if(param == "")
|
||||
{
|
||||
log_e("No param(%s) given", param);
|
||||
return def;
|
||||
}
|
||||
if(!settingsDoc.containsKey(param))
|
||||
{
|
||||
log_e("param(%s) not found",param);
|
||||
return def;
|
||||
}
|
||||
return settingsDoc[param];
|
||||
}
|
||||
|
||||
|
||||
float getFloatParam(String param, int def)
|
||||
{
|
||||
log_i("Get param %s",param );
|
||||
if( param == "")
|
||||
{
|
||||
log_e("No param(%s) given",param);
|
||||
return def;
|
||||
}
|
||||
if(!settingsDoc.containsKey(param))
|
||||
{
|
||||
log_e("param(%s)",param);
|
||||
return def;
|
||||
}
|
||||
return settingsDoc[param];
|
||||
}
|
||||
|
||||
void loadConfig(const char *fname)
|
||||
{
|
||||
log_i("config: load");
|
||||
@@ -80,6 +115,9 @@ void loadConfig(const char *fname)
|
||||
}
|
||||
configInitOK = !hasError;
|
||||
}
|
||||
//test values
|
||||
int test = GetIntparam("ScanTimeout");
|
||||
log_i("retval(%i)",test);
|
||||
log_i("config: load done");
|
||||
}
|
||||
|
||||
@@ -95,6 +133,26 @@ void handleConfig(void)
|
||||
{
|
||||
}
|
||||
|
||||
bool getUIDvalid(String uid)
|
||||
{
|
||||
JsonArray array = settingsDoc["tags"].as<JsonArray>();
|
||||
for (JsonVariant v : array)
|
||||
{
|
||||
String taguid((const char*)v["TagUID"]);
|
||||
uint16_t result = uid.compareTo(taguid);
|
||||
|
||||
log_v("compare %s(config) with %s(read) = %d",taguid.c_str(), uid.c_str(), result);
|
||||
if (!result)
|
||||
{
|
||||
String filename((const char*)v["audiofile"]);
|
||||
log_i("Tag found in config");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
log_e("taguid %s not found",uid.c_str() );
|
||||
return false;
|
||||
}
|
||||
|
||||
String getConfigSong(String uid)
|
||||
{
|
||||
JsonArray array = settingsDoc["tags"].as<JsonArray>();
|
||||
|
||||
@@ -3,8 +3,10 @@
|
||||
#include "Arduino.h"
|
||||
|
||||
String getConfigSong(String uid);
|
||||
bool getUIDvalid(String uid);
|
||||
String GetWifiPassword(String ssid);
|
||||
|
||||
int GetIntparam(String param, int def = -1);
|
||||
float getFloatParam( String param, int def = -1);
|
||||
|
||||
void initConfig(void);
|
||||
void handleConfig(void);
|
||||
@@ -5,91 +5,171 @@
|
||||
bool newState = true;
|
||||
uint32_t idleTime = 0;
|
||||
|
||||
GamneStates gameState = GamneStates::stateInit;
|
||||
|
||||
|
||||
static const char *Gameenum_str[]
|
||||
{
|
||||
"stateInit",
|
||||
"stateIdle",
|
||||
"stateScanning",
|
||||
"stateArmed",
|
||||
"stateStartPlaying",
|
||||
"statePlaying",
|
||||
"stateStopPlaying",
|
||||
"stateStopped"
|
||||
};
|
||||
|
||||
|
||||
GameStates gameState = GameStates::stateInit;
|
||||
|
||||
void initGame(void)
|
||||
{
|
||||
log_i("Game: init: done");
|
||||
}
|
||||
|
||||
void setGameState(GamneStates newstate)
|
||||
void setGameState(GameStates newstate)
|
||||
{
|
||||
gameState = newstate;
|
||||
newState = true;
|
||||
log_i("NewState = %s", StateToString(newstate).c_str());
|
||||
}
|
||||
|
||||
void handleNewState(void)
|
||||
{
|
||||
if (newState)
|
||||
{
|
||||
log_i("ActiveState = %s" , StateToString(gameState).c_str());
|
||||
newState = false;
|
||||
}
|
||||
}
|
||||
|
||||
String StateToString(GameStates gamestate)
|
||||
{
|
||||
try
|
||||
{
|
||||
return Gameenum_str[gamestate];
|
||||
}
|
||||
catch(const std::exception& e)
|
||||
{
|
||||
log_e("statestring size does not match");
|
||||
return "statestringerror";
|
||||
}
|
||||
}
|
||||
|
||||
void GameStartPlayingSong(void)
|
||||
{
|
||||
// get filefrom config
|
||||
String lastUID = getRFIDlastUID();
|
||||
log_i("uid=%s", lastUID.c_str());
|
||||
String nextSong = getConfigSong(lastUID);
|
||||
log_i("nextSong=%s", nextSong.c_str());
|
||||
playSong(nextSong);
|
||||
setAudioState(true);
|
||||
}
|
||||
|
||||
|
||||
void handleGame(void)
|
||||
{
|
||||
switch (gameState)
|
||||
{
|
||||
case stateInit:
|
||||
{
|
||||
SetLedColor(CRGB::White);
|
||||
setLedBlink(true);
|
||||
if (newState)
|
||||
{
|
||||
log_i("activeState = Init");
|
||||
newState = false;
|
||||
handleNewState();
|
||||
}
|
||||
if (getSensorInitStatus() && getAudioInitStatus() && getRFIDInitStatus())
|
||||
{
|
||||
log_i("All systems init OK, Game ready");
|
||||
setGameState(stateIdle);
|
||||
log_i("nextState = idle");
|
||||
}
|
||||
}
|
||||
break;
|
||||
case stateIdle:
|
||||
{
|
||||
SetLedColor(CRGB::Purple);
|
||||
setLedBlink(false);
|
||||
if (newState)
|
||||
{
|
||||
log_i("activeState = Idle");
|
||||
newState = false;
|
||||
idleTime = millis();
|
||||
handleNewState();
|
||||
setRFIDscanState(false);
|
||||
setAudioState(false);
|
||||
//idleTime = millis();
|
||||
}
|
||||
|
||||
if (getRFIDlastUID() == "")
|
||||
idleTime = getLastTagTime();
|
||||
|
||||
if (!getRFIDlastUIDValid())
|
||||
{
|
||||
// no UID found, go RFID scanning
|
||||
setGameState(stateScanning);
|
||||
log_i("nextState = Scanning");
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!hallIsIdle())
|
||||
{
|
||||
setGameState(stateStartPlaying);
|
||||
log_i("nextState = Start playing");
|
||||
}
|
||||
else
|
||||
{
|
||||
setRFIDscanState(true);
|
||||
}
|
||||
// valid RFID found arm system
|
||||
setGameState(stateArmed);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case stateScanning:
|
||||
{
|
||||
SetLedColor(CRGB::Green);
|
||||
setLedBlink(true);
|
||||
if (newState)
|
||||
{
|
||||
log_i("activeState = RFID scanning");
|
||||
handleNewState();
|
||||
setRFIDscanState(true);
|
||||
newState = false;
|
||||
}
|
||||
|
||||
if (getRFIDlastUID() != "")
|
||||
if (getRFIDlastUIDValid())
|
||||
{
|
||||
setGameState(stateIdle);
|
||||
// valid RFID found arm system
|
||||
setRFIDscanState(false);
|
||||
log_i("nextState = idle");
|
||||
setGameState(stateArmed);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case stateStartPlaying:
|
||||
|
||||
case stateArmed:
|
||||
{
|
||||
SetLedColor(CRGB::Green);
|
||||
setLedBlink(false);
|
||||
if (newState)
|
||||
{
|
||||
log_i("activeState = startPlaying");
|
||||
newState = false;
|
||||
handleNewState();
|
||||
setRFIDscanState(true);
|
||||
idleTime = millis();
|
||||
}
|
||||
|
||||
if (!hallIsIdle())
|
||||
{
|
||||
// hall has detected movement, start playing
|
||||
setGameState(stateStartPlaying);
|
||||
}
|
||||
else
|
||||
{
|
||||
uint32_t now = millis();
|
||||
if(now - idleTime > TIMEOUT_ARMED)
|
||||
{
|
||||
log_i("Armed timed-out, clear current UID and go back to Idle");
|
||||
clearRFIDlastUID();
|
||||
setGameState(stateIdle);
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case stateStartPlaying:
|
||||
{
|
||||
SetLedColor(CRGB::Pink);
|
||||
setLedBlink(true);
|
||||
if (newState)
|
||||
{
|
||||
handleNewState();
|
||||
setRFIDscanState(false);
|
||||
PowerKeepAlive();
|
||||
|
||||
}
|
||||
|
||||
if (hallIsIdle())
|
||||
@@ -98,53 +178,52 @@ void handleGame(void)
|
||||
}
|
||||
else
|
||||
{
|
||||
// get filefrom config
|
||||
String lastUID = getRFIDlastUID();
|
||||
log_i("uid=%s", lastUID.c_str());
|
||||
String nextSong = getConfigSong(lastUID);
|
||||
log_i("nextSong=%s", nextSong.c_str());
|
||||
playSong(nextSong);
|
||||
setAudioState(true);
|
||||
GameStartPlayingSong();
|
||||
setGameState(statePlaying);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case statePlaying:
|
||||
{
|
||||
SetLedColor(CRGB::Pink);
|
||||
setLedBlink(false);
|
||||
if (newState)
|
||||
{
|
||||
log_i("activeState = Playing");
|
||||
newState = false;
|
||||
handleNewState();
|
||||
}
|
||||
|
||||
if (hallIsIdle())
|
||||
{
|
||||
setAudioState(false);
|
||||
setGameState(stateStopPlaying);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case stateStopPlaying:
|
||||
{
|
||||
SetLedColor(CRGB::Teal);
|
||||
setLedBlink(true);
|
||||
if (newState)
|
||||
{
|
||||
log_i("activeState = stopPlaying");
|
||||
newState = false;
|
||||
setAudioState(false);
|
||||
handleNewState();
|
||||
}
|
||||
|
||||
if (!getAudioState())
|
||||
{
|
||||
setAudioState(false);
|
||||
setGameState(stateStopped);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case stateStopped:
|
||||
{
|
||||
SetLedColor(CRGB::Teal);
|
||||
setLedBlink(false);
|
||||
if (newState)
|
||||
{
|
||||
log_i("activeState = stopped");
|
||||
newState = false;
|
||||
handleNewState();
|
||||
}
|
||||
|
||||
if (!getAudioState())
|
||||
{
|
||||
setGameState(stateIdle);
|
||||
@@ -153,6 +232,8 @@ void handleGame(void)
|
||||
break;
|
||||
default:
|
||||
{
|
||||
log_w("Unknown state go to Idle");
|
||||
setGameState(stateIdle);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -9,17 +9,19 @@
|
||||
#include "power.h"
|
||||
|
||||
#define TIMEOUT_IDLE 20000
|
||||
#define TIMEOUT_ARMED 10000
|
||||
|
||||
typedef enum{
|
||||
stateInit,
|
||||
stateIdle,
|
||||
stateScanning,
|
||||
stateArmed,
|
||||
stateStartPlaying,
|
||||
statePlaying,
|
||||
stateStopPlaying,
|
||||
stateStopped,
|
||||
stateLAST
|
||||
}GamneStates;
|
||||
}GameStates;
|
||||
|
||||
void initGame(void);
|
||||
void handleGame(void);
|
||||
@@ -27,3 +29,6 @@ bool hallIsIdle(void);
|
||||
|
||||
void handleHallSensor(void);
|
||||
|
||||
String StateToString(GameStates state);
|
||||
|
||||
|
||||
|
||||
@@ -1,5 +1,11 @@
|
||||
#include "led.h"
|
||||
|
||||
#ifdef STEALTH
|
||||
const bool LED_STEALTH = true;
|
||||
#else
|
||||
const bool LED_STEALTH = false;
|
||||
#endif
|
||||
|
||||
CRGB leds[NUM_LEDS];
|
||||
|
||||
bool ledstate = false;
|
||||
@@ -28,7 +34,7 @@ void SetLedColor(CRGB color, bool blink)
|
||||
void initLed(void)
|
||||
{
|
||||
FastLED.addLeds<SK6812, LED_PIN, GRB>(leds, NUM_LEDS); // GRB ordering is typical
|
||||
FastLED.setBrightness(LEDBRIGHTNESS);
|
||||
FastLED.setBrightness(GetIntparam("Brightness", LEDDEFBRIGHT));
|
||||
}
|
||||
|
||||
void handleLed(void)
|
||||
@@ -56,7 +62,8 @@ void handleLed(void)
|
||||
{
|
||||
leds[0] = ledcolor;
|
||||
}
|
||||
FastLED.show();
|
||||
FastLED.show();
|
||||
|
||||
lastLedTime = timeNow;
|
||||
}
|
||||
}
|
||||
@@ -4,11 +4,12 @@
|
||||
#include "power.h"
|
||||
#include "audio.h"
|
||||
#include "rfid.h"
|
||||
#include "config.h"
|
||||
|
||||
#define NUM_LEDS 1
|
||||
#define LEDTIMEOUT 100
|
||||
#define LEDBLINKTIME 500
|
||||
#define LEDBRIGHTNESS 75
|
||||
#define LEDDEFBRIGHT 20
|
||||
|
||||
void initLed(void);
|
||||
void handleLed(void);
|
||||
|
||||
@@ -36,6 +36,11 @@ bool OtaProcess_class::initialize(void)
|
||||
m_ssid = WiFi.SSID(i);
|
||||
m_psk = tmppsk;
|
||||
}
|
||||
else{
|
||||
log_w("using fallback SSID %s", SECRET_SSID);
|
||||
m_ssid = SECRET_SSID;
|
||||
m_psk = SECRET_PASS;
|
||||
}
|
||||
log_i("[%d] %s %s (%d) [%s]", i, WiFi.SSID(i), (WiFi.encryptionType(i) == WIFI_AUTH_OPEN) ? " " : "*", WiFi.RSSI(i), (tmppsk != "")? "OK": "Not congigured");
|
||||
}
|
||||
}
|
||||
@@ -64,10 +69,10 @@ bool OtaProcess_class::initialize(void)
|
||||
|
||||
case otaConnect:
|
||||
{
|
||||
log_i("Otastate = initialize(connect)");
|
||||
uint32_t timeTemp = millis();
|
||||
if (timeTemp - m_lastconnectTime > WIFICONNECTINTERVAL)
|
||||
{
|
||||
log_i("Otastate = initialize(connect)");
|
||||
if (WiFi.status() != WL_CONNECTED)
|
||||
{
|
||||
log_e("Connection Failed! Retry...");
|
||||
@@ -112,7 +117,7 @@ bool OtaProcess_class::initialize(void)
|
||||
.onEnd([]()
|
||||
{ log_i("End"); ota.m_otaState = otaDone; })
|
||||
.onProgress([](unsigned int progress, unsigned int total)
|
||||
{ log_i("Progress: %u%%\r", (progress / (total / 100))); ota.m_otaState = otaBusy; })
|
||||
{ log_i("Progress: %u%%\r", (progress / (total / 100))); ota.m_otaState = otaBusy; PowerKeepAlive();})
|
||||
.onError([](ota_error_t error)
|
||||
{
|
||||
log_e("Error[%u]: ", error);
|
||||
@@ -130,8 +135,9 @@ bool OtaProcess_class::initialize(void)
|
||||
{
|
||||
log_i("Otastate = initialize(start)");
|
||||
ArduinoOTA.begin();
|
||||
log_i("Ota ready, IPaddress:%s", WiFi.localIP());
|
||||
log_i("Ota ready, IPaddress:%s", WiFi.localIP().toString());
|
||||
m_otaState = otaInitDone;
|
||||
setLedBlink(true);
|
||||
}
|
||||
break;
|
||||
case otaInitDone:
|
||||
|
||||
@@ -38,7 +38,7 @@ class OtaProcess_class : public processClass
|
||||
public:
|
||||
OtaProcess_class(uint32_t timeout):processClass(timeout){}
|
||||
|
||||
OTASTATES m_otaState = otaInit;
|
||||
OTASTATES m_otaState = otaInit;
|
||||
|
||||
};
|
||||
|
||||
|
||||
@@ -121,6 +121,7 @@ void handlePowerState(void)
|
||||
// init all
|
||||
log_i("powerinit");
|
||||
SetLedColor(CRGB::Green);
|
||||
//initConfig();
|
||||
powerstate = on;
|
||||
}
|
||||
break;
|
||||
|
||||
@@ -10,9 +10,9 @@
|
||||
|
||||
|
||||
#define TIMEOUT_POWER (7 * 1000 * 60) // 7 minutes timeout
|
||||
#define POWERBUTTONDELAY 1000
|
||||
#define POWERBUTTONDELAY 400
|
||||
//#define BATTERYMEASUREDELAY 60000
|
||||
#define POWERBUTTONOTADELAY 7000
|
||||
#define POWERBUTTONOTADELAY 4000
|
||||
#define POWEROFFOFFDELAY 3000
|
||||
|
||||
typedef enum
|
||||
|
||||
@@ -4,6 +4,11 @@ PN532_SPI pn532spi(SPI, NFC_SS, NFC_SCK, NFC_MISO, NFC_MOSI);
|
||||
NfcAdapter nfc = NfcAdapter(pn532spi);
|
||||
|
||||
uint32_t lastRFID = 0;
|
||||
uint32_t lastRFIDlog = 0;
|
||||
uint32_t lastTagTime = 0;
|
||||
|
||||
//settings
|
||||
uint32_t scantimeout = 0;
|
||||
|
||||
String lastUid = "";
|
||||
|
||||
@@ -15,6 +20,7 @@ void initRfid()
|
||||
{
|
||||
log_i("RFID init:"); // shows in serial that it is ready to read
|
||||
nfc.begin(true);
|
||||
scantimeout = GetIntparam("ScanTimeout", RFIDTIMEOUT );
|
||||
RfidinitOK = true;
|
||||
log_i("RFID init: OK"); // shows in serial that it is ready to read
|
||||
}
|
||||
@@ -23,19 +29,30 @@ void initRfid()
|
||||
void handleRfid()
|
||||
{
|
||||
uint32_t timeNow = millis();
|
||||
if (lastRFID - timeNow > RFIDINTERVAL && RfidScanActive)
|
||||
if (timeNow - lastRFID > RFIDINTERVAL && RfidScanActive)
|
||||
{
|
||||
log_i("scanning");
|
||||
if (nfc.tagPresent(100))
|
||||
if(timeNow - lastRFIDlog > RFIDLOGINTERVAL)
|
||||
{
|
||||
log_i("scanning");
|
||||
lastRFIDlog = timeNow;
|
||||
}
|
||||
|
||||
if (nfc.tagPresent(RFIDTIMEOUT))
|
||||
{
|
||||
NfcTag tag = nfc.read();
|
||||
lastUid = tag.getUidString();
|
||||
lastTagTime = millis();
|
||||
log_i("found tag %s",lastUid.c_str());
|
||||
}
|
||||
lastRFID = timeNow;
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t getLastTagTime(void)
|
||||
{
|
||||
return lastTagTime;
|
||||
}
|
||||
|
||||
bool getRFIDInitStatus(void)
|
||||
{
|
||||
return RfidinitOK;
|
||||
@@ -46,6 +63,15 @@ String getRFIDlastUID(void)
|
||||
return lastUid;
|
||||
}
|
||||
|
||||
bool getRFIDlastUIDValid(void)
|
||||
{
|
||||
if(lastUid == "")
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return (getUIDvalid(lastUid));
|
||||
}
|
||||
|
||||
void setRFIDscanState(bool state)
|
||||
{
|
||||
RfidScanActive = state;
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
#include "board.h"
|
||||
#include "game.h"
|
||||
#include "config.h"
|
||||
|
||||
#include <SPI.h>
|
||||
#include "PN532_SPI.h"
|
||||
@@ -9,11 +10,15 @@
|
||||
#include "NfcAdapter.h"
|
||||
|
||||
#define NDEF_SUPPORT_MIFARE_CLASSIC
|
||||
#define RFIDINTERVAL 800
|
||||
#define RFIDINTERVAL 200
|
||||
#define RFIDLOGINTERVAL 5000
|
||||
#define RFIDTIMEOUT 50
|
||||
|
||||
void initRfid(void);
|
||||
void handleRfid(void);
|
||||
bool getRFIDInitStatus(void);
|
||||
String getRFIDlastUID(void);
|
||||
void setRFIDscanState(bool state);
|
||||
void clearRFIDlastUID(void);
|
||||
bool getRFIDlastUIDValid(void);
|
||||
void clearRFIDlastUID(void);
|
||||
uint32_t getLastTagTime(void);
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
#include "sensor.h"
|
||||
|
||||
AS5600 as5600; // use default Wire
|
||||
|
||||
ADS1115 ADS(0x48);
|
||||
Battery battery(VBATTMIN, VBATTMAX, MEAS_ADC, &getvbatt);
|
||||
|
||||
@@ -11,30 +13,23 @@ uint16_t BatterySensor = 0;
|
||||
uint16_t BatteryVoltage = 0;
|
||||
uint32_t BatteryWarningFirst = 0;
|
||||
|
||||
uint16_t HallSensor = 0;
|
||||
|
||||
uint32_t last_hall_read = 0;
|
||||
uint16_t last_hall_sample = 0;
|
||||
uint16_t last_hall_Delta = 0;
|
||||
uint8_t hall_idle_count = 0;
|
||||
uint8_t hall_decrease_count = 0;
|
||||
uint8_t hall_increase_count = 0;
|
||||
bool hall_is_Idle = true;
|
||||
|
||||
bool hallinitOK = false;
|
||||
bool ADSinitOK = false;
|
||||
bool ASinitOK = false;
|
||||
|
||||
bool getSensorInitStatus(void)
|
||||
{
|
||||
return hallinitOK;
|
||||
}
|
||||
|
||||
uint16_t getHall(void)
|
||||
{
|
||||
return HallSensor;
|
||||
return (ADSinitOK & ASinitOK);
|
||||
}
|
||||
|
||||
uint16_t getvbatt(uint8_t dummy = 0)
|
||||
{
|
||||
if(!ADSinitOK)
|
||||
{
|
||||
log_e("battery not initialized due to ADS error");
|
||||
return 0;
|
||||
}
|
||||
int16_t readbatt = ADS.readADC(MEAS_ADC);
|
||||
log_i("readvbat=%d", readbatt);
|
||||
return readbatt;
|
||||
@@ -45,26 +40,49 @@ bool hallIsIdle(void)
|
||||
return hall_is_Idle;
|
||||
}
|
||||
|
||||
bool initADS(void)
|
||||
{
|
||||
log_i("sensor init ADS1x15:");
|
||||
bool result = ADS.begin(I2C_SDA, I2C_SCL);
|
||||
ADS.setMode(0);
|
||||
result = ADS.isConnected();
|
||||
ADSinitOK = result;
|
||||
if(!result)
|
||||
{
|
||||
log_e("Failed to init ADS1x15");
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
void initBattery(void)
|
||||
{
|
||||
if(!ADSinitOK)
|
||||
{
|
||||
log_e("battery not initialized due to ADS error");
|
||||
return;
|
||||
}
|
||||
battery.onDemand(MEAS_EN, LOW);
|
||||
battery.begin(VBATTREF, (R12 + R13) / R13, &sigmoidal); // R1 = 220K, R2 = 100K, factor = (R1+R2)/R2
|
||||
}
|
||||
|
||||
bool initAS5600(void)
|
||||
{
|
||||
as5600.begin(); // set direction pin.
|
||||
as5600.setDirection(AS5600_CLOCK_WISE); // default, just be explicit.
|
||||
bool result = as5600.isConnected();
|
||||
ASinitOK = result;
|
||||
if(!result)
|
||||
{
|
||||
log_e("error initilizing AS5600");
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
void initSensor(void)
|
||||
{
|
||||
log_i("sensor init ADS1x15:");
|
||||
bool result = ADS.begin(I2C_SDA, I2C_SCL);
|
||||
initADS();
|
||||
initBattery();
|
||||
if (!result)
|
||||
{
|
||||
log_e("sensor init: FAIL");
|
||||
}
|
||||
else
|
||||
{
|
||||
log_i("sensor init: OK");
|
||||
hallinitOK = true;
|
||||
}
|
||||
initAS5600();
|
||||
}
|
||||
|
||||
bool CheckBattery(void)
|
||||
@@ -108,6 +126,11 @@ bool getLowBatt(void)
|
||||
void handleBatterySensor(void)
|
||||
{
|
||||
uint32_t timeNow = millis();
|
||||
|
||||
if(getAudioState())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (timeNow - lastVbatt > (VBATTINTERVALL - VBATTMEASPRECHARGE))
|
||||
{
|
||||
@@ -118,7 +141,7 @@ void handleBatterySensor(void)
|
||||
if (timeNow - lastVbatt > VBATTINTERVALL)
|
||||
{
|
||||
CheckBattery();
|
||||
log_i("vbatt voltage = %d mv", BatteryVoltage);
|
||||
log_i("vbatt level = %d %%", BatterySensor);
|
||||
if (BatterySensor > 80)
|
||||
SetLedColor(CRGB::Green);
|
||||
else if (BatterySensor > 50)
|
||||
@@ -129,187 +152,36 @@ void handleBatterySensor(void)
|
||||
}
|
||||
}
|
||||
|
||||
HALLSENSORSTATES hall_sensor_state = HALLSENSORSTATES::hall_idle;
|
||||
uint32_t hall_timeout = 0;
|
||||
uint32_t hall_stateTimer = 0;
|
||||
HALLSENSORSTATES previous_hall_state = hall_sensor_state;
|
||||
|
||||
#define HALLSTATETIMEOUT 300
|
||||
#define HALLTIMEOUT 1000
|
||||
|
||||
void handleHallSensor(void)
|
||||
{
|
||||
uint32_t timeNow = millis();
|
||||
if (timeNow - last_hall_read > HALLINTERVAL)
|
||||
|
||||
if (timeNow - lastADS < ADSINTERVAL)
|
||||
{
|
||||
// get sample
|
||||
uint16_t hall_sample = ADS.readADC(HALL_INPUT);
|
||||
int hall_delta = hall_sample - last_hall_sample;
|
||||
|
||||
switch (hall_sensor_state)
|
||||
{
|
||||
case hall_idle:
|
||||
{
|
||||
if (hall_delta > HALLTHRESHOLD)
|
||||
{
|
||||
hall_decrease_count = 0;
|
||||
if (hall_increase_count++ > HALLTHRESHOLD)
|
||||
{
|
||||
hall_sensor_state = hall_increasing;
|
||||
log_i("next state = increasing");
|
||||
}
|
||||
}
|
||||
else if (hall_delta < HALLTHRESHOLD)
|
||||
{
|
||||
hall_increase_count = 0;
|
||||
if (hall_decrease_count++ > HALLTHRESHOLD)
|
||||
{
|
||||
hall_sensor_state = hall_decreasing;
|
||||
log_i("next state = decreasing");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/* stay idle */
|
||||
}
|
||||
}
|
||||
break;
|
||||
case hall_decreasing:
|
||||
{
|
||||
// lets see if we are bottoming out or stalling
|
||||
if (hall_delta < HALLIDLETHRESHOLD)
|
||||
{
|
||||
// reset timer
|
||||
hall_timeout = timeNow;
|
||||
hall_stateTimer = timeNow;
|
||||
}
|
||||
|
||||
if (timeNow - hall_stateTimer > HALLSTATETIMEOUT)
|
||||
{
|
||||
// we are stalling or tipping under
|
||||
hall_sensor_state = hall_tipunder;
|
||||
hall_stateTimer = 0;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case hall_tipunder:
|
||||
{
|
||||
// check if we are stalling or moving into the increasing state
|
||||
if (!(hall_delta > HALLIDLETHRESHOLD))
|
||||
{
|
||||
hall_stateTimer = timeNow;
|
||||
}
|
||||
|
||||
if (timeNow - hall_stateTimer > HALLSTATETIMEOUT)
|
||||
{
|
||||
// samples detected to the upside, move to increasing state
|
||||
hall_sensor_state = hall_increasing;
|
||||
hall_stateTimer = 0;
|
||||
}
|
||||
|
||||
if(timeNow - hall_timeout > HALLTIMEOUT)
|
||||
{
|
||||
//timeed out, move to idle
|
||||
hall_sensor_state = hall_idle;
|
||||
hall_stateTimer = 0;
|
||||
hall_timeout = 0;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case hall_increasing:
|
||||
{
|
||||
// check if we are increasing
|
||||
if (hall_delta > HALLIDLETHRESHOLD)
|
||||
{
|
||||
hall_stateTimer = timeNow;
|
||||
}
|
||||
|
||||
if (timeNow - hall_stateTimer > HALLSTATETIMEOUT)
|
||||
{
|
||||
// samples detected to the upside, move to increasing state
|
||||
hall_sensor_state = hall_tipover;
|
||||
hall_stateTimer = 0;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case hall_tipover:
|
||||
{
|
||||
// check if we are stalling or moving into the increasing state
|
||||
if (!(hall_delta > HALLIDLETHRESHOLD))
|
||||
{
|
||||
hall_stateTimer = timeNow;
|
||||
}
|
||||
|
||||
if (timeNow - hall_stateTimer > HALLSTATETIMEOUT)
|
||||
{
|
||||
// samples detected to the upside, move to increasing state
|
||||
hall_sensor_state = hall_decreasing;
|
||||
hall_stateTimer = 0;
|
||||
}
|
||||
|
||||
if(timeNow - hall_timeout > HALLTIMEOUT)
|
||||
{
|
||||
//timeed out, move to idle
|
||||
hall_sensor_state = hall_idle;
|
||||
hall_stateTimer = 0;
|
||||
hall_timeout = 0;
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
{
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
bool skipfirstSample = false;
|
||||
if (!last_hall_Delta)
|
||||
{
|
||||
skipfirstSample = true;
|
||||
}
|
||||
uint16_t hall_delta = (last_hall_sample > hall_sample) ? (last_hall_sample - hall_sample) : (hall_sample - last_hall_sample);
|
||||
hall_delta = (hall_delta + last_hall_Delta) / 2;
|
||||
last_hall_Delta = hall_delta;
|
||||
if (skipfirstSample)
|
||||
{
|
||||
log_v("First sample skipped");
|
||||
if (hall_idle_count)
|
||||
{
|
||||
hall_idle_count--;
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (hall_delta > HALLIDLETHRESHOLD)
|
||||
{
|
||||
if (hall_idle_count > HALLIDLESAMPLES)
|
||||
{
|
||||
hall_is_Idle = false;
|
||||
hall_idle_count = HALLPLAYSAMPLES;
|
||||
log_i("Game: playing, delta = %d", hall_delta);
|
||||
}
|
||||
else
|
||||
{
|
||||
hall_idle_count++;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (hall_idle_count == 0)
|
||||
{
|
||||
hall_is_Idle = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
hall_idle_count--;
|
||||
}
|
||||
}
|
||||
log_i("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;
|
||||
//wait for timer
|
||||
return;
|
||||
}
|
||||
lastADS = timeNow;
|
||||
|
||||
int angle = as5600.getCumulativePosition();
|
||||
log_v("sensor angle %d", angle);
|
||||
|
||||
if( angle > HALLTHRESHOLD)
|
||||
{
|
||||
if(hall_is_Idle)
|
||||
{
|
||||
log_i("hall state changed to active(%i)", angle);
|
||||
}
|
||||
hall_is_Idle = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
if(!hall_is_Idle)
|
||||
{
|
||||
log_i("hall state changed to idle (%i)", angle);
|
||||
}
|
||||
hall_is_Idle = true;
|
||||
|
||||
}
|
||||
as5600.resetPosition();
|
||||
}
|
||||
@@ -1,30 +1,21 @@
|
||||
#pragma once
|
||||
|
||||
#include "Arduino.h"
|
||||
#include "ADS1X15.h"
|
||||
#include "Battery.h"
|
||||
#include "board.h"
|
||||
#include "led.h"
|
||||
#include "AS5600.h"
|
||||
#include "Wire.h"
|
||||
#include "audio.h"
|
||||
|
||||
#define ADSINTERVAL 100
|
||||
#define VBATTINTERVALL 15000
|
||||
#define VBATTMEASPRECHARGE 500
|
||||
#define LOWBATTPERIOD 30000
|
||||
#define ADSINTERVAL 100
|
||||
#define VBATTINTERVALL 15000
|
||||
#define VBATTMEASPRECHARGE 500
|
||||
#define LOWBATTPERIOD 30000
|
||||
|
||||
#define HALLINTERVAL 100
|
||||
#define HALLTHRESHOLD 5
|
||||
#define HALLIDLETHRESHOLD 10
|
||||
#define HALLIDLESAMPLES 15
|
||||
#define HALLPLAYSAMPLES 24
|
||||
|
||||
typedef enum
|
||||
{
|
||||
hall_idle,
|
||||
hall_increasing,
|
||||
hall_tipover,
|
||||
hall_decreasing,
|
||||
hall_tipunder,
|
||||
HALL_LAST
|
||||
}HALLSENSORSTATES;
|
||||
|
||||
static String HALLSENESORSTATES_ENUM2STR[HALL_LAST]
|
||||
{
|
||||
@@ -39,7 +30,6 @@ void initSensor(void);
|
||||
void handleBatterySensor(void);
|
||||
void handleHallSensor(void);
|
||||
|
||||
|
||||
uint16_t getHall( void );
|
||||
bool hallIsIdle(void);
|
||||
uint16_t getvbatt(uint8_t dummy);
|
||||
@@ -47,5 +37,7 @@ bool getSensorInitStatus(void);
|
||||
|
||||
bool CheckBattery(void);
|
||||
bool getLowBatt(void);
|
||||
void readsensor(void);
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
#include "FS.h"
|
||||
|
||||
#if defined ESP_ARDUINO_VERSION_VAL
|
||||
#if (ESP_ARDUINO_VERSION >= ESP_ARDUINO_VERSION_VAL(2, 0, 0)
|
||||
#if (ESP_ARDUINO_VERSION >= ESP_ARDUINO_VERSION_VAL(2, 0, 0))
|
||||
#include <LittleFS.h>
|
||||
#define ESP_V2
|
||||
#endif
|
||||
|
||||
@@ -1,85 +0,0 @@
|
||||
{
|
||||
"cod": "200",
|
||||
"message": 0,
|
||||
"list": [
|
||||
{
|
||||
"dt": 1581498000,
|
||||
"main": {
|
||||
"temp": 3.23,
|
||||
"feels_like": -3.63,
|
||||
"temp_min": 3.23,
|
||||
"temp_max": 4.62,
|
||||
"pressure": 1014,
|
||||
"sea_level": 1014,
|
||||
"grnd_level": 1010,
|
||||
"humidity": 58,
|
||||
"temp_kf": -1.39
|
||||
},
|
||||
"weather": [
|
||||
{
|
||||
"id": 800,
|
||||
"main": "Clear",
|
||||
"description": "clear sky",
|
||||
"icon": "01d"
|
||||
}
|
||||
],
|
||||
"clouds": {
|
||||
"all": 0
|
||||
},
|
||||
"wind": {
|
||||
"speed": 6.19,
|
||||
"deg": 266
|
||||
},
|
||||
"sys": {
|
||||
"pod": "d"
|
||||
},
|
||||
"dt_txt": "2020-02-12 09:00:00"
|
||||
},
|
||||
{
|
||||
"dt": 1581508800,
|
||||
"main": {
|
||||
"temp": 6.09,
|
||||
"feels_like": -1.07,
|
||||
"temp_min": 6.09,
|
||||
"temp_max": 7.13,
|
||||
"pressure": 1015,
|
||||
"sea_level": 1015,
|
||||
"grnd_level": 1011,
|
||||
"humidity": 48,
|
||||
"temp_kf": -1.04
|
||||
},
|
||||
"weather": [
|
||||
{
|
||||
"id": 800,
|
||||
"main": "Clear",
|
||||
"description": "clear sky",
|
||||
"icon": "01d"
|
||||
}
|
||||
],
|
||||
"clouds": {
|
||||
"all": 9
|
||||
},
|
||||
"wind": {
|
||||
"speed": 6.64,
|
||||
"deg": 268
|
||||
},
|
||||
"sys": {
|
||||
"pod": "d"
|
||||
},
|
||||
"dt_txt": "2020-02-12 12:00:00"
|
||||
}
|
||||
],
|
||||
"city": {
|
||||
"id": 2643743,
|
||||
"name": "London",
|
||||
"coord": {
|
||||
"lat": 51.5085,
|
||||
"lon": -0.1257
|
||||
},
|
||||
"country": "GB",
|
||||
"population": 1000000,
|
||||
"timezone": 0,
|
||||
"sunrise": 1581492085,
|
||||
"sunset": 1581527294
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user