4 Commits

Author SHA1 Message Date
unlockable
df4e264dba 不再需要诱导 2023-09-10 13:44:55 +08:00
unlockable
f0d7ac873e Merge branch '尝试clock' 2023-09-10 12:03:23 +08:00
unlockable
378d387986 显示文字! 2023-09-10 11:11:23 +08:00
unlockable
449d3c098e 尝试words。 2023-09-09 21:54:38 +08:00

View File

@@ -20,7 +20,7 @@
#define MAG_UPDATE 0x08
#define READ_UPDATE 0x80
#define DEBUG true
#define DEBUG false
#define TRACE false
// 3 width, 4 height
@@ -31,7 +31,7 @@ const uint16_t numbers[10] = {
// 8 width, 7 height
const uint64_t letters[26]{
const uint64_t letters[]{
0x3C66667E666666, // A
0x7C66667C66667C, // B
0x3C66606060663C, // C
@@ -58,6 +58,16 @@ const uint64_t letters[26]{
0x6363361C366363, // X
0x6666663C181818, // Y
0x7E060C1830607E, // Z
0x3C666E7666663C, // 0
0x1818381818187E, // 1
0x3C66060C30607E, // 2
0x3C66061C06663C, // 3
0x0C1C2C4C7E0C0C, // 4
0x7E607C0606663C, // 5
0x3C66607C66663C, // 6
0x7E660C0C181818, // 7
0x3C66663C66663C, // 8
0x3C66663E06663C, // 9
};
struct Triple {
@@ -156,6 +166,11 @@ public:
}
}
if (WitSetBandwidth(BANDWIDTH_256HZ) != WIT_HAL_OK) {
Serial.println("Set Bandwidth Error");
return false;
}
if (WitSetContent(RSW_ANGLE | RSW_ACC | RSW_GYRO) != WIT_HAL_OK) {
Serial.println("Set send content: angle, acc, and GYRO Error");
return false;
@@ -424,14 +439,14 @@ public:
// 1 = look reverse x
// 2 = look along y
// 3 = look reverse y
if (num > 25 || num < 0) {
if (num >= sizeof(letters) || num < 0) {
return;
}
switch (direction) {
case 0: {
for (int i = 0; i < 8; i++) {
for (int j = 0; j < 7; j++) {
if ((numbers[num] >> (55 - (i + j * 8))) & 1) {
if ((letters[num] >> (55 - (i + j * 8))) & 1) {
Cube::set_status(x, y - i, z - j, brightness);
}
else {
@@ -444,7 +459,7 @@ public:
case 1: {
for (int i = 0; i < 8; i++) {
for (int j = 0; j < 7; j++) {
if ((numbers[num] >> (55 - (i + j * 8))) & 1) {
if ((letters[num] >> (55 - (i + j * 8))) & 1) {
Cube::set_status(x, y + i, z - j, brightness);
}
else {
@@ -457,7 +472,7 @@ public:
case 2: {
for (int i = 0; i < 8; i++) {
for (int j = 0; j < 7; j++) {
if ((numbers[num] >> (55 - (i + j * 8))) & 1) {
if ((letters[num] >> (55 - (i + j * 8))) & 1) {
Cube::set_status(x + i, y, z - j, brightness);
}
else {
@@ -470,7 +485,7 @@ public:
case 3: {
for (int i = 0; i < 8; i++) {
for (int j = 0; j < 7; j++) {
if ((numbers[num] >> (55 - (i + j * 8))) & 1) {
if ((letters[num] >> (55 - (i + j * 8))) & 1) {
Cube::set_status(x - i, y, z - j, brightness);
}
else {
@@ -883,6 +898,11 @@ byte cube_step = 1;
bool rain_create_new = false;
String display_string = "MUELSYSE";
int letter_create_layer_count = 0;
// When count to 7, it's time to draw the new letter.
int next_char_ptr = 0;
int clock_hour = 0, clock_minute = 0, clock_sec = 0, clock_sec_flip = 0;
ClockStatus clock_status;
bool clock_waiting_for_new_command = true;
@@ -1150,7 +1170,66 @@ void clock() {
}
void words() {
return;
if (Serial.available()) {
byte input_char = Serial.read();
if (input_char >= 'A' && input_char <= 'Z') {
display_string.concat((char)input_char);
}
if (input_char >= 'a' && input_char <= 'z') {
display_string.concat((char)(input_char - 'a' + 'A'));
}
if (input_char >= '0' && input_char <= '9') {
display_string.concat((char)input_char);
}
if (input_char == '?') {
Serial.print("Current string: ");
Serial.println(display_string);
}
if (input_char == '/') {
display_string = "";
next_char_ptr = 0;
Serial.println("Cleared input.");
}
}
delay(50);
// Move everything one light forward.
for (int i = 0; i < 8; i++) {
for (int j = 0; j < 8; j++) {
Cube::LED_brightness[i][j] = Cube::LED_brightness[i][j] >> 2;
Cube::LED_status[i][j] = Cube::LED_status[i][j] >> 2;
}
}
letter_create_layer_count++;
if (letter_create_layer_count < 7) {
// The previous have not been moved out
return;
}
letter_create_layer_count = 0;
if (next_char_ptr == display_string.length()) {
// Displayed all chars. 'Display' a space and reverse to the first char.
next_char_ptr = 0;
return;
}
if (display_string[next_char_ptr] >= 'A') {
Cube::draw_letter(0, 7, 7, display_string[next_char_ptr] - 'A', 2, 3);
}
else {
Serial.print(display_string[next_char_ptr]);
Cube::draw_letter(0, 7, 7, display_string[next_char_ptr] - '0' + 26, 2,
3);
}
next_char_ptr++;
}
void calculate_and_draw() {
@@ -1230,8 +1309,8 @@ void calculate_and_draw() {
if (SensorReader::angle.z - z_ref > 40.0) {
if (DEBUG) {
Serial.println(SensorReader::angle.z);
Serial.println("e");
}
Serial.println("Zoom out");
zoom /= 2.0;
need_reevaluate = true;
waiting_for_command = false;
@@ -1239,8 +1318,8 @@ void calculate_and_draw() {
else if (SensorReader::angle.z - z_ref < -40.0) {
if (DEBUG) {
Serial.println(SensorReader::angle.z);
Serial.println("f");
}
Serial.println("Zoom in");
zoom *= 2.0;
need_reevaluate = true;
waiting_for_command = false;