Format everything
The next commit will add this to a `.git-blame-ignore-revs` file which
you can use to ignore this commit when running git blame. Simply run
git blame --ignore-revs-file .git-blame-ignore-revs [...]
Or configure git to persistently ignore the commit:
git config blame.ignoreRevsFile .git-blame-ignore-revs
This commit is contained in:
@ -1,142 +1,144 @@
|
||||
#include "FT18_STW_INIT.h"
|
||||
|
||||
#include <Arduino.h>
|
||||
#include <Bounce2.h>
|
||||
#include <RotaryEncoder.h>
|
||||
|
||||
volatile stw_data_type Stw_data = {0}; //alles mit 0 initialisieren
|
||||
volatile vehicle_data_type Vehicle_data = {0}; //alles mit 0 initialisieren
|
||||
bool enc1PinALast,enc1PinANow,enc2PinALast,enc2PinANow;
|
||||
int led[] = {led1,led2,led3,led4,led5,led6,led7,led8,led9,led10,led11,led12,led13,led14,led15,led16};
|
||||
bool entprell;
|
||||
int buttons[] = {button1,button2,button3,button4,button5,button6,enc1PinS,enc2PinS};
|
||||
constexpr size_t N_BUTTONS = sizeof(buttons)/sizeof(buttons[0]);
|
||||
Bounce2::Button debouncer[N_BUTTONS];
|
||||
double val = 0;
|
||||
double val2 = 0;
|
||||
RotaryEncoder encoder(enc1PinA,enc1PinB,1,1,50);
|
||||
RotaryEncoder encoder2(enc2PinA,enc2PinB,1,1,50);
|
||||
///////////////////////////////////////////////////
|
||||
// functions
|
||||
///////////////////////////////////////////////////
|
||||
|
||||
void set_pins(){
|
||||
pinMode (l,OUTPUT);
|
||||
for (int thisLed = 0; thisLed < sizeof(led)/sizeof(int); thisLed++) {
|
||||
pinMode(led[thisLed], OUTPUT);
|
||||
}
|
||||
pinMode(enc1PinA, INPUT);
|
||||
pinMode(enc1PinB, INPUT);
|
||||
pinMode(enc2PinA, INPUT);
|
||||
pinMode(enc2PinB, INPUT);
|
||||
enc1PinALast=LOW;
|
||||
enc1PinANow=LOW;
|
||||
enc2PinALast=LOW;
|
||||
enc2PinANow=LOW;
|
||||
for(int i = 0; i < N_BUTTONS; i++){
|
||||
debouncer[i].attach(buttons[i], INPUT);
|
||||
debouncer[i].interval(10);
|
||||
}
|
||||
}
|
||||
|
||||
void read_buttons(){
|
||||
for (int i = 0; i < N_BUTTONS; i++) {
|
||||
debouncer[i].update();
|
||||
}
|
||||
|
||||
// These are only used to send them out via CAN, so they only need to be
|
||||
// high once.
|
||||
Stw_data.Stw_neutral = debouncer[1].rose();
|
||||
Stw_data.Stw_auto_shift = debouncer[2].rose();
|
||||
Stw_data.Stw_shift_down = debouncer[4].rose();
|
||||
Stw_data.Stw_shift_up = debouncer[5].rose();
|
||||
|
||||
Stw_data.buttonState1 = debouncer[0].isPressed();
|
||||
Stw_data.buttonState4 = debouncer[3].isPressed();
|
||||
Stw_data.buttonStateEnc1 = debouncer[6].isPressed();
|
||||
Stw_data.buttonStateEnc2 = debouncer[7].isPressed();
|
||||
if (debouncer[0].rose()) {
|
||||
Stw_data.button1_rises++;
|
||||
}
|
||||
if (debouncer[3].rose()) {
|
||||
Stw_data.button4_rises++;
|
||||
}
|
||||
if (debouncer[6].rose()) {
|
||||
Stw_data.enc1_rises++;
|
||||
}
|
||||
if (debouncer[7].rose()) {
|
||||
Stw_data.enc2_rises++;
|
||||
}
|
||||
}
|
||||
|
||||
void read_rotary(){
|
||||
int enc = encoder.readEncoder();
|
||||
int enc2 = encoder2.readEncoder();
|
||||
if(enc != 0){
|
||||
val = val +0.5*enc;
|
||||
if (val==1 or val ==-1){
|
||||
if(Stw_data.trc==0 and enc<0){
|
||||
Stw_data.trc = 11;
|
||||
}else if(Stw_data.trc==11 and enc>0){
|
||||
Stw_data.trc=0;
|
||||
}else{
|
||||
Stw_data.trc = Stw_data.trc + enc;
|
||||
}
|
||||
val = 0;
|
||||
}
|
||||
}
|
||||
/*enc1PinANow = digitalRead(enc1PinA);
|
||||
enc2PinANow = digitalRead(enc2PinA);
|
||||
if ((enc1PinALast == LOW) && (enc1PinANow == HIGH)) {
|
||||
if (digitalRead(enc1PinB) == HIGH) {
|
||||
if(Stw_data.trc==0){
|
||||
Stw_data.trc = 5;
|
||||
}else{
|
||||
Stw_data.trc--;
|
||||
}
|
||||
}else {
|
||||
if(Stw_data.trc==5){
|
||||
Stw_data.trc=0;
|
||||
}else{
|
||||
Stw_data.trc++;
|
||||
}
|
||||
}
|
||||
}
|
||||
enc1PinALast = enc1PinANow;
|
||||
/*if (Stw_data.buttonStateEnc1 == HIGH){
|
||||
digitalWrite(led[Stw_data.i], HIGH);
|
||||
}*/
|
||||
if(enc2 != 0){
|
||||
val2 = val2 +0.5*enc2;
|
||||
if(val2==1 or val2==-1){
|
||||
if((Stw_data.mode==1 or Stw_data.mode==0) and enc2<0){
|
||||
Stw_data.mode = 5;
|
||||
}else if(Stw_data.mode==5 and enc2>0){
|
||||
Stw_data.mode=1;
|
||||
}else{
|
||||
Stw_data.mode = Stw_data.mode + enc2;
|
||||
}
|
||||
val2=0;
|
||||
}
|
||||
}
|
||||
/*if ((enc2PinALast == LOW) && (enc2PinANow == HIGH)) {
|
||||
//if(enc2PinALast != enc2PinANow){
|
||||
if (digitalRead(enc2PinB) == HIGH) {
|
||||
if(Stw_data.i==0){
|
||||
Stw_data.i = sizeof(led)/sizeof(int)-1;
|
||||
}else{
|
||||
Stw_data.i--;
|
||||
}
|
||||
}else {
|
||||
if(Stw_data.i==sizeof(led)/sizeof(int)-1){
|
||||
Stw_data.i=0;
|
||||
}else{
|
||||
Stw_data.i++;
|
||||
}
|
||||
}
|
||||
}
|
||||
enc2PinALast = enc2PinANow;*/
|
||||
/*if (Stw_data.buttonStateEnc2 == HIGH){
|
||||
digitalWrite(led[Stw_data.i], HIGH);
|
||||
}*/
|
||||
}
|
||||
#include "FT18_STW_INIT.h"
|
||||
|
||||
#include <Arduino.h>
|
||||
#include <Bounce2.h>
|
||||
#include <RotaryEncoder.h>
|
||||
|
||||
volatile stw_data_type Stw_data = {0}; // alles mit 0 initialisieren
|
||||
volatile vehicle_data_type Vehicle_data = {0}; // alles mit 0 initialisieren
|
||||
bool enc1PinALast, enc1PinANow, enc2PinALast, enc2PinANow;
|
||||
int led[] = {led1, led2, led3, led4, led5, led6, led7, led8,
|
||||
led9, led10, led11, led12, led13, led14, led15, led16};
|
||||
bool entprell;
|
||||
int buttons[] = {button1, button2, button3, button4,
|
||||
button5, button6, enc1PinS, enc2PinS};
|
||||
constexpr size_t N_BUTTONS = sizeof(buttons) / sizeof(buttons[0]);
|
||||
Bounce2::Button debouncer[N_BUTTONS];
|
||||
double val = 0;
|
||||
double val2 = 0;
|
||||
RotaryEncoder encoder(enc1PinA, enc1PinB, 1, 1, 50);
|
||||
RotaryEncoder encoder2(enc2PinA, enc2PinB, 1, 1, 50);
|
||||
///////////////////////////////////////////////////
|
||||
// functions
|
||||
///////////////////////////////////////////////////
|
||||
|
||||
void set_pins() {
|
||||
pinMode(l, OUTPUT);
|
||||
for (int thisLed = 0; thisLed < sizeof(led) / sizeof(int); thisLed++) {
|
||||
pinMode(led[thisLed], OUTPUT);
|
||||
}
|
||||
pinMode(enc1PinA, INPUT);
|
||||
pinMode(enc1PinB, INPUT);
|
||||
pinMode(enc2PinA, INPUT);
|
||||
pinMode(enc2PinB, INPUT);
|
||||
enc1PinALast = LOW;
|
||||
enc1PinANow = LOW;
|
||||
enc2PinALast = LOW;
|
||||
enc2PinANow = LOW;
|
||||
for (int i = 0; i < N_BUTTONS; i++) {
|
||||
debouncer[i].attach(buttons[i], INPUT);
|
||||
debouncer[i].interval(10);
|
||||
}
|
||||
}
|
||||
|
||||
void read_buttons() {
|
||||
for (int i = 0; i < N_BUTTONS; i++) {
|
||||
debouncer[i].update();
|
||||
}
|
||||
|
||||
// These are only used to send them out via CAN, so they only need to be
|
||||
// high once.
|
||||
Stw_data.Stw_neutral = debouncer[1].rose();
|
||||
Stw_data.Stw_auto_shift = debouncer[2].rose();
|
||||
Stw_data.Stw_shift_down = debouncer[4].rose();
|
||||
Stw_data.Stw_shift_up = debouncer[5].rose();
|
||||
|
||||
Stw_data.buttonState1 = debouncer[0].isPressed();
|
||||
Stw_data.buttonState4 = debouncer[3].isPressed();
|
||||
Stw_data.buttonStateEnc1 = debouncer[6].isPressed();
|
||||
Stw_data.buttonStateEnc2 = debouncer[7].isPressed();
|
||||
if (debouncer[0].rose()) {
|
||||
Stw_data.button1_rises++;
|
||||
}
|
||||
if (debouncer[3].rose()) {
|
||||
Stw_data.button4_rises++;
|
||||
}
|
||||
if (debouncer[6].rose()) {
|
||||
Stw_data.enc1_rises++;
|
||||
}
|
||||
if (debouncer[7].rose()) {
|
||||
Stw_data.enc2_rises++;
|
||||
}
|
||||
}
|
||||
|
||||
void read_rotary() {
|
||||
int enc = encoder.readEncoder();
|
||||
int enc2 = encoder2.readEncoder();
|
||||
if (enc != 0) {
|
||||
val = val + 0.5 * enc;
|
||||
if (val == 1 or val == -1) {
|
||||
if (Stw_data.trc == 0 and enc < 0) {
|
||||
Stw_data.trc = 11;
|
||||
} else if (Stw_data.trc == 11 and enc > 0) {
|
||||
Stw_data.trc = 0;
|
||||
} else {
|
||||
Stw_data.trc = Stw_data.trc + enc;
|
||||
}
|
||||
val = 0;
|
||||
}
|
||||
}
|
||||
/*enc1PinANow = digitalRead(enc1PinA);
|
||||
enc2PinANow = digitalRead(enc2PinA);
|
||||
if ((enc1PinALast == LOW) && (enc1PinANow == HIGH)) {
|
||||
if (digitalRead(enc1PinB) == HIGH) {
|
||||
if(Stw_data.trc==0){
|
||||
Stw_data.trc = 5;
|
||||
}else{
|
||||
Stw_data.trc--;
|
||||
}
|
||||
}else {
|
||||
if(Stw_data.trc==5){
|
||||
Stw_data.trc=0;
|
||||
}else{
|
||||
Stw_data.trc++;
|
||||
}
|
||||
}
|
||||
}
|
||||
enc1PinALast = enc1PinANow;
|
||||
/*if (Stw_data.buttonStateEnc1 == HIGH){
|
||||
digitalWrite(led[Stw_data.i], HIGH);
|
||||
}*/
|
||||
if (enc2 != 0) {
|
||||
val2 = val2 + 0.5 * enc2;
|
||||
if (val2 == 1 or val2 == -1) {
|
||||
if ((Stw_data.mode == 1 or Stw_data.mode == 0) and enc2 < 0) {
|
||||
Stw_data.mode = 5;
|
||||
} else if (Stw_data.mode == 5 and enc2 > 0) {
|
||||
Stw_data.mode = 1;
|
||||
} else {
|
||||
Stw_data.mode = Stw_data.mode + enc2;
|
||||
}
|
||||
val2 = 0;
|
||||
}
|
||||
}
|
||||
/*if ((enc2PinALast == LOW) && (enc2PinANow == HIGH)) {
|
||||
//if(enc2PinALast != enc2PinANow){
|
||||
if (digitalRead(enc2PinB) == HIGH) {
|
||||
if(Stw_data.i==0){
|
||||
Stw_data.i = sizeof(led)/sizeof(int)-1;
|
||||
}else{
|
||||
Stw_data.i--;
|
||||
}
|
||||
}else {
|
||||
if(Stw_data.i==sizeof(led)/sizeof(int)-1){
|
||||
Stw_data.i=0;
|
||||
}else{
|
||||
Stw_data.i++;
|
||||
}
|
||||
}
|
||||
}
|
||||
enc2PinALast = enc2PinANow;*/
|
||||
/*if (Stw_data.buttonStateEnc2 == HIGH){
|
||||
digitalWrite(led[Stw_data.i], HIGH);
|
||||
}*/
|
||||
}
|
||||
|
||||
@ -1,105 +1,101 @@
|
||||
#include "Arduino.h"
|
||||
#ifndef FT18_STW_Init
|
||||
#define FT18_STW_Init
|
||||
|
||||
#define l 78 //test_led
|
||||
#define led1 12//PD8
|
||||
#define led2 11//PD7
|
||||
#define led3 9//PC21
|
||||
#define led4 8//PC22
|
||||
#define led5 7//PC23
|
||||
#define led6 6//PC24
|
||||
#define led7 5//PC25
|
||||
#define led8 4//PC26 und PA29
|
||||
#define led9 3//PC28
|
||||
#define led10 2//PB25
|
||||
#define led11 10//PC29 und PA28
|
||||
#define led12 22//PB26
|
||||
#define led13 19//PA10
|
||||
#define led14 13//PB27
|
||||
#define led15 17//PA12
|
||||
#define led16 18//PA11
|
||||
#define button1 48//bl
|
||||
#define button2 47//gl
|
||||
#define button3 44//gr
|
||||
#define button4 46//br
|
||||
#define button5 45//sl
|
||||
#define button6 49//sr
|
||||
#define enc1PinA 37
|
||||
#define enc1PinB 38
|
||||
#define enc1PinS 35
|
||||
#define enc2PinA 40
|
||||
#define enc2PinB 41
|
||||
#define enc2PinS 39
|
||||
|
||||
|
||||
// define Drehzahlgrenzen TODOOOO
|
||||
#define RPM_THRES_1 1000
|
||||
#define RPM_THRES_2 6000
|
||||
#define RPM_THRES_3 7000
|
||||
#define RPM_THRES_4 8000
|
||||
#define RPM_THRES_5 10000
|
||||
#define RPM_THRES_6 14000
|
||||
#define RPM_THRES_7 17000
|
||||
#define RPM_THRES_8 18000
|
||||
#define RPM_THRES_9 20000
|
||||
#define RPM_THRES_10 20000
|
||||
|
||||
|
||||
void set_pins(void);
|
||||
void read_buttons(void);
|
||||
void read_rotary(void); // read rotary switches
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint8_t Stw_shift_up; // 1 Bit 0
|
||||
uint8_t Stw_shift_down; // 1 Bit 1
|
||||
uint8_t Stw_neutral; // 1 Bit 2
|
||||
uint8_t Stw_auto_shift; // 1 Bit 3
|
||||
uint8_t buttonState1; // 1 Bit 4
|
||||
uint8_t buttonState4; // 1 Bit 5
|
||||
//bool CAN_toggle;
|
||||
//bool CAN_check;
|
||||
//uint8_t i; //Index linker Drehschalter
|
||||
uint8_t buttonStateEnc1; // button
|
||||
//uint8_t br; //test mode : mittlere Drehschalter position
|
||||
uint8_t buttonStateEnc2; //button
|
||||
uint8_t displayindex; //index für Displayanzeige
|
||||
uint8_t error_type; //Extrainfos über Error-LED
|
||||
uint8_t trc;
|
||||
uint8_t mode;
|
||||
|
||||
uint8_t button1_rises;
|
||||
uint8_t button4_rises;
|
||||
uint8_t enc1_rises;
|
||||
uint8_t enc2_rises;
|
||||
} stw_data_type;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint8_t e_thro; // E-Drossel
|
||||
uint8_t g_auto; // Auto-Shift
|
||||
uint8_t gear; // Gang
|
||||
uint16_t revol; // Drehzahl
|
||||
uint8_t t_oil; // Öl-Motor-Temperatur
|
||||
uint8_t t_mot; // Wasser-Motor-Temperatur
|
||||
uint8_t t_air; // LLK-Temperatur
|
||||
uint8_t u_batt; // Batteriespannung
|
||||
uint8_t rev_lim; // Drehzahllimit Bit
|
||||
uint8_t p_wat;
|
||||
uint8_t p_fuel;
|
||||
uint8_t p_oil;
|
||||
uint8_t p_brake_front;
|
||||
uint8_t p_brake_rear;
|
||||
uint8_t speed_fl;
|
||||
uint8_t speed_fr;
|
||||
uint8_t speed;
|
||||
|
||||
} vehicle_data_type;
|
||||
|
||||
|
||||
extern volatile stw_data_type Stw_data;
|
||||
extern volatile vehicle_data_type Vehicle_data;
|
||||
|
||||
|
||||
#include "Arduino.h"
|
||||
#ifndef FT18_STW_Init
|
||||
#define FT18_STW_Init
|
||||
|
||||
#define l 78 // test_led
|
||||
#define led1 12 // PD8
|
||||
#define led2 11 // PD7
|
||||
#define led3 9 // PC21
|
||||
#define led4 8 // PC22
|
||||
#define led5 7 // PC23
|
||||
#define led6 6 // PC24
|
||||
#define led7 5 // PC25
|
||||
#define led8 4 // PC26 und PA29
|
||||
#define led9 3 // PC28
|
||||
#define led10 2 // PB25
|
||||
#define led11 10 // PC29 und PA28
|
||||
#define led12 22 // PB26
|
||||
#define led13 19 // PA10
|
||||
#define led14 13 // PB27
|
||||
#define led15 17 // PA12
|
||||
#define led16 18 // PA11
|
||||
#define button1 48 // bl
|
||||
#define button2 47 // gl
|
||||
#define button3 44 // gr
|
||||
#define button4 46 // br
|
||||
#define button5 45 // sl
|
||||
#define button6 49 // sr
|
||||
#define enc1PinA 37
|
||||
#define enc1PinB 38
|
||||
#define enc1PinS 35
|
||||
#define enc2PinA 40
|
||||
#define enc2PinB 41
|
||||
#define enc2PinS 39
|
||||
|
||||
// define Drehzahlgrenzen TODOOOO
|
||||
#define RPM_THRES_1 1000
|
||||
#define RPM_THRES_2 6000
|
||||
#define RPM_THRES_3 7000
|
||||
#define RPM_THRES_4 8000
|
||||
#define RPM_THRES_5 10000
|
||||
#define RPM_THRES_6 14000
|
||||
#define RPM_THRES_7 17000
|
||||
#define RPM_THRES_8 18000
|
||||
#define RPM_THRES_9 20000
|
||||
#define RPM_THRES_10 20000
|
||||
|
||||
void set_pins(void);
|
||||
void read_buttons(void);
|
||||
void read_rotary(void); // read rotary switches
|
||||
|
||||
typedef struct {
|
||||
uint8_t Stw_shift_up; // 1 Bit 0
|
||||
uint8_t Stw_shift_down; // 1 Bit 1
|
||||
uint8_t Stw_neutral; // 1 Bit 2
|
||||
uint8_t Stw_auto_shift; // 1 Bit 3
|
||||
uint8_t buttonState1; // 1 Bit 4
|
||||
uint8_t buttonState4; // 1 Bit 5
|
||||
// bool CAN_toggle;
|
||||
// bool CAN_check;
|
||||
// uint8_t i; //Index
|
||||
// linker Drehschalter
|
||||
uint8_t buttonStateEnc1; // button
|
||||
// uint8_t br; //test mode : mittlere
|
||||
// Drehschalter position
|
||||
uint8_t buttonStateEnc2; // button
|
||||
uint8_t displayindex; // index für Displayanzeige
|
||||
uint8_t error_type; // Extrainfos über Error-LED
|
||||
uint8_t trc;
|
||||
uint8_t mode;
|
||||
|
||||
uint8_t button1_rises;
|
||||
uint8_t button4_rises;
|
||||
uint8_t enc1_rises;
|
||||
uint8_t enc2_rises;
|
||||
} stw_data_type;
|
||||
|
||||
typedef struct {
|
||||
uint8_t e_thro; // E-Drossel
|
||||
uint8_t g_auto; // Auto-Shift
|
||||
uint8_t gear; // Gang
|
||||
uint16_t revol; // Drehzahl
|
||||
uint8_t t_oil; // Öl-Motor-Temperatur
|
||||
uint8_t t_mot; // Wasser-Motor-Temperatur
|
||||
uint8_t t_air; // LLK-Temperatur
|
||||
uint8_t u_batt; // Batteriespannung
|
||||
uint8_t rev_lim; // Drehzahllimit Bit
|
||||
uint8_t p_wat;
|
||||
uint8_t p_fuel;
|
||||
uint8_t p_oil;
|
||||
uint8_t p_brake_front;
|
||||
uint8_t p_brake_rear;
|
||||
uint8_t speed_fl;
|
||||
uint8_t speed_fr;
|
||||
uint8_t speed;
|
||||
|
||||
} vehicle_data_type;
|
||||
|
||||
extern volatile stw_data_type Stw_data;
|
||||
extern volatile vehicle_data_type Vehicle_data;
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user