Skip to content

Commit

Permalink
Fix blinking alignment, add homing showoff
Browse files Browse the repository at this point in the history
  • Loading branch information
DeflateAwning committed Jan 6, 2024
1 parent 22e0e30 commit 9b779af
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 12 deletions.
6 changes: 5 additions & 1 deletion GNCTR_Claw_Machine/include/game_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,12 @@
#include <stdint.h>

const uint16_t start_btn_led_blink_rate_ms = 400; // half-period
const uint16_t game_play_max_time_sec = 45; // FIXME: set to 45 for deployment
const uint16_t game_play_max_time_sec = 120; // FIXME: set to 45 for deployment
const uint32_t idle_time_to_start_demo_sec = 69; // FIXME: set to about a minute for deployment


// 1 in n chance of this being at the start of your play, or 0 to disable, or 1 to force
const uint8_t approx_homing_showoff_chance = 0; // this is lame anyway


#endif // __INCLUDE_GUARD_GAME_CONFIG_H_CLAW_MACHINE__
2 changes: 2 additions & 0 deletions GNCTR_Claw_Machine/include/main_drivers.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ void endgame_move_to_bin();
void move_claw_to_absolute_xy(long x, long y);
bool move_to_absolute_xy_and_watch_for_start_press(long x, long y);

void run_homing_showoff();

void i2c_scan();

void display_duration_sec(uint32_t duration_sec);
Expand Down
41 changes: 37 additions & 4 deletions GNCTR_Claw_Machine/src/main_drivers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ bool run_z_motor_for_duration_and_watch_start(z_motor_direction_t direction, uin
delay(Z_BRAKE_DURATION_MS);
}
set_z_motor_state(Z_MOTOR_DIRECTION_STOP);
set_start_button_led(false);
// set_start_button_led(false);
return false;
}

Expand Down Expand Up @@ -381,6 +381,10 @@ void home_x_axis()
Serial.println("INFO: Starting home_x_axis()");
set_stepper_enable(1);

// set direction as positive
x1Stepper.setSpeed(stepper_speed);
x2Stepper.setSpeed(stepper_speed);

// move the claw to the left until it hits the limit switch
while (!get_switch_state(LIMIT_X1) && !get_switch_state(LIMIT_X2)) {
x1Stepper.runSpeed();
Expand Down Expand Up @@ -478,7 +482,7 @@ void move_claw_to_absolute_xy(long x, long y) {
// blocking
// system should be homed

Serial.print("DBEUG: move_claw_to_absolute_xy(x=");
Serial.print("DEBUG: move_claw_to_absolute_xy(x=");
Serial.print(x);
Serial.print(", y=");
Serial.print(y);
Expand All @@ -487,7 +491,6 @@ void move_claw_to_absolute_xy(long x, long y) {
long xxyPos[] = {x, x, y};
xxySteppers.moveTo(xxyPos);
xxySteppers.runSpeedToPosition();

}

bool move_to_absolute_xy_and_watch_for_start_press(long x, long y) {
Expand Down Expand Up @@ -517,6 +520,7 @@ bool move_to_absolute_xy_and_watch_for_start_press(long x, long y) {
if (millis() - last_check_time > 100) {
last_check_time = millis();
if (get_switch_state(START_BTN)) {
set_start_button_led(false);
return true;
}
}
Expand All @@ -525,10 +529,39 @@ bool move_to_absolute_xy_and_watch_for_start_press(long x, long y) {
loop_update_start_button_blinking();
display_scrolling_press_start();
}
set_start_button_led(false);
// set_start_button_led(false);
return false;
}

void run_homing_showoff() {
// pointless thing because it's only 8am and Aleks is still an hour away

move_claw_to_absolute_xy(xAxisLength*0.8, yAxisLength*0.5);

home_x_axis();

// move_claw_to_absolute_xy(xAxisLength*0.4, 0);
// move_claw_to_absolute_xy(xAxisLength*0.6, 0);
// move_claw_to_absolute_xy(xAxisLength*0.4, 0);
// move_claw_to_absolute_xy(xAxisLength*0.6, 0);

// grab
set_claw_state(CLAW_ENGAGE);
delay(250);
set_claw_state(CLAW_RELEASE);

}

void easter_egg_gnctr_theme() {
// G-N-CTR, GNCTR

#define MELODY_Z 0x10
#define MELODY_REST 0x20

// uint8_t melody[] = {
// MELODY_Z | 2,
// MELODY_REST |
}

void loop_moveMotorsBasedOnButtons()
{
Expand Down
13 changes: 6 additions & 7 deletions GNCTR_Claw_Machine/src/states.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
#include "main_drivers.h"

// persistent vars for GAME_STATE_IDLE
bool start_btn_led_state = false;
uint32_t start_btn_led_last_toggle_time_ms = 0;
uint32_t idle_start_time_ms = 0;

// persistent vars for GAME_STATE_PLAY
Expand Down Expand Up @@ -59,11 +57,7 @@ game_state_t idle_state(game_state_t prev)
display_scrolling_press_start();

// flash the START_BTN LED
if (millis() - start_btn_led_last_toggle_time_ms > start_btn_led_blink_rate_ms) {
start_btn_led_state = !start_btn_led_state;
set_start_button_led(start_btn_led_state);
start_btn_led_last_toggle_time_ms = millis();
}
loop_update_start_button_blinking();

// set the motors idle
set_z_motor_state(Z_MOTOR_DIRECTION_STOP);
Expand Down Expand Up @@ -207,6 +201,11 @@ game_state_t play_state(game_state_t prev)

set_start_button_led(false);

if (approx_homing_showoff_chance > 0 && (millis() % approx_homing_showoff_chance) == 0) {
Serial.println("INFO: doing homing showoff, by random chance");
run_homing_showoff();
}

// do a countdown (4444, 3333, 2222, 1111) [LAME]
// for (uint16_t i = 3333; i >= 1111; i -= 1111) {
// display_int(i);
Expand Down

0 comments on commit 9b779af

Please sign in to comment.