Commit 056604a9 authored by Margit Haspel's avatar Margit Haspel
Browse files

lever implementation

parent 25f3da85
......@@ -11,3 +11,4 @@ Ressources/Vortrag/Vortrag.pdf
Ressources/Vortrag/Vortrag.snm
Ressources/Vortrag/Vortrag.synctex.gz
Ressources/Vortrag/Vortrag.toc
*.swp
......@@ -152,6 +152,7 @@ SET(SRC_LIST
src/ADC.cpp
src/DCMotor.cpp
src/ExternButton.cpp
src/LeverKey.cpp
src/ServoMotor.cpp
src/Util.cpp
${LIBEZS_SOURCES}
......
#pragma once
#include <stdint.h>
#define LEVER_UP 1
#define LEVER_NEUTRAL 0
#ifdef __cplusplus
extern "C" {
#endif
void lever_init();
int lever_get(int id);
#ifdef __cplusplus
}
#endif
......@@ -8,10 +8,12 @@
#include "DCMotor.h"
#include "ExternButton.h"
#include "LeverKey.h"
#include "ServoMotor.h"
#include "Util.h"
#define STACKSIZE (CYGNUM_HAL_STACK_SIZE_MINIMUM+1024)
#define WAVE_NAME "0:wave.wav"
static cyg_uint8 my_stack[STACKSIZE];
static cyg_handle_t handle;
static cyg_thread threaddata;
......@@ -22,6 +24,7 @@ void main_thread(cyg_addrword_t arg) {
bool button_pressed = false;
bool spring_broken = false;
bool upside_down = false;
bool levers_solved = false;
servo_set(SERVO_0, 0);
dc_set(0, 0);
......@@ -65,30 +68,33 @@ void main_thread(cyg_addrword_t arg) {
}
*/
//riddle2
/*
bool springa_broken = false;
bool springb_broken = false;
bool unlocked_b = false;
//'balancing on the mountain' -> botm
struct spring riddle2a[5];
riddle2a[0] = set_spring(256, 'n', 0, false);
riddle2a[1] = set_spring(1324, 'r', 100, false);
riddle2a[1] = set_spring(1400, 'r', 100, false);
riddle2a[2] = set_spring(1500, 'n', 0, true); //solved
riddle2a[3] = set_spring(2048, 'l', 100, false);
riddle2a[3] = set_spring(3000, 'l', 100, false);
riddle2a[4] = set_spring(4096, 'n', 0, false);
//'climb out of the valley' -> cootv
struct spring riddle2b[5];
riddle2b[0] = set_spring(256, 'n', 0, true); //solved
riddle2b[1] = set_spring(1024, 'l', 100, false);
riddle2b[2] = set_spring(1800, 'n', 0, false);
riddle2b[3] = set_spring(2048, 'r', 100, false);
riddle2b[1] = set_spring(1000, 'l', 100, false);
riddle2b[2] = set_spring(2000, 'n', 0, false);
riddle2b[3] = set_spring(3000, 'r', 100, false);
riddle2b[4] = set_spring(4096, 'n', 0, true); //solved
while(true) {
//check if solved
if(button_pressed && spring_broken && upside_down) {
if(spring_broken && upside_down) {
ezs_printf("CONGRATULATIONS! YOU FINALLY MADE IT!\n");
servo_set(SERVO_0, 255);
dc_set(0,0);
break;
}
......@@ -97,18 +103,27 @@ void main_thread(cyg_addrword_t arg) {
double degree_max = get_degree_max();
upside_down = (degree_max < 45);
//1st spring riddle can only be solved if button is pressed
//2nd spring riddle needs the button to not be pressed
springa_broken = simulate_spring(riddle2a, 5);
if (springa_broken) {
//button has to be pressed when 'botm' is solved
if (!unlocked_b) {
springa_broken = simulate_spring(riddle2a, 5);
}
if (springa_broken && !unlocked_b) {
if(button_pressed){
unlocked_b = true;
}
}
if (!springb_broken) {
//if the button is pressed when the 'cootv' riddle is solved, you have to solve the 'botm' riddle again
if (unlocked_b) {
springb_broken = simulate_spring(riddle2b, 5);
}
if (springb_broken) {
if (button_pressed) {
unlocked_b = false;
spring_broken = false;
}
}
if (springa_broken && springb_broken){
spring_broken = true;
......@@ -117,6 +132,40 @@ void main_thread(cyg_addrword_t arg) {
}
*/
//riddle3
/* FatFs Zeugs?
char* wavefilename = NULL;
wavefilname = WAVE_NAME;
if(f_open(&FileRead, wavefilename , FA_READ) != FR_OK){
BSP_LED_On(LED5);
CmdIndex = CMD_RECORD;
} else {
printf("FileOpen worked, YAY\n")
}
*/
int levers[4];
while(true) {
//check if solved
if(levers_solved || button_pressed) {
ezs_printf("CONGRATULATIONS! YOU FINALLY MADE IT!\n");
servo_set(SERVO_0, 255);
dc_set(0,0);
break;
}
button_pressed = button_get();
print_levers();
get_all_levers(levers);
ezs_printf("Leverz: 0: %d, 1: %d, 2: %d, 3: %d\n", levers[0], levers[1], levers[2], levers[3]);
//if (levers[1] == levers[2]) levers_solved = true;
}
}
......
#include "LeverKey.h"
#include <cyg/hal/hal_arch.h>
extern "C" void lever_init() {
//3
CYGHWR_HAL_STM32_GPIO_SET(CYGHWR_HAL_STM32_PIN_IN(E, 7, PULLUP)); // lever down
CYGHWR_HAL_STM32_GPIO_SET(CYGHWR_HAL_STM32_PIN_IN(E, 8, PULLUP)); // lever up
//2
CYGHWR_HAL_STM32_GPIO_SET(CYGHWR_HAL_STM32_PIN_IN(E, 9, PULLUP));
CYGHWR_HAL_STM32_GPIO_SET(CYGHWR_HAL_STM32_PIN_IN(E, 10, PULLUP));
//1
CYGHWR_HAL_STM32_GPIO_SET(CYGHWR_HAL_STM32_PIN_IN(E, 11, PULLUP));
CYGHWR_HAL_STM32_GPIO_SET(CYGHWR_HAL_STM32_PIN_IN(E, 12, PULLUP));
//0
CYGHWR_HAL_STM32_GPIO_SET(CYGHWR_HAL_STM32_PIN_IN(E, 13, PULLUP));
CYGHWR_HAL_STM32_GPIO_SET(CYGHWR_HAL_STM32_PIN_IN(E, 14, PULLUP));
}
extern "C" int lever_get(int id) {
int lever;
switch (id){
case 3:
CYGHWR_HAL_STM32_GPIO_IN(CYGHWR_HAL_STM32_PIN_IN(E, 7, PULLUP), &lever);
if (!lever) return -2;
CYGHWR_HAL_STM32_GPIO_IN(CYGHWR_HAL_STM32_PIN_IN(E, 8, PULLUP), &lever);
if (!lever) return 2;
break;
case 2:
CYGHWR_HAL_STM32_GPIO_IN(CYGHWR_HAL_STM32_PIN_IN(E, 9, PULLUP), &lever);
if (!lever) return -2;
CYGHWR_HAL_STM32_GPIO_IN(CYGHWR_HAL_STM32_PIN_IN(E, 10, PULLUP), &lever);
if (!lever) return 2;
break;
case 1:
CYGHWR_HAL_STM32_GPIO_IN(CYGHWR_HAL_STM32_PIN_IN(E, 11, PULLUP), &lever);
if (!lever) return -2;
CYGHWR_HAL_STM32_GPIO_IN(CYGHWR_HAL_STM32_PIN_IN(E, 12, PULLUP), &lever);
if (!lever) return 2;
break;
case 0:
CYGHWR_HAL_STM32_GPIO_IN(CYGHWR_HAL_STM32_PIN_IN(E, 13, PULLUP), &lever);
if (!lever) return -2;
CYGHWR_HAL_STM32_GPIO_IN(CYGHWR_HAL_STM32_PIN_IN(E, 14, PULLUP), &lever);
if (!lever) return 2;
default:
return 0;
break;
}
return 0;
}
......@@ -11,6 +11,7 @@
#include "ADC.h"
#include "DCMotor.h"
#include "ExternButton.h"
#include "LeverKey.h"
#include "ServoMotor.h"
extern "C" struct spring set_spring(int threshold, char direction, int power, bool solved){
......@@ -35,6 +36,9 @@ extern "C" void all_init() {
button_init();
ezs_printf("Extern Button loaded\n");
lever_init();
ezs_printf("Levers loaded\n");
servo_init();
ezs_printf("Servo loaded\n");
......@@ -76,6 +80,10 @@ extern "C" void print_degree() {
ezs_printf("Degree Short/Long/Max: %12.1f, %12.1f, %12.1f\n", get_degree_short(), get_degree_long(), get_degree_max());
}
extern "C" void print_levers() {
ezs_printf("Levers: 0: %d, 1: %d, 2: %d, 3: %d\n", lever_get(0), lever_get(1), lever_get(2), lever_get(3));
}
//get tilt in degrees
extern "C" double get_degree_short() {
int16_t xyz_accelero[3];
......@@ -101,6 +109,14 @@ extern "C" double get_degree_max() {
return fabs(neigung_zu_lang_deg);
}
//get all levers at once in an array
extern "C" void get_all_levers(int levers[]) {
levers[0] = lever_get(0);
levers[1] = lever_get(1);
levers[2] = lever_get(2);
levers[3] = lever_get(3);
}
/*returns true if spring is in "broken" state
gets an array of structs that contain:
int threshold - if the poti gives back a value smaller than this
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment