3.24_433_RX版本:封装RF433模块,完成开机进入TX/RX模式并在开发板验证成功
This commit is contained in:
1478
Middlewares/MultMenu/application/AirPlane.c
Normal file
1478
Middlewares/MultMenu/application/AirPlane.c
Normal file
File diff suppressed because it is too large
Load Diff
12
Middlewares/MultMenu/application/AirPlane.h
Normal file
12
Middlewares/MultMenu/application/AirPlane.h
Normal file
@ -0,0 +1,12 @@
|
||||
#ifndef _AirPlane_H
|
||||
#define _AirPlane_H
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdlib.h> // rand
|
||||
#include "menuConfig.h"
|
||||
|
||||
void AirPlane_Run(xpItem item);
|
||||
|
||||
#endif
|
||||
385
Middlewares/MultMenu/application/DinoGame.c
Normal file
385
Middlewares/MultMenu/application/DinoGame.c
Normal file
@ -0,0 +1,385 @@
|
||||
/*
|
||||
* Copyright (c) 2016, Freescale Semiconductor, Inc.
|
||||
* Copyright 2016-2021 NXP
|
||||
* All rights reserved.
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-3-Clause
|
||||
*/
|
||||
|
||||
/* Standard C Included Files */
|
||||
#include "DinoGame.h"
|
||||
|
||||
/*******************************************************************************
|
||||
* Definitions
|
||||
******************************************************************************/
|
||||
/* System Tick Configuration */
|
||||
#define SYS_TICK_PER_SECOND 1000
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
* Prototypes
|
||||
******************************************************************************/
|
||||
|
||||
/*******************************************************************************
|
||||
* Variables
|
||||
******************************************************************************/
|
||||
extern u8g2_t u8g2;
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
* Code
|
||||
|
||||
******************************************************************************/
|
||||
static int random(int low, int high)
|
||||
{
|
||||
return rand() % (high - low + 1) + low;
|
||||
}
|
||||
|
||||
static unsigned long millis(void)
|
||||
{
|
||||
return ((unsigned long)HAL_GetTick() * 1000 / SYS_TICK_PER_SECOND );
|
||||
}
|
||||
|
||||
// https://github.com/sarafong/T-Rex-Runner/blob/master/TRexRunner/TRexRunner.ino
|
||||
|
||||
//Multiple Dino Bitmaps
|
||||
|
||||
//--------------------Bitmaps--------------------//
|
||||
|
||||
//----------Dimensions----------//
|
||||
#define smallcactus_width 8
|
||||
#define smallcactus_height 17
|
||||
#define standing_width 21
|
||||
#define standing_height 20
|
||||
#define frontLeg_width 21
|
||||
#define frontLeg_height 20
|
||||
#define backLeg_width 21
|
||||
#define backLeg_height 20
|
||||
#define gameover_width 99
|
||||
#define gameover_height 35
|
||||
#define easy_width 32
|
||||
#define easy_height 15
|
||||
#define medium_width 30
|
||||
#define medium_height 20
|
||||
#define hard_width 32
|
||||
#define hard_height 15
|
||||
#define insane_width 30
|
||||
#define insane_height 20
|
||||
#define menu_width 32
|
||||
#define menu_height 15
|
||||
#define replay_width 32
|
||||
#define replay_height 15
|
||||
|
||||
#define UP 3
|
||||
#define DOWN 2
|
||||
|
||||
//----------Bitmap Arrays----------//
|
||||
|
||||
static unsigned char smallcactus_bits[] = {
|
||||
0x18, 0x18, 0x98, 0x98, 0x99, 0x99, 0x99, 0x99, 0x79, 0x19, 0x1e, 0x18,
|
||||
0x18, 0x18, 0x18, 0x18, 0x18 };
|
||||
|
||||
static unsigned char standing_bits[] = {
|
||||
0x00, 0xf8, 0x0f, 0x00, 0xcc, 0x1f, 0x00, 0xf8, 0x1f, 0x00, 0xfc, 0x1f,
|
||||
0x00, 0xf8, 0x1f, 0x00, 0xfc, 0x00, 0x00, 0xf8, 0x07, 0x01, 0x3e, 0x00,
|
||||
0x01, 0x7f, 0x00, 0xc3, 0xff, 0x01, 0xef, 0x7f, 0x00, 0xff, 0x7f, 0x00,
|
||||
0xfe, 0x3f, 0x00, 0xfc, 0x3f, 0x00, 0xf8, 0x1f, 0x00, 0xf0, 0x07, 0x00,
|
||||
0xe0, 0x0e, 0x00, 0x60, 0x04, 0x00, 0x20, 0x08, 0x00, 0x60, 0x08, 0x00 };
|
||||
|
||||
static unsigned char frontLeg_bits[] = {
|
||||
0x00, 0xf0, 0x0f, 0x00, 0xdc, 0x1f, 0x00, 0xf8, 0x1f, 0x00, 0xf8, 0x1f,
|
||||
0x00, 0xf8, 0x1f, 0x00, 0xfc, 0x00, 0x00, 0xf8, 0x07, 0x01, 0x7e, 0x00,
|
||||
0x01, 0x7f, 0x00, 0xc3, 0xff, 0x01, 0xef, 0x7f, 0x01, 0xff, 0x7f, 0x00,
|
||||
0xfe, 0x7f, 0x00, 0xfc, 0x3f, 0x00, 0xf8, 0x1f, 0x00, 0xf0, 0x0f, 0x00,
|
||||
0xe0, 0x18, 0x00, 0xe0, 0x00, 0x00, 0x20, 0x00, 0x00, 0x60, 0x00, 0x00 };
|
||||
|
||||
static unsigned char backLeg_bits[] = {
|
||||
0x00, 0xf8, 0x0f, 0x00, 0xd8, 0x1f, 0x00, 0xfc, 0x1f, 0x00, 0xf8, 0x1f,
|
||||
0x00, 0xfc, 0x1f, 0x00, 0xf8, 0x00, 0x00, 0xfc, 0x07, 0x01, 0x3e, 0x00,
|
||||
0x01, 0x7f, 0x00, 0xc3, 0xff, 0x01, 0xef, 0x7f, 0x00, 0xff, 0x7f, 0x00,
|
||||
0xfe, 0x3f, 0x00, 0xfc, 0x3f, 0x00, 0xf8, 0x1f, 0x00, 0xf0, 0x07, 0x00,
|
||||
0x60, 0x0e, 0x00, 0xc0, 0x04, 0x00, 0x00, 0x08, 0x00, 0x00, 0x0c, 0x00 };
|
||||
|
||||
static unsigned char gameover_bits[] = {
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0xc0, 0x03, 0x0e, 0xd8, 0xc0, 0x07, 0x80, 0x07, 0x24,
|
||||
0xe0, 0x01, 0x0f, 0x00, 0x20, 0x00, 0x09, 0xf8, 0x40, 0x00, 0x80, 0x04,
|
||||
0x66, 0x30, 0x80, 0x09, 0x00, 0x20, 0x03, 0x19, 0xe8, 0xc0, 0x03, 0x80,
|
||||
0x04, 0x3c, 0xe0, 0x01, 0x0d, 0x00, 0x60, 0x02, 0x1b, 0x88, 0x40, 0x00,
|
||||
0xc0, 0x0c, 0x18, 0x20, 0x00, 0x07, 0x00, 0xc0, 0x03, 0x11, 0x98, 0xc0,
|
||||
0x07, 0x80, 0x07, 0x08, 0xe0, 0x01, 0x0d, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x54,
|
||||
0x55, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0xfe, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0xfe, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x7e, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x1e, 0xe6, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x4e, 0xee, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x6e, 0xef, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xce, 0xef, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xee, 0xef, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0e, 0xe0, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x9e, 0xf4, 0x01,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfe, 0xff,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfe,
|
||||
0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0xfe, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
|
||||
|
||||
static unsigned char easy_bits[] = {
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80,
|
||||
0x00, 0x00, 0x00, 0xc0, 0xf0, 0x00, 0x00, 0xf0, 0x10, 0x00, 0x00, 0xfc,
|
||||
0x50, 0x6d, 0x09, 0xff, 0x10, 0x2c, 0xc5, 0xff, 0x10, 0x4b, 0x06, 0xff,
|
||||
0xf0, 0x7e, 0x02, 0xfc, 0x00, 0x00, 0x02, 0xf0, 0x00, 0x00, 0x00, 0xc0,
|
||||
0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
|
||||
|
||||
static unsigned char medium_bits[] = {
|
||||
0x00, 0x00, 0x00, 0x00, 0x22, 0x40, 0x01, 0x00, 0x66, 0x40, 0x00, 0x00,
|
||||
0xaa, 0x75, 0xd5, 0x0f, 0xda, 0x4f, 0x61, 0x08, 0x82, 0x48, 0x45, 0x09,
|
||||
0x42, 0x77, 0x5d, 0x0a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0xe0, 0x00, 0x00,
|
||||
0x00, 0xe0, 0x00, 0x00, 0x00, 0xf0, 0x01, 0x00, 0x00, 0xf0, 0x01, 0x00,
|
||||
0x00, 0xf8, 0x03, 0x00, 0x00, 0xf8, 0x03, 0x00, 0x00, 0xfc, 0x07, 0x00,
|
||||
0x00, 0xfc, 0x07, 0x00, 0x00, 0xfe, 0x0f, 0x00 };
|
||||
|
||||
static unsigned char hard_bits[] = {
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
|
||||
0x07, 0x00, 0x00, 0x00, 0x1f, 0x40, 0x00, 0x20, 0x7f, 0x40, 0x04, 0x20,
|
||||
0xff, 0x41, 0xbb, 0x3b, 0xff, 0x43, 0x62, 0x24, 0xff, 0x41, 0x8c, 0x24,
|
||||
0x7f, 0x40, 0xb8, 0x38, 0x1f, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00,
|
||||
0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
|
||||
|
||||
static unsigned char insane_bits[] = {
|
||||
0x00, 0xfe, 0x0f, 0x00, 0x00, 0xfc, 0x07, 0x00, 0x00, 0xfc, 0x07, 0x00,
|
||||
0x00, 0xf8, 0x03, 0x00, 0x00, 0xf8, 0x03, 0x00, 0x00, 0xf0, 0x01, 0x00,
|
||||
0x00, 0xf0, 0x01, 0x00, 0x00, 0xe0, 0x00, 0x00, 0x00, 0xe0, 0x00, 0x00,
|
||||
0x00, 0x40, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x18, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0xc0, 0xdd, 0x9d, 0x03,
|
||||
0x50, 0x84, 0xa5, 0x03, 0x50, 0x52, 0x65, 0x00, 0x58, 0xdc, 0xa5, 0x03,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
|
||||
|
||||
static unsigned char menu_bits[] = {
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
|
||||
0x07, 0x00, 0x00, 0x00, 0x1f, 0x10, 0x01, 0x00, 0x7f, 0x30, 0x01, 0x00,
|
||||
0xff, 0xb1, 0xdd, 0x25, 0xff, 0x53, 0x5d, 0x26, 0xff, 0x11, 0x44, 0x4a,
|
||||
0x7f, 0x10, 0x5d, 0x3a, 0x1f, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00,
|
||||
0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
|
||||
|
||||
static unsigned char replay_bits[] = {
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80,
|
||||
0x00, 0x00, 0x00, 0xc0, 0x07, 0x20, 0x00, 0xf0, 0x09, 0x20, 0x00, 0xfc,
|
||||
0xe9, 0xae, 0x4b, 0xff, 0xe7, 0x32, 0xeb, 0xff, 0x15, 0xb2, 0x34, 0xff,
|
||||
0xe9, 0xae, 0x13, 0xfc, 0x00, 0x02, 0x10, 0xf0, 0x00, 0x00, 0x00, 0xc0,
|
||||
0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
|
||||
|
||||
|
||||
|
||||
//----------Initializing Variables----------//
|
||||
static unsigned long dinoTimeToMove = 0; //Used to space out time(millis) between draws/moves
|
||||
static unsigned long dinoTimeToDraw = 0;
|
||||
|
||||
static int score;
|
||||
static int highScore = 0;
|
||||
static int multiplier; //Score multiplier
|
||||
|
||||
//bool ignoreRepeat = false; //Avoid Switch Bouncing
|
||||
static long compensation; //To compensate for the amount of time the Arduino has been running for after each run (essentially "resets" the time)
|
||||
static bool gameOver;
|
||||
static bool menu = true;
|
||||
|
||||
static bool down, jump; //Boolean values to check the state of the dinosaur
|
||||
// static int dinoSwitch; //Switch between dino bitmaps to simulate movement
|
||||
static int dinoY, cactiX1, cactiX2; //Positions of objects
|
||||
static int velocity; //Speed of entire game
|
||||
static int difficulty; //How fast the velocity increases
|
||||
|
||||
|
||||
//--------------------Functions--------------------//
|
||||
|
||||
//Set/Reset Loop for Playing Again
|
||||
void reset(){
|
||||
compensation = millis();
|
||||
gameOver = false;
|
||||
down = false;
|
||||
jump = false;
|
||||
// dinoSwitch = true;
|
||||
dinoY = 44;
|
||||
cactiX1 = 130;
|
||||
cactiX2 = cactiX1 + random(70, 120);
|
||||
velocity = 2;
|
||||
}
|
||||
|
||||
//Deteching Joystick Interaction
|
||||
void keyPress(xpItem item)
|
||||
{
|
||||
uint8_t temp;
|
||||
|
||||
if(item->state == MENU_UP)temp = DOWN;
|
||||
if(item->state == MENU_DOWN)temp = UP;
|
||||
if(menu & (temp != 0))
|
||||
{
|
||||
reset();
|
||||
menu = false;
|
||||
if(temp == DOWN)
|
||||
{
|
||||
difficulty = 7500;
|
||||
multiplier = 15000 / difficulty;
|
||||
}
|
||||
if(temp == UP)
|
||||
{
|
||||
difficulty = 2500;
|
||||
multiplier = 15000 / difficulty;
|
||||
}
|
||||
}
|
||||
else if ( gameOver && (temp!=0) ) { //Left -> PlayAgain // Right -> Menu
|
||||
//ignoreRepeat = false;
|
||||
reset();
|
||||
if ( temp == UP ) menu = true; //Pushing Down
|
||||
}
|
||||
else if ( dinoY == 44 && temp == DOWN ) { //Corresponds to pushing up on the joystick
|
||||
jump = true;
|
||||
down = true;
|
||||
}
|
||||
}
|
||||
|
||||
//Collision Detecting and Setting HighScore
|
||||
void collision(void)
|
||||
{
|
||||
if ( cactiX1 <= 23 && cactiX1 + smallcactus_width >= 15 && dinoY+20 >= 50 ) {
|
||||
if ( (millis()-compensation)*multiplier/250 > highScore && !gameOver ) highScore = (millis()-compensation)*multiplier/250; //Changes highscore if current score is greater
|
||||
gameOver = true;
|
||||
}
|
||||
}
|
||||
|
||||
void moveDino(void)
|
||||
{
|
||||
if ( dinoY > 44 ) dinoY = 44; //Resets dinosaur to it passes it
|
||||
if ( jump || dinoY <= 43 ) { //Allows jumping if on the ground
|
||||
jump = false;
|
||||
if ( dinoY >= 16 && down ) dinoY -= velocity; //Going up
|
||||
else { //Going down
|
||||
down = false;
|
||||
dinoY += velocity;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void moveCactus(void)
|
||||
{
|
||||
cactiX1 -= velocity;
|
||||
cactiX2 -= velocity;
|
||||
if ( cactiX1 <= -15 ) { //Once cacti reaches left side of screen, resets to right side of screen
|
||||
cactiX1 = cactiX2;
|
||||
cactiX2 = cactiX1 + random(70, 150);
|
||||
}
|
||||
}
|
||||
|
||||
//-------Move Functions-------//
|
||||
void moveObjects(void)
|
||||
{
|
||||
if( millis() > dinoTimeToMove+50 )
|
||||
{ //Updates every 50 milliseconds
|
||||
velocity = (millis()-compensation)/difficulty + 2; //Increases velocity as game progresses
|
||||
moveDino();
|
||||
moveCactus();
|
||||
dinoTimeToMove = millis();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//-------Draw Functions-------//
|
||||
void drawDinoCactus(void)
|
||||
{
|
||||
if ( dinoY < 44 ) u8g2_DrawXBM(&u8g2, 10, dinoY, standing_width, standing_height, standing_bits); //While jumping don't change bitmap
|
||||
else if ( (millis()-compensation) % 16 > 9 ) u8g2_DrawXBM(&u8g2, 10, dinoY, frontLeg_width, frontLeg_height, frontLeg_bits); //Switch between bitmaps every 9 millis
|
||||
else u8g2_DrawXBM(&u8g2, 10, dinoY, backLeg_width, backLeg_height, backLeg_bits);
|
||||
u8g2_DrawXBM(&u8g2, cactiX1, 47, smallcactus_width, smallcactus_height, smallcactus_bits); //Draw cacti
|
||||
u8g2_DrawXBM(&u8g2, cactiX2, 47, smallcactus_width, smallcactus_height, smallcactus_bits);
|
||||
}
|
||||
|
||||
void drawScore(void)
|
||||
{
|
||||
char scoreBuff[50];
|
||||
if ( menu ) { //Print highscore on menu screen
|
||||
score = highScore;
|
||||
snprintf(scoreBuff, 50, "HighS: %d", score);
|
||||
}
|
||||
else if ( !gameOver )
|
||||
{ //Increments score ONLY while playing
|
||||
score = (millis() - compensation) / 250;
|
||||
snprintf(scoreBuff, 50, "Score: %d", score);
|
||||
}
|
||||
u8g2_SetFont(&u8g2, MENU_FONT);
|
||||
u8g2_DrawStr(&u8g2, 55, 8, scoreBuff );
|
||||
}
|
||||
|
||||
//Draws Game Over Screen
|
||||
void playAgain(void)
|
||||
{
|
||||
u8g2_DrawXBM(&u8g2, 14, 14, gameover_width, gameover_height, gameover_bits);
|
||||
u8g2_DrawXBM(&u8g2, 23, 30, replay_width, replay_height, replay_bits);
|
||||
u8g2_DrawXBM(&u8g2, 70, 30, menu_width, menu_height, menu_bits);
|
||||
}
|
||||
|
||||
//Draws Menu Screen
|
||||
void menuScreen(void)
|
||||
{
|
||||
u8g2_DrawXBM(&u8g2, 26, 30, easy_width, easy_height, easy_bits);
|
||||
u8g2_DrawXBM(&u8g2, 49, 12, medium_width, medium_height, medium_bits);
|
||||
u8g2_DrawXBM(&u8g2, 69, 30, hard_width, hard_height, hard_bits);
|
||||
u8g2_DrawXBM(&u8g2, 49, 43, insane_width, insane_height, insane_bits);
|
||||
}
|
||||
|
||||
void draw_DinoGame(void)
|
||||
{
|
||||
if( millis() > dinoTimeToDraw + 25 ){ //Draws every 25 milliseconds
|
||||
do {
|
||||
drawDinoCactus();
|
||||
drawScore();
|
||||
if ( menu ) menuScreen(); //Draw Menu Screen
|
||||
else if ( gameOver ) playAgain(); //Draw Game Over Screen
|
||||
} while( u8g2_NextPage(&u8g2) );
|
||||
dinoTimeToDraw = millis();
|
||||
}
|
||||
}
|
||||
/*!
|
||||
* @brief DinoGame_Task function
|
||||
*/
|
||||
void DinoGame_Run(xpItem item)
|
||||
{
|
||||
static uint8_t Dino_IntoState=false;
|
||||
if(Dino_IntoState==false)
|
||||
{
|
||||
/* set systick and start systick interrupt */
|
||||
SysTick_Config(SystemCoreClock/SYS_TICK_PER_SECOND);
|
||||
//u8g2_SetFont(&u8g2, u8g2_font_helvB08_tr);
|
||||
u8g2_SetFont(&u8g2, MENU_FONT);
|
||||
u8g2_SetFontDirection(&u8g2, 0);
|
||||
u8g2_SetFontRefHeightAll(&u8g2);
|
||||
reset();
|
||||
Dino_IntoState=true;
|
||||
}
|
||||
|
||||
u8g2_FirstPage(&u8g2);
|
||||
keyPress(item);
|
||||
if ( (!gameOver) && (!menu) )
|
||||
{
|
||||
moveObjects();
|
||||
}
|
||||
draw_DinoGame();
|
||||
collision();
|
||||
}
|
||||
12
Middlewares/MultMenu/application/DinoGame.h
Normal file
12
Middlewares/MultMenu/application/DinoGame.h
Normal file
@ -0,0 +1,12 @@
|
||||
#ifndef _DinoGame_H
|
||||
#define _DinoGame_H
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdlib.h> // rand
|
||||
#include "application.h"
|
||||
|
||||
void DinoGame_Run(xpItem item);
|
||||
|
||||
#endif
|
||||
799
Middlewares/MultMenu/application/application.c
Normal file
799
Middlewares/MultMenu/application/application.c
Normal file
@ -0,0 +1,799 @@
|
||||
#include "application.h"
|
||||
#include "dispDirver.h"
|
||||
#include "main.h"
|
||||
#include "e32_hal.h"
|
||||
#include "usart.h"
|
||||
|
||||
/**
|
||||
* 菜单 Setting > Work Mode 对应的工作模式显示名称
|
||||
*/
|
||||
static const char *mode_name[4] = {"Transparent","WOR Master ","WOR Slave ","Sleep "};
|
||||
|
||||
/**
|
||||
* 菜单 Setting > Rate Mode 对应的空速显示名称
|
||||
*/
|
||||
static const char *rate_name[8] = {" 2.4"," 2.4"," 2.4"," 4.8"," 9.6","19.2","19.2","19.2"};
|
||||
|
||||
/**
|
||||
* 菜单 Setting > 参数默认显示值
|
||||
*/
|
||||
menu_config_t user_config =
|
||||
{
|
||||
.work_mode = 3, // 工作模式
|
||||
.rate_mode = 2, // 空速模式 挡位选择
|
||||
.channel = 23, // 通信信道
|
||||
.tx_power = 30, // 发射功率 挡位选择
|
||||
.tx_count = 10, // 数据发送测试总次数
|
||||
};
|
||||
|
||||
/**
|
||||
* 注意为xbm格式数据 可以使用网络在线工具转换 https://convertio.co/zh/xbm-converter/
|
||||
*/
|
||||
static const unsigned char ebyte_logo[861] = {
|
||||
0x00, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00, 0x00, 0x30, 0x00, 0x00,
|
||||
0x00, 0x3E, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1C, 0x00, 0x00, 0x00, 0x00,
|
||||
0x70, 0x00, 0x00, 0x00, 0xC1, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0E, 0x00,
|
||||
0x00, 0x00, 0x00, 0xE0, 0x00, 0x00, 0x80, 0x9C, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x06, 0x18, 0x00, 0x00, 0x60, 0xC0, 0x01, 0x00, 0xC0, 0x26, 0x01,
|
||||
0x00, 0x00, 0x00, 0x00, 0x03, 0x0C, 0x00, 0x00, 0x60, 0x80, 0x01, 0x00,
|
||||
0x40, 0x26, 0x01, 0x00, 0x00, 0x00, 0x80, 0x01, 0x06, 0x00, 0x00, 0xC0,
|
||||
0x00, 0x03, 0x00, 0x40, 0x1E, 0x00, 0x00, 0x00, 0x00, 0xC0, 0x01, 0x03,
|
||||
0x03, 0x80, 0x81, 0x01, 0x07, 0x00, 0x40, 0x16, 0x01, 0x00, 0x00, 0x00,
|
||||
0xC0, 0x80, 0x83, 0x03, 0x80, 0x03, 0x03, 0x06, 0x00, 0xC0, 0x36, 0x01,
|
||||
0x00, 0x00, 0x00, 0x60, 0xC0, 0xC1, 0x01, 0x00, 0x07, 0x07, 0x0C, 0x00,
|
||||
0x80, 0x80, 0x00, 0x00, 0x00, 0x00, 0x60, 0xC0, 0xC0, 0x00, 0x00, 0x06,
|
||||
0x06, 0x0C, 0x00, 0x00, 0xC1, 0x00, 0x00, 0x00, 0x00, 0x60, 0xC0, 0x60,
|
||||
0xC0, 0x07, 0x0C, 0x06, 0x0C, 0x00, 0x00, 0x1E, 0x00, 0x00, 0x00, 0x00,
|
||||
0x60, 0xC0, 0x60, 0xC0, 0x0F, 0x0C, 0x0C, 0x18, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x30, 0x60, 0x60, 0xE0, 0x0F, 0x08, 0x0C, 0x18, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x60, 0x20, 0xE0, 0x0F, 0x18,
|
||||
0x0C, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x60, 0x20,
|
||||
0xE0, 0x0F, 0x18, 0x0C, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x30, 0x60, 0x60, 0xC0, 0x0F, 0x18, 0x0C, 0x18, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x20, 0x40, 0x60, 0x80, 0x03, 0x0C, 0x0C, 0x18, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x60, 0xC0, 0x60, 0x00, 0x00, 0x0C,
|
||||
0x06, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x60, 0xC0, 0xC0,
|
||||
0x00, 0x00, 0x06, 0x06, 0x0C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x60, 0x80, 0xC1, 0x01, 0x00, 0x06, 0x07, 0x0C, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0xC0, 0x80, 0x83, 0x03, 0x80, 0x03, 0x03, 0x0E, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xC0, 0x01, 0x03, 0x03, 0x80, 0x81,
|
||||
0x01, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x01, 0x06,
|
||||
0xC0, 0x07, 0xC0, 0x01, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x03, 0x0C, 0xC0, 0x07, 0xE0, 0x80, 0x03, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x07, 0x00, 0xC0, 0x07, 0x00, 0x80, 0x01, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0E, 0x00, 0xC0, 0x07, 0x00,
|
||||
0xE0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0C, 0x00,
|
||||
0xC0, 0x07, 0x00, 0x60, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0xC0, 0x0F, 0x00, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xC0, 0x0F, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xE0, 0x0F, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0xC0, 0x0F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0xC0, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x07, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0xFF, 0xFF, 0xE7, 0xFF, 0x3F, 0xF0, 0x03, 0xE0, 0xCF, 0xFF, 0xFF, 0xCF,
|
||||
0xFF, 0xFF, 0x01, 0xFF, 0xFF, 0xE7, 0xFF, 0xFF, 0xE0, 0x07, 0xE0, 0xC7,
|
||||
0xFF, 0xFF, 0xCF, 0xFF, 0xFF, 0x01, 0xFF, 0xFF, 0xC7, 0xFF, 0xFF, 0xC1,
|
||||
0x0F, 0xF0, 0xC3, 0xFF, 0xFF, 0xCF, 0xFF, 0xFF, 0x01, 0x3F, 0x00, 0xC0,
|
||||
0x07, 0xF8, 0xC3, 0x0F, 0xF8, 0x01, 0xC0, 0x0F, 0xC0, 0x0F, 0x00, 0x00,
|
||||
0x1F, 0x00, 0xC0, 0x07, 0xF0, 0x83, 0x1F, 0xFC, 0x00, 0xC0, 0x0F, 0xC0,
|
||||
0x07, 0x00, 0x00, 0x3F, 0x00, 0xC0, 0x07, 0xF0, 0x01, 0x3F, 0x7E, 0x00,
|
||||
0xC0, 0x0F, 0xC0, 0x07, 0x00, 0x00, 0x3F, 0x00, 0xE0, 0x07, 0xFC, 0x00,
|
||||
0x7E, 0x3E, 0x00, 0xC0, 0x0F, 0xC0, 0x0F, 0x00, 0x00, 0xFF, 0xFF, 0xC3,
|
||||
0xFF, 0x3F, 0x00, 0xFC, 0x1F, 0x00, 0xC0, 0x0F, 0xC0, 0xFF, 0xFF, 0x00,
|
||||
0xFF, 0xFF, 0xC3, 0xFF, 0x3F, 0x00, 0xF8, 0x0F, 0x00, 0xC0, 0x0F, 0xC0,
|
||||
0xFF, 0xFF, 0x00, 0xFF, 0xFF, 0xC3, 0xFF, 0xFF, 0x01, 0xF0, 0x07, 0x00,
|
||||
0xC0, 0x0F, 0xC0, 0xFF, 0xFF, 0x00, 0x3F, 0x00, 0xC0, 0x07, 0xF0, 0x03,
|
||||
0xE0, 0x03, 0x00, 0xC0, 0x0F, 0xC0, 0x07, 0x00, 0x00, 0x3F, 0x00, 0xC0,
|
||||
0x07, 0xE0, 0x03, 0xE0, 0x03, 0x00, 0xC0, 0x0F, 0xC0, 0x07, 0x00, 0x00,
|
||||
0x3F, 0x00, 0xE0, 0x07, 0xE0, 0x07, 0xE0, 0x03, 0x00, 0xC0, 0x0F, 0xC0,
|
||||
0x07, 0x00, 0x00, 0x3F, 0x00, 0xC0, 0x07, 0xF0, 0x03, 0xE0, 0x03, 0x00,
|
||||
0xC0, 0x0F, 0xC0, 0x07, 0x00, 0x00, 0xFF, 0xFF, 0xC7, 0xFF, 0xFF, 0x03,
|
||||
0xE0, 0x03, 0x00, 0xC0, 0x0F, 0xC0, 0xFF, 0xFF, 0x01, 0xFF, 0xFF, 0xC7,
|
||||
0xFF, 0xFF, 0x01, 0xE0, 0x03, 0x00, 0xC0, 0x0F, 0xC0, 0xFF, 0xFF, 0x01,
|
||||
0xFF, 0xFF, 0xC7, 0xFF, 0x7F, 0x00, 0xE0, 0x03, 0x00, 0xC0, 0x0F, 0xC0,
|
||||
0xFF, 0xFF, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, };
|
||||
|
||||
/**
|
||||
* Tx Mode 数据发送测试 过程状态
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
TX_MODE_INIT = 0,
|
||||
TX_MODE_SEND,
|
||||
TX_MODE_WAIT,
|
||||
TX_MODE_END,
|
||||
}tx_state_t;
|
||||
|
||||
/**
|
||||
* Rx Mode 数据接收测试 过程状态
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
RX_MODE_INIT = 0,
|
||||
RX_MODE_RECV,
|
||||
RX_MODE_WAIT,
|
||||
RX_MODE_END,
|
||||
}rx_state_t;
|
||||
|
||||
/**
|
||||
* Rx Mode 数据接收测试 提示光标状态
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
HINT_WAIT = 0,
|
||||
HINT_DONE,
|
||||
}hint_state_t;
|
||||
|
||||
/**
|
||||
* Version 版本信息显示 过程状态
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
VERSION_START = 0,
|
||||
VERSION_WAIT,
|
||||
VERSION_END
|
||||
}version_state_t;
|
||||
|
||||
/**
|
||||
* @brief 菜单 进入首页
|
||||
*
|
||||
* @param item 指向项目状态的指针
|
||||
*/
|
||||
void logo_callback( xpItem item )
|
||||
{
|
||||
OLED_ClearBuffer();
|
||||
OLED_DrawXBMP(4, 6, 118, 57, ebyte_logo);
|
||||
OLED_SendBuffer();
|
||||
switch (item->state)
|
||||
{
|
||||
case MENU_UP:
|
||||
case MENU_DOWN:
|
||||
item->state = MENU_ENTER;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 菜单三级页面 模组工作模式设定 Setting > Work Mode
|
||||
*
|
||||
* @param item 指向项目状态的指针
|
||||
*/
|
||||
void work_mode_callback( xpItem item)
|
||||
{
|
||||
char value[20] = {0};
|
||||
int scrollbar_min = 0;
|
||||
int scrollbar_max = 3;
|
||||
|
||||
if (DialogScale_Show(0, 0, 127, 63))
|
||||
{
|
||||
switch (item->state)
|
||||
{
|
||||
case MENU_UP:
|
||||
(*item->data.ptr) = Draw_Scrollbar(8, 50, 111, 6, 0, scrollbar_min, scrollbar_max, 1, (*item->data.ptr));
|
||||
e32_hal_work_mode( (work_mode_t)(*item->data.ptr) );
|
||||
break;
|
||||
case MENU_DOWN:
|
||||
(*item->data.ptr) = Draw_Scrollbar(8, 50, 111, 6, 0, scrollbar_min, scrollbar_max, -1, (*item->data.ptr));
|
||||
e32_hal_work_mode( (work_mode_t)(*item->data.ptr) );
|
||||
break;
|
||||
default:
|
||||
Draw_Scrollbar(8, 50, 111, 6, 0, scrollbar_min, scrollbar_max, 0, (*item->data.ptr));
|
||||
break;
|
||||
}
|
||||
|
||||
sprintf(value, "Mode: %d ", (*item->data.ptr));
|
||||
OLED_DrawStr(8, 25, value);
|
||||
sprintf(value, "%s", mode_name[(*item->data.ptr)]);
|
||||
OLED_DrawStr(8, 40, value);
|
||||
OLED_SendBuffer();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 菜单三级页面 模组通信空速设定 Setting > Rate Mode
|
||||
*
|
||||
* @param item 指向项目状态的指针
|
||||
*/
|
||||
void rate_mode_callback( xpItem item )
|
||||
{
|
||||
char value[20] = {0};
|
||||
int scrollbar_min = 2;
|
||||
int scrollbar_max = 5;
|
||||
|
||||
|
||||
if (DialogScale_Show(0, 0, 127, 63))
|
||||
{
|
||||
switch (item->state)
|
||||
{
|
||||
case MENU_UP:
|
||||
(*item->data.ptr) = Draw_Scrollbar(8, 50, 111, 6, 0, scrollbar_min, scrollbar_max, 1, (*item->data.ptr));
|
||||
break;
|
||||
case MENU_DOWN:
|
||||
(*item->data.ptr) = Draw_Scrollbar(8, 50, 111, 6, 0, scrollbar_min, scrollbar_max, -1, (*item->data.ptr));
|
||||
break;
|
||||
default:
|
||||
Draw_Scrollbar(8, 50, 111, 6, 0, scrollbar_min, scrollbar_max, 0, (*item->data.ptr));
|
||||
break;
|
||||
}
|
||||
|
||||
sprintf(value, "Rate: %d ", (*item->data.ptr));
|
||||
OLED_DrawStr(8, 25, value);
|
||||
|
||||
sprintf(value, "%s Kbps", rate_name[(*item->data.ptr)]);
|
||||
OLED_DrawStr(8, 40, value);
|
||||
OLED_SendBuffer();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 菜单三级页面 模组通信信道设定 Setting > Channel
|
||||
*
|
||||
* @param item 指向项目状态的指针
|
||||
*/
|
||||
void channel_callback( xpItem item)
|
||||
{
|
||||
char value[20] = {0};
|
||||
int scrollbar_min = 0;
|
||||
int scrollbar_max = 41;
|
||||
|
||||
if (DialogScale_Show(0, 0, 127, 63))
|
||||
{
|
||||
|
||||
switch (item->state)
|
||||
{
|
||||
case MENU_UP:
|
||||
(*item->data.ptr) = Draw_Scrollbar(8, 50, 111, 6, 0, scrollbar_min, scrollbar_max, 1, (*item->data.ptr));
|
||||
break;
|
||||
case MENU_DOWN:
|
||||
(*item->data.ptr) = Draw_Scrollbar(8, 50, 111, 6, 0, scrollbar_min, scrollbar_max, -1, (*item->data.ptr));
|
||||
break;
|
||||
case MENU_ENTER:
|
||||
key_set_continue( KEY_NAME_UP, false );
|
||||
key_set_continue( KEY_NAME_DOWN, false );
|
||||
break;
|
||||
default:
|
||||
Draw_Scrollbar(8, 50, 111, 6, 0, scrollbar_min, scrollbar_max, 0, (*item->data.ptr));
|
||||
key_set_continue( KEY_NAME_UP, true );
|
||||
key_set_continue( KEY_NAME_DOWN, true );
|
||||
break;
|
||||
}
|
||||
|
||||
sprintf(value, "Channel: %d ", (*item->data.ptr));
|
||||
OLED_DrawStr(8, 25, value);
|
||||
|
||||
sprintf(value, "%d MHz", ((*item->data.ptr) + 410 ));
|
||||
OLED_DrawStr(8, 40, value);
|
||||
OLED_SendBuffer();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 菜单三级页面 模组发射功率设定 Setting > TX Power
|
||||
*
|
||||
* @param item 指向项目状态的指针
|
||||
*/
|
||||
void tx_power_callback( xpItem item)
|
||||
{
|
||||
char value[20] = {0};
|
||||
int power_convert[4] = { 30, 27, 24, 21 };
|
||||
int scrollbar_min = 0;
|
||||
int scrollbar_max = 3;
|
||||
|
||||
/* 默认对应 power_convert 中的 30 */
|
||||
static int scrollbar_value = 0;
|
||||
|
||||
if (DialogScale_Show(0, 0, 127, 63))
|
||||
{
|
||||
|
||||
switch (item->state)
|
||||
{
|
||||
case MENU_UP:
|
||||
scrollbar_value = Draw_Scrollbar(8, 30, 111, 6, 0, scrollbar_min, scrollbar_max, 1, scrollbar_value);
|
||||
(*item->data.ptr) = power_convert[ scrollbar_value ];
|
||||
break;
|
||||
case MENU_DOWN:
|
||||
scrollbar_value = Draw_Scrollbar(8, 30, 111, 6, 0, scrollbar_min, scrollbar_max, -1, scrollbar_value);
|
||||
(*item->data.ptr) = power_convert[ scrollbar_value ];
|
||||
break;
|
||||
case MENU_ENTER:
|
||||
break;
|
||||
default:
|
||||
Draw_Scrollbar(8, 30, 111, 6, 0, scrollbar_min, scrollbar_max, 0, scrollbar_value);
|
||||
break;
|
||||
}
|
||||
|
||||
sprintf(value, "Power: %d dBm", (*item->data.ptr));
|
||||
OLED_DrawStr(8, 25, value);
|
||||
OLED_SendBuffer();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 菜单三级页面 模组通信测试数据发射次数设定 Setting > TX Count
|
||||
*
|
||||
* @param item 指向项目状态的指针
|
||||
*/
|
||||
void tx_count_callback( xpItem item)
|
||||
{
|
||||
char value[20] = {0};
|
||||
int scrollbar_min = 10;
|
||||
int scrollbar_max = 100;
|
||||
|
||||
if (DialogScale_Show(0, 0, 127, 63))
|
||||
{
|
||||
|
||||
switch (item->state)
|
||||
{
|
||||
case MENU_UP:
|
||||
(*item->data.ptr) = Draw_Scrollbar(8, 30, 111, 6, 0, scrollbar_min, scrollbar_max, 10, (*item->data.ptr));
|
||||
break;
|
||||
case MENU_DOWN:
|
||||
(*item->data.ptr) = Draw_Scrollbar(8, 30, 111, 6, 0, scrollbar_min, scrollbar_max, -10, (*item->data.ptr));
|
||||
break;
|
||||
default:
|
||||
Draw_Scrollbar(8, 30, 111, 6, 0, scrollbar_min, scrollbar_max, 0, (*item->data.ptr));
|
||||
break;
|
||||
}
|
||||
|
||||
sprintf(value, "Count: %d ", (*item->data.ptr));
|
||||
OLED_DrawStr(8, 25, value);
|
||||
OLED_SendBuffer();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 菜单三级页面 显示背景色设定 Setting > Back Color
|
||||
*
|
||||
* @param item 指向项目状态的指针
|
||||
*/
|
||||
void background_color_callback( xpItem item )
|
||||
{
|
||||
Set_BgColor(item->switchState);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Tx Mode 数据发送测试 构造发送数据
|
||||
*
|
||||
* @param send_count 当前发送计数
|
||||
*/
|
||||
static void tx_e32_send( int send_count )
|
||||
{
|
||||
char value[30] = {0};
|
||||
uint8_t tx_length = 0;
|
||||
|
||||
gpio_led_tx_on();
|
||||
|
||||
tx_length = sprintf( value, "TX.%03d.%03d.", user_config.tx_count , send_count );
|
||||
e32_demo_transmit( (uint8_t*)value , tx_length + 1);
|
||||
|
||||
///@note 此时并不代表已发送完成
|
||||
gpio_led_tx_off();
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Tx Mode 数据发送测试 发送过程显示
|
||||
*
|
||||
* @param send_count 当前发送计数
|
||||
*/
|
||||
static void tx_display_count( int send_count )
|
||||
{
|
||||
char value[30] = {0};
|
||||
uint8_t bg_color;
|
||||
|
||||
|
||||
/* 如果进入页面后第一次 则刷新全部显示信息 */
|
||||
if( send_count == 0 )
|
||||
{
|
||||
/* display refresh */
|
||||
bg_color = Get_BgColor();
|
||||
|
||||
OLED_ClearBuffer();
|
||||
OLED_SetDrawColor(bg_color);
|
||||
OLED_DrawBox(0, 0, 128, 64);
|
||||
OLED_SetDrawColor(bg_color^0x01);
|
||||
|
||||
sprintf(value, "Channel:%d %dMHz ",user_config.channel,(user_config.channel+410));
|
||||
OLED_DrawStr(0, Font_Size*1, value );
|
||||
|
||||
OLED_DrawLine(0, Font_Size*1+3,127,Font_Size*1+3 );
|
||||
|
||||
sprintf(value, "Rate:%sK Pwr:%ddBm", rate_name[user_config.rate_mode] ,user_config.tx_power);
|
||||
OLED_DrawStr(0, Font_Size*2+3, value);
|
||||
|
||||
OLED_DrawLine(0, Font_Size*2+6,127,Font_Size*2+6 );
|
||||
|
||||
|
||||
sprintf(value, "Tx Total :%d", user_config.tx_count);
|
||||
OLED_DrawStr(0, Font_Size*3+9, value);
|
||||
}
|
||||
|
||||
/* 如果是最后一次发送 */
|
||||
if( send_count == user_config.tx_count )
|
||||
{
|
||||
OLED_DrawStr(0, Font_Size*3+9, "Tx Done ! ");
|
||||
OLED_DrawStr(0, Font_Size*4+9, "Press DOWN button");
|
||||
}
|
||||
else
|
||||
{
|
||||
sprintf(value, "Tx Number:%d", send_count);
|
||||
OLED_DrawStr(0, Font_Size*4+9, value);
|
||||
}
|
||||
|
||||
OLED_SendBuffer();
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 菜单二级页面 模组发送测试 Tx Mode
|
||||
*
|
||||
* @param item 指向项目状态的指针
|
||||
*/
|
||||
void tx_mode_callback( xpItem item )
|
||||
{
|
||||
current_feature = FUNC_FEATURE2;
|
||||
static uint32_t send_count = 0; // 改为uint32_t防止溢出
|
||||
static tx_state_t tx_state = TX_MODE_END;
|
||||
|
||||
switch (item->state)
|
||||
{
|
||||
case MENU_UP:
|
||||
break;
|
||||
case MENU_DOWN:
|
||||
/* 按下DOWN键,触发一次发送 */
|
||||
if( tx_state == TX_MODE_SEND || tx_state == TX_MODE_WAIT )
|
||||
{
|
||||
send_count++;
|
||||
tx_display_count( send_count );
|
||||
tx_e32_send(send_count);
|
||||
}
|
||||
break;
|
||||
case MENU_ENTER:
|
||||
/* 结束 */
|
||||
tx_state = TX_MODE_END;
|
||||
|
||||
break;
|
||||
default:
|
||||
/* 开始 */
|
||||
if( tx_state == TX_MODE_END )
|
||||
{
|
||||
tx_state = TX_MODE_INIT;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
switch( tx_state )
|
||||
{
|
||||
case TX_MODE_INIT:
|
||||
tx_display_count( 0 );
|
||||
e32_demo_menu_config( &user_config );
|
||||
send_count = 0;
|
||||
tx_display_count( send_count );
|
||||
tx_state = TX_MODE_SEND;
|
||||
break;
|
||||
|
||||
case TX_MODE_SEND:
|
||||
/* 等待用户按键触发发送,不再自动发送 */
|
||||
break;
|
||||
|
||||
case TX_MODE_WAIT:
|
||||
/* 等待用户按键 */
|
||||
break;
|
||||
|
||||
case TX_MODE_END:
|
||||
current_feature = FUNC_FEATURE1;
|
||||
default:
|
||||
tx_state = TX_MODE_END;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Rx Mode 数据接收测试 显示页面初始化
|
||||
*/
|
||||
static void rx_init_display(void)
|
||||
{
|
||||
char value[30] = {0};
|
||||
uint8_t bg_color;
|
||||
|
||||
bg_color = Get_BgColor();
|
||||
|
||||
OLED_ClearBuffer();
|
||||
OLED_SetDrawColor(bg_color);
|
||||
OLED_DrawBox(0, 0, 128, 64);
|
||||
OLED_SetDrawColor(bg_color^0x01);
|
||||
|
||||
sprintf(value, "Channel:%d %dMHz ",user_config.channel,(user_config.channel+410));
|
||||
OLED_DrawStr(0, Font_Size*1, value);
|
||||
|
||||
OLED_DrawLine(0, Font_Size*1+3,127,Font_Size*1+3 );
|
||||
|
||||
sprintf(value, "Rate:%sK",rate_name[user_config.rate_mode] );
|
||||
OLED_DrawStr(0, Font_Size*2+3, value );
|
||||
|
||||
OLED_DrawLine(0, Font_Size*2+6,127,Font_Size*2+6 );
|
||||
|
||||
|
||||
OLED_SendBuffer();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Rx Mode 数据接收测试 提示光标显示
|
||||
*
|
||||
* @param state 光标状态
|
||||
*/
|
||||
static void rx_hint( hint_state_t state )
|
||||
{
|
||||
static uint8_t hint_select = 0;
|
||||
static const char *hint[3]={"= ","== ","==="};
|
||||
|
||||
switch( state )
|
||||
{
|
||||
case HINT_WAIT:
|
||||
OLED_DrawStr(100, Font_Size*2+3, hint[hint_select++] );
|
||||
if(hint_select>2)
|
||||
{
|
||||
hint_select = 0;
|
||||
}
|
||||
break;
|
||||
|
||||
case HINT_DONE:
|
||||
OLED_DrawStr(100, Font_Size*2+3, "DONE" );
|
||||
break;
|
||||
}
|
||||
|
||||
OLED_SendBuffer();
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Rx Mode 数据接收测试 无线数据包校验与数据解析
|
||||
*
|
||||
* @param buffer 执行接收数据缓存
|
||||
* @param length 接收数据长度
|
||||
* @param total_number 发送总数
|
||||
* @param current_number 当前包序号
|
||||
* @param rssi 数据包RSSI
|
||||
*/
|
||||
static bool rx_analysis( uint8_t *buffer , uint8_t length , uint32_t *total_number, uint32_t *current_number )
|
||||
{
|
||||
/* 长度至少10字节 */
|
||||
if( length < 10 )
|
||||
return false;
|
||||
|
||||
/* 帧头字符判断TX */
|
||||
if( buffer[0] != 'T' || buffer[1] != 'X' )
|
||||
return false;
|
||||
|
||||
/* 拆分出发送总计数与当前序号 */
|
||||
sscanf( ( char* )(buffer+3), "%d.%d.", total_number, current_number );
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Rx Mode 数据接收测试 接收过程显示
|
||||
*
|
||||
* @param total_number 发送总数
|
||||
* @param current_number 但钱
|
||||
* @param rssi 数据包RSSI
|
||||
* @param lost_nubmer 已丢失数据包计数
|
||||
* @param lost_percent 已丢失数据包百分比
|
||||
*/
|
||||
static void rx_mode_display( uint32_t total_number , uint32_t current_number , uint32_t lost_nubmer , uint32_t lost_percent)
|
||||
{
|
||||
char value[30] = {0};
|
||||
|
||||
sprintf(value, "Total:%d ", total_number);
|
||||
OLED_DrawStr(0, Font_Size*3+5, value);
|
||||
|
||||
sprintf(value, "Current:%d ", current_number);
|
||||
OLED_DrawStr(60, Font_Size*3+5, value);
|
||||
|
||||
sprintf(value, "Lost :%d ", lost_nubmer);
|
||||
OLED_DrawStr(0, Font_Size*4+4, value);
|
||||
|
||||
sprintf(value, "Lost P%%:%d%% ", lost_percent);
|
||||
OLED_DrawStr(60, Font_Size*4+4, value);
|
||||
|
||||
OLED_SendBuffer();
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @brief 菜单二级页面 模组通信测试数据发射次数设定 Rx Mode
|
||||
*
|
||||
* @param item 指向项目状态的指针
|
||||
*/
|
||||
void rx_mode_callback( xpItem item )
|
||||
{
|
||||
current_feature = FUNC_FEATURE2;
|
||||
static uint8_t rx_mode_buffer[255];
|
||||
static uint32_t rx_mode_length = 0;
|
||||
static rx_state_t rx_state = RX_MODE_INIT;
|
||||
static uint32_t tick_start;
|
||||
static uint32_t tx_number_record = 0;
|
||||
static uint32_t tx_total_number = 0;
|
||||
static uint32_t rx_count = 0; // 改为uint32_t防止溢出
|
||||
uint32_t tx_current_number = 0;
|
||||
|
||||
switch (item->state)
|
||||
{
|
||||
case MENU_UP:
|
||||
break;
|
||||
case MENU_DOWN:
|
||||
/* 再次开始 */
|
||||
if( rx_state == RX_MODE_WAIT )
|
||||
{
|
||||
rx_state = RX_MODE_INIT;
|
||||
}
|
||||
break;
|
||||
case MENU_ENTER:
|
||||
/* 结束 */
|
||||
rx_state = RX_MODE_END;
|
||||
|
||||
break;
|
||||
default:
|
||||
/* 开始 */
|
||||
if( rx_state == RX_MODE_END )
|
||||
{
|
||||
rx_state = RX_MODE_INIT;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
switch( rx_state )
|
||||
{
|
||||
case RX_MODE_INIT:
|
||||
rx_init_display();
|
||||
e32_demo_menu_config( &user_config );
|
||||
tick_start = HAL_GetTick();
|
||||
rx_count = 0;
|
||||
tx_number_record = 0;
|
||||
rx_state = RX_MODE_RECV;
|
||||
break;
|
||||
|
||||
case RX_MODE_RECV:
|
||||
if( uart1_check_rx_done(rx_mode_buffer, &rx_mode_length) == true)
|
||||
{
|
||||
if( rx_analysis( rx_mode_buffer , rx_mode_length , &tx_total_number, &tx_current_number ) == true )
|
||||
{
|
||||
gpio_led_rx_on();
|
||||
|
||||
/* 其他情况,可能是发送端重新开始了,需要重新计数 */
|
||||
if( tx_number_record >= tx_current_number)
|
||||
{
|
||||
rx_count = 0;
|
||||
}
|
||||
|
||||
tx_number_record = tx_current_number;
|
||||
|
||||
/* 有效接收计数 */
|
||||
rx_count++;
|
||||
|
||||
rx_mode_display(tx_total_number,tx_current_number,(tx_number_record-rx_count), ((tx_number_record-rx_count)*100/tx_number_record));
|
||||
|
||||
// 注释掉自动完成判断,持续接收
|
||||
// if( tx_current_number == tx_total_number )
|
||||
// {
|
||||
// rx_state = RX_MODE_WAIT;
|
||||
// rx_hint( HINT_DONE );
|
||||
// }
|
||||
|
||||
gpio_led_rx_off();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if( (HAL_GetTick() - tick_start) > 1000 )
|
||||
{
|
||||
tick_start = HAL_GetTick();
|
||||
rx_hint( HINT_WAIT );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
break;
|
||||
|
||||
case RX_MODE_WAIT:
|
||||
/* 接收完成,等待用户按键 */
|
||||
break;
|
||||
|
||||
case RX_MODE_END:
|
||||
current_feature = FUNC_FEATURE1;
|
||||
default:
|
||||
rx_state = RX_MODE_END;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @brief 菜单二级页面 版本信息显示 Version
|
||||
*
|
||||
* @param item 指向项目状态的指针
|
||||
*/
|
||||
void version_callback( xpItem item )
|
||||
{
|
||||
current_feature = FUNC_FEATURE2;
|
||||
char e32_buffer[30] = {0};
|
||||
uint8_t opt_length = 0;
|
||||
static version_state_t version_state = VERSION_END;
|
||||
uint8_t bg_color;
|
||||
|
||||
switch (item->state)
|
||||
{
|
||||
case MENU_UP:
|
||||
break;
|
||||
case MENU_DOWN:
|
||||
break;
|
||||
case MENU_ENTER:
|
||||
/* 离开 */
|
||||
version_state = VERSION_END;
|
||||
break;
|
||||
default:
|
||||
/* 进入 */
|
||||
if( version_state == VERSION_END )
|
||||
{
|
||||
version_state = VERSION_START;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
switch( version_state )
|
||||
{
|
||||
case VERSION_START:
|
||||
bg_color = Get_BgColor();
|
||||
|
||||
OLED_ClearBuffer();
|
||||
OLED_SetDrawColor(bg_color);
|
||||
OLED_DrawBox(0, 0, 128, 64);
|
||||
OLED_SendBuffer();
|
||||
|
||||
OLED_SetDrawColor(bg_color^0x01);
|
||||
OLED_DrawStr(0, Font_Size*1, "Model Type:");
|
||||
|
||||
e32_demo_read_device_name( e32_buffer , &opt_length );
|
||||
OLED_DrawStr(8, Font_Size*2, e32_buffer + 8);
|
||||
OLED_DrawLine(0, Font_Size*2+3,127,Font_Size*2+3 );
|
||||
|
||||
OLED_DrawStr(0, Font_Size*3+3, "Model Fireware:");
|
||||
e32_demo_read_fireware_version( e32_buffer , &opt_length );
|
||||
OLED_DrawStr(8, Font_Size*4+3, e32_buffer + 7);
|
||||
OLED_DrawLine(0, Font_Size*4+6,127,Font_Size*4+6 );
|
||||
|
||||
OLED_SendBuffer();
|
||||
|
||||
version_state = VERSION_WAIT;
|
||||
break;
|
||||
|
||||
case VERSION_WAIT:
|
||||
case VERSION_END:
|
||||
current_feature = FUNC_FEATURE1;
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 菜单二级页面 重启复位
|
||||
*
|
||||
* @param item 指向项目状态的指针
|
||||
*/
|
||||
void reset_callback( xpItem item )
|
||||
{
|
||||
NVIC_SystemReset();
|
||||
}
|
||||
32
Middlewares/MultMenu/application/application.h
Normal file
32
Middlewares/MultMenu/application/application.h
Normal file
@ -0,0 +1,32 @@
|
||||
#ifndef _APPLICATION_H
|
||||
#define _APPLICATION_H
|
||||
|
||||
#include "menu.h"
|
||||
#include "menuConfig.h"
|
||||
|
||||
typedef struct
|
||||
{
|
||||
int work_mode;
|
||||
int rate_mode;
|
||||
int channel;
|
||||
int tx_power;
|
||||
int tx_count;
|
||||
}menu_config_t;
|
||||
|
||||
extern menu_config_t user_config;
|
||||
|
||||
void logo_callback( xpItem item );
|
||||
|
||||
void work_mode_callback( xpItem item );
|
||||
void rate_mode_callback( xpItem item );
|
||||
void channel_callback( xpItem item );
|
||||
void tx_power_callback( xpItem item);
|
||||
void tx_count_callback( xpItem item);
|
||||
void background_color_callback( xpItem item );
|
||||
|
||||
void tx_mode_callback( xpItem item );
|
||||
void rx_mode_callback( xpItem item );
|
||||
void version_callback( xpItem item );
|
||||
void reset_callback( xpItem item );
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user