forked from Concept-Bytes/Open-Chess
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsensor_test.cpp
More file actions
65 lines (53 loc) · 2.17 KB
/
sensor_test.cpp
File metadata and controls
65 lines (53 loc) · 2.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#include "sensor_test.h"
#include <Arduino.h>
// Expected initial configuration for sensor testing
// Standard chess: Queen on her own color (white queen on light, black queen on dark)
const char SensorTest::INITIAL_BOARD[8][8] = {
{'R', 'N', 'B', 'K', 'Q', 'B', 'N', 'R'}, // row 0 (rank 8 - black pieces at top)
{'P', 'P', 'P', 'P', 'P', 'P', 'P', 'P'}, // row 1 (rank 7)
{' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '}, // row 2 (rank 6)
{' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '}, // row 3 (rank 5)
{' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '}, // row 4 (rank 4)
{' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '}, // row 5 (rank 3)
{'p', 'p', 'p', 'p', 'p', 'p', 'p', 'p'}, // row 6 (rank 2)
{'r', 'n', 'b', 'k', 'q', 'b', 'n', 'r'} // row 7 (rank 1 - white pieces at bottom)
};
SensorTest::SensorTest(BoardDriver* bd) : boardDriver(bd) {
}
void SensorTest::begin() {
Serial.println("Starting Sensor Test Mode...");
Serial.println("Place pieces on the board to see them light up!");
Serial.println("This mode continuously displays detected pieces.");
boardDriver->clearAllLEDs();
}
void SensorTest::update() {
// Read current sensor state
boardDriver->readSensors();
// Clear all LEDs first
boardDriver->clearAllLEDs();
// Light up squares where pieces are detected
for (int row = 0; row < 8; row++) {
for (int col = 0; col < 8; col++) {
if (boardDriver->getSensorState(row, col)) {
// Light up detected pieces in white
boardDriver->setSquareLED(row, col, 0, 0, 0, 255);
}
}
}
// Show the updated LED state
boardDriver->showLEDs();
// Print board state periodically for debugging
static unsigned long lastPrint = 0;
if (millis() - lastPrint > 2000) { // Print every 2 seconds
boardDriver->printBoardState(INITIAL_BOARD);
lastPrint = millis();
}
delay(100); // Small delay to prevent overwhelming the system
}
bool SensorTest::isActive() {
return true; // Always active once started
}
void SensorTest::reset() {
boardDriver->clearAllLEDs();
Serial.println("Sensor test reset - ready for testing!");
}