mirror of
https://github.com/DashyFox/StackSport.git
synced 2025-05-04 07:10:17 +00:00
indicator
This commit is contained in:
parent
d088948a1d
commit
e4cc2cecf5
68
Core/Inc/Indicator.h
Normal file
68
Core/Inc/Indicator.h
Normal file
@ -0,0 +1,68 @@
|
||||
/*
|
||||
* Indicator.h
|
||||
*
|
||||
* Created on: Sep 26, 2024
|
||||
* Author: DashyFox
|
||||
*/
|
||||
|
||||
#ifndef INC_INDICATOR_H_
|
||||
#define INC_INDICATOR_H_
|
||||
#include "ShiftReg.h"
|
||||
/********* led map: *********
|
||||
* - [2] 0b01000000
|
||||
* - [2] 0b00100000
|
||||
* - [2] 0b00010000
|
||||
* - [2] 0b00001000
|
||||
* - [2] 0b00000100
|
||||
* - [2] 0b00000010
|
||||
* - [2] 0b00000001
|
||||
*
|
||||
* = [1] 0b00010000
|
||||
* = [1] 0b00100000
|
||||
* = [1] 0b01000000
|
||||
*
|
||||
*
|
||||
*
|
||||
* = [1] 0b00000100
|
||||
* = [1] 0b00000010
|
||||
* = [1] 0b00000001
|
||||
*
|
||||
* - [0] 0b00000001
|
||||
* - [0] 0b00000010
|
||||
* - [0] 0b00000100
|
||||
* - [0] 0b00001000
|
||||
* - [0] 0b00010000
|
||||
* - [0] 0b00100000
|
||||
* - [0] 0b01000000
|
||||
*
|
||||
**/
|
||||
|
||||
#define INDICATORS_COUNT 2
|
||||
|
||||
typedef struct LedMap_element {
|
||||
uint8_t byteIndx;
|
||||
uint8_t offsetMask;
|
||||
} LedMap_element;
|
||||
|
||||
typedef struct LedMap {
|
||||
LedMap_element ALL[NUMLEDS * INDICATORS_COUNT];
|
||||
LedMap_element UP[NUMLEDS];
|
||||
LedMap_element DOWN[NUMLEDS];
|
||||
LedMap_element RED[6];
|
||||
}LedMap;
|
||||
|
||||
extern const LedMap ledMap;
|
||||
|
||||
void led_init();
|
||||
|
||||
void led_show();
|
||||
void led_tick();
|
||||
|
||||
void led_writeMirror(uint8_t number, uint8_t state);
|
||||
void led_write(LedMap_element led, uint8_t state);
|
||||
void led_blink(LedMap_element led, uint16_t period, uint16_t count);
|
||||
void led_blink_num(uint8_t ledNum, uint16_t period, uint16_t count);
|
||||
uint8_t led_getState(LedMap_element led);
|
||||
void led_clear();
|
||||
|
||||
#endif /* INC_INDICATOR_H_ */
|
@ -52,24 +52,27 @@ uint8_t speedDown = 100;
|
||||
|
||||
void IR_Home_Process() {
|
||||
InputHandler = IR_Home_Process;
|
||||
SetShiftReg_inline(0xff, 0, 0);
|
||||
// SetShiftReg_inline(0xff, 0, 0);
|
||||
switch (data.command) {
|
||||
case IR_FONT_RIGHT:
|
||||
case IR_SHOT:
|
||||
paramEnter(onSelectShot);
|
||||
break;
|
||||
|
||||
// case IR_PROG:
|
||||
//// paramEnter(onSelectShot);
|
||||
// break;
|
||||
//
|
||||
// case IR_FRONT_MID:
|
||||
// SetShiftReg_inline(0, 0, 0);
|
||||
// b1 = b2 = b3 = 0;
|
||||
// break;
|
||||
case IR_PROG: {
|
||||
SetShiftReg_inline(0, 7, 0);
|
||||
b1 = b2 = b3 = 0;
|
||||
break;
|
||||
}
|
||||
|
||||
case IR_FONT_RIGHT:
|
||||
SetShiftReg_inline(b1, b2, ++b3);
|
||||
break;
|
||||
case IR_FRONT_MID:
|
||||
SetShiftReg_inline(b1, ++b2, b3);
|
||||
break;
|
||||
case IR_FRONT_LEFT:
|
||||
SetShiftReg_inline(++b1, ++b2, ++b3);
|
||||
onHoldRepeat = IR_Home_Process;
|
||||
SetShiftReg_inline(++b1, b2, b3);
|
||||
// onHoldRepeat = IR_Home_Process;
|
||||
break;
|
||||
|
||||
case IR_F_BTN: {
|
||||
|
@ -110,16 +110,16 @@ void IR_CMD_Clear() {
|
||||
inputInProgerss = 0;
|
||||
digitInputInProgerss = 0;
|
||||
inputParam = NULL_NumberParam;
|
||||
SetShiftReg_inline(0, 0xff, 0);
|
||||
// SetShiftReg_inline(0, 0xff, 0);
|
||||
}
|
||||
|
||||
void IR_ParamEnter() {
|
||||
SetShiftReg_inline(0x03, 0, 0);
|
||||
// SetShiftReg_inline(0x03, 0, 0);
|
||||
if (0 <= data.command && data.command <= 9) {
|
||||
if (digitInputInProgerss) {
|
||||
inputParam = inputParam * 10; // dec shift << 1
|
||||
inputParam += (data.command + 1) % 10;
|
||||
SetShiftReg_inline(0xF0, 0, 0);
|
||||
// SetShiftReg_inline(0xF0, 0, 0);
|
||||
} else {
|
||||
inputParam = (data.command + 1) % 10;
|
||||
}
|
||||
@ -132,7 +132,7 @@ void IR_ParamEnter() {
|
||||
if(inputParam != NULL_NumberParam){
|
||||
print("Enter: ");
|
||||
printNumber(inputParam);
|
||||
SetShiftReg_inline(0, 0, inputParam);
|
||||
// SetShiftReg_inline(0, 0, inputParam);
|
||||
onParamEnter();
|
||||
}
|
||||
inputParam = NULL_NumberParam;
|
||||
|
156
Core/Src/Indicator.c
Normal file
156
Core/Src/Indicator.c
Normal file
@ -0,0 +1,156 @@
|
||||
/*
|
||||
* Indicator.c
|
||||
*
|
||||
* Created on: Sep 26, 2024
|
||||
* Author: DashyFox
|
||||
*/
|
||||
|
||||
#include "Indicator.h"
|
||||
#include "ShiftReg.h"
|
||||
#include "SimpleTimer.h"
|
||||
#include <string.h>
|
||||
|
||||
const LedMap ledMap = {
|
||||
// ALL - DOWN[0] TO UP[19]
|
||||
{
|
||||
{0, 0b01000000},
|
||||
{0, 0b00100000},
|
||||
{0, 0b00010000},
|
||||
{0, 0b00001000},
|
||||
{0, 0b00000100},
|
||||
{0, 0b00000010},
|
||||
{0, 0b00000001},
|
||||
{1, 0b00000001},
|
||||
{1, 0b00000010},
|
||||
{1, 0b00000100},
|
||||
|
||||
{1, 0b01000000},
|
||||
{1, 0b00100000},
|
||||
{1, 0b00010000},
|
||||
{2, 0b00000001},
|
||||
{2, 0b00000010},
|
||||
{2, 0b00000100},
|
||||
{2, 0b00001000},
|
||||
{2, 0b00010000},
|
||||
{2, 0b00100000},
|
||||
{2, 0b01000000},
|
||||
},
|
||||
// UP - DOWN[0] TO UP[9]
|
||||
{
|
||||
{1, 0b01000000},
|
||||
{1, 0b00100000},
|
||||
{1, 0b00010000},
|
||||
{2, 0b00000001},
|
||||
{2, 0b00000010},
|
||||
{2, 0b00000100},
|
||||
{2, 0b00001000},
|
||||
{2, 0b00010000},
|
||||
{2, 0b00100000},
|
||||
{2, 0b01000000},
|
||||
},
|
||||
// DOWN - DOWN[0] TO UP[9]
|
||||
{
|
||||
{0, 0b01000000},
|
||||
{0, 0b00100000},
|
||||
{0, 0b00010000},
|
||||
{0, 0b00001000},
|
||||
{0, 0b00000100},
|
||||
{0, 0b00000010},
|
||||
{0, 0b00000001},
|
||||
{1, 0b00000001},
|
||||
{1, 0b00000010},
|
||||
{1, 0b00000100},
|
||||
},
|
||||
// RED - DOWN[0] TO UP[5]
|
||||
{
|
||||
{1, 0b00000001},
|
||||
{1, 0b00000010},
|
||||
{1, 0b00000100},
|
||||
|
||||
{1, 0b01000000},
|
||||
{1, 0b00100000},
|
||||
{1, 0b00010000},
|
||||
}
|
||||
};
|
||||
|
||||
static uint8_t ledBuf[3] = { 0, 0, 0 };
|
||||
|
||||
typedef struct {
|
||||
uint16_t period;
|
||||
uint16_t count;
|
||||
uint32_t timer;
|
||||
} LedBlinkInfo;
|
||||
static LedBlinkInfo ledBlinkInfo[NUMLEDS * INDICATORS_COUNT];
|
||||
|
||||
static void blinkHandler() {
|
||||
for (int i = 0; i < sizeof(ledBlinkInfo) / sizeof(ledBlinkInfo[0]); ++i) {
|
||||
if(!ledBlinkInfo[i].count || !ledBlinkInfo[i].period){
|
||||
continue;
|
||||
}
|
||||
|
||||
if(millis() - ledBlinkInfo[i].timer > ledBlinkInfo[i].period){
|
||||
ledBlinkInfo[i].timer = millis();
|
||||
led_write(ledMap.ALL[i], (ledBlinkInfo[i].count & 1) != 1);
|
||||
ledBlinkInfo[i].count--;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void led_init(){
|
||||
memset(ledBlinkInfo, 0x00, sizeof(ledBlinkInfo));
|
||||
}
|
||||
|
||||
void led_show() {
|
||||
SetShiftReg(ledBuf);
|
||||
}
|
||||
|
||||
void led_tick() {
|
||||
blinkHandler();
|
||||
}
|
||||
|
||||
void led_write(LedMap_element led, uint8_t state) {
|
||||
if (state) {
|
||||
ledBuf[led.byteIndx] |= led.offsetMask;
|
||||
} else {
|
||||
ledBuf[led.byteIndx] &= ~(led.offsetMask);
|
||||
}
|
||||
led_show();
|
||||
}
|
||||
|
||||
uint8_t led_getState(LedMap_element led){
|
||||
return (ledBuf[led.byteIndx] & led.offsetMask) != 0;
|
||||
}
|
||||
|
||||
void led_writeMirror(uint8_t number, uint8_t state) {
|
||||
|
||||
if (number >= 10) {
|
||||
number = 9;
|
||||
}
|
||||
|
||||
led_write(ledMap.UP[number], state);
|
||||
led_write(ledMap.DOWN[9 - number], state);
|
||||
|
||||
led_show();
|
||||
}
|
||||
|
||||
void led_blink_num(uint8_t ledNum, uint16_t period, uint16_t count){
|
||||
if(ledNum>=sizeof(ledBlinkInfo)/sizeof(ledBlinkInfo[0]))
|
||||
return;
|
||||
ledBlinkInfo[ledNum].count = count*2;
|
||||
ledBlinkInfo[ledNum].period = period;
|
||||
ledBlinkInfo[ledNum].timer = 0; // run immediately
|
||||
}
|
||||
|
||||
void led_blink(LedMap_element led, uint16_t period, uint16_t count) {
|
||||
for (int i = 0; i < sizeof(ledMap.ALL)/sizeof(ledMap.ALL[0]); ++i) {
|
||||
if(memcmp(&led, &ledMap.ALL[i], sizeof(LedMap_element)) == 0){
|
||||
led_blink_num(i, period, count);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void led_clear() {
|
||||
memset(ledBuf, 0x00, sizeof(ledBuf));
|
||||
led_show();
|
||||
}
|
@ -9,9 +9,9 @@
|
||||
#include "pca9685.h"
|
||||
#include "UART3_Handler.h"
|
||||
#include "EEPROM.h"
|
||||
#include "ShiftReg.h"
|
||||
#include "Print.h"
|
||||
#include "SimpleTimer.h"
|
||||
#include "Indicator.h"
|
||||
|
||||
#define ballReact_value 10 // время реакции на вылет мяча
|
||||
|
||||
@ -80,65 +80,20 @@ void Robot_INIT() {
|
||||
initPCA9685();
|
||||
EEPROM_INIT();
|
||||
UART3_START();
|
||||
led_init();
|
||||
|
||||
setPosDefault();
|
||||
Shiftreg[0] = 0x00;
|
||||
Shiftreg[1] = 0x44;
|
||||
Shiftreg[2] = 0x00;
|
||||
SetShiftReg(Shiftreg);
|
||||
HAL_Delay(10);
|
||||
Shiftreg[0] = 0x00;
|
||||
Shiftreg[1] = 0x66;
|
||||
Shiftreg[2] = 0x00;
|
||||
SetShiftReg(Shiftreg);
|
||||
HAL_Delay(10);
|
||||
Shiftreg[0] = 0x00;
|
||||
Shiftreg[1] = 0x77;
|
||||
Shiftreg[2] = 0x00;
|
||||
SetShiftReg(Shiftreg);
|
||||
HAL_Delay(10);
|
||||
Shiftreg[0] = 0x01;
|
||||
Shiftreg[1] = 0x77;
|
||||
Shiftreg[2] = 0x01;
|
||||
SetShiftReg(Shiftreg);
|
||||
HAL_Delay(10);
|
||||
Shiftreg[0] = 0x03;
|
||||
Shiftreg[1] = 0x77;
|
||||
Shiftreg[2] = 0x03;
|
||||
SetShiftReg(Shiftreg);
|
||||
HAL_Delay(10);
|
||||
Shiftreg[0] = 0x07;
|
||||
Shiftreg[1] = 0x77;
|
||||
Shiftreg[2] = 0x07;
|
||||
SetShiftReg(Shiftreg);
|
||||
HAL_Delay(10);
|
||||
Shiftreg[0] = 0x0F;
|
||||
Shiftreg[1] = 0x77;
|
||||
Shiftreg[2] = 0x0F;
|
||||
SetShiftReg(Shiftreg);
|
||||
HAL_Delay(10);
|
||||
Shiftreg[0] = 0x1F;
|
||||
Shiftreg[1] = 0x77;
|
||||
Shiftreg[2] = 0x1F;
|
||||
SetShiftReg(Shiftreg);
|
||||
HAL_Delay(10);
|
||||
Shiftreg[0] = 0x3F;
|
||||
Shiftreg[1] = 0x77;
|
||||
Shiftreg[2] = 0x3F;
|
||||
SetShiftReg(Shiftreg);
|
||||
HAL_Delay(10);
|
||||
Shiftreg[0] = 0x7F;
|
||||
Shiftreg[1] = 0x77;
|
||||
Shiftreg[2] = 0x7F;
|
||||
SetShiftReg(Shiftreg);
|
||||
HAL_Delay(10);
|
||||
Shiftreg[0] = 0x00;
|
||||
Shiftreg[1] = 0x00;
|
||||
Shiftreg[2] = 0x00;
|
||||
SetShiftReg(Shiftreg);
|
||||
for (int i = 0; i < 10; ++i) {
|
||||
// if ((i&1U)!=1 || i > 4) for test
|
||||
{
|
||||
led_writeMirror(i, 1);
|
||||
HAL_Delay(10);
|
||||
}
|
||||
}
|
||||
led_clear();
|
||||
|
||||
//testing
|
||||
for (int i = 7; i < 13; ++i) {
|
||||
led_blink_num(i, 100, 15);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -149,6 +104,7 @@ void BallEXT() {
|
||||
|
||||
void RobotTick() {
|
||||
BallEXT_Handler();
|
||||
led_tick();
|
||||
|
||||
// No Ball Handler
|
||||
if (currentInfo.state == RUN && millis() - noBallTimer > noBallTimeout) {
|
||||
|
@ -11,6 +11,13 @@ void SetShiftReg_inline(unsigned char b1, unsigned char b2, unsigned char b3){
|
||||
SetShiftReg(shiftreg);
|
||||
}
|
||||
|
||||
//static void Delay(uint16_t d)
|
||||
//{
|
||||
// for (volatile int i = 0; i < d; i++) {
|
||||
// __NOP();
|
||||
// }
|
||||
//}
|
||||
|
||||
void SetShiftReg(unsigned char shiftreg[3])
|
||||
{
|
||||
for (unsigned char i = 0; i < 3; i++)
|
||||
@ -28,6 +35,7 @@ void SetShiftReg(unsigned char shiftreg[3])
|
||||
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_5, GPIO_PIN_RESET);
|
||||
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_5, GPIO_PIN_RESET);
|
||||
|
||||
|
||||
if (((shiftreg[i] >> j) & 0x01) == 0x01)
|
||||
{
|
||||
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_4, GPIO_PIN_SET);
|
||||
|
Loading…
x
Reference in New Issue
Block a user