Вт янв 18, 2022 20:05:33
Вт янв 18, 2022 20:23:28
Вт янв 18, 2022 20:37:44
Вт янв 18, 2022 20:56:22
Вт янв 18, 2022 21:04:21
Вт янв 18, 2022 21:09:23
Вт янв 18, 2022 21:43:33
Вт янв 18, 2022 21:49:56
template<typename T, typename U>
auto min(T a, U b) { return a<b?a:b; }
Вт янв 18, 2022 23:20:17
uint8_t MenuCurent, znak = 10;
extern char send_buf [20];
char buf_char [6];
void(* on_clicks)(void);
typedef void (*StateFunc) (void);
enum {
SKROL_MENU = 1,
NUMBER_ENTRY,
};
typedef struct PROGMEM {
const char format[5]; // Имя меню
void(* on_click)(void); // Ссылка на функцию вызова обрабоки изменения значения, параметр +1 или -1)
uint8_t *param; // Ссылка на переменную значения
uint8_t max_value;
uint8_t min_value;
uint8_t key_state;
} MenuItem;
MenuItem* parent ;
MenuItem const MenuItems[] = {
{"PAR1", &Level1Item1Sub1, &znak, 10, 0, SKROL_MENU},
{"PAR2", &Level1Item1Sub1, &znak, 20, 0, NUMBER_ENTRY},
};
void main_menu (void)
{
if (button_press (KEY_UP) ) { parent = (MenuItem*) &MenuItems[0]; }
if (button_press (KEY_DOWN)){ parent = (MenuItem*) &MenuItems[1];}
strcpy_P(send_buf, MenuItems[MenuCurent].format );
znak = pgm_read_byte(parent->key_state); // тут тоже получаю фигню
// znak = (parent->key_state); // и так тоже
if (znak==NUMBER_ENTRY){LEDON ;}
else {LEDOFF ;}
//if (pgm_read_byte(parent->key_state)==SKROL_MENU){LEDOFF ;}
//on_clicks = (StateFunc) pgm_read_ptr(&MenuItems[1].on_click);
//on_clicks ();
}
void init_menu (void)
{
//parent = ((MenuItem*)pgm_read_ptr(&MenuItems[1])); // так получаю фигню
parent = ((MenuItem*)&MenuItems[1]); // так получаю правильный адрес
}
Ср янв 19, 2022 05:01:38
Ср янв 19, 2022 06:51:22
Ср янв 19, 2022 09:10:19
typedef const struct Menu_Item {
const struct Menu_Item *Next; /**< Pointer to the next menu item of this menu item */
const struct Menu_Item *Previous; /**< Pointer to the previous menu item of this menu item */
const struct Menu_Item *Parent; /**< Pointer to the parent menu item of this menu item */
const struct Menu_Item *Child; /**< Pointer to the child menu item of this menu item */
void (*SelectCallback)(void); /**< Pointer to the optional menu-specific select callback of this menu item */
void (*EnterCallback)(void); /**< Pointer to the optional menu-specific enter callback of this menu item */
const char Text[]; /**< Menu item text to pass to the menu display callback function */
} Menu_Item_t;
Ср янв 19, 2022 19:22:28
parent = ((MenuItem*)pgm_read_ptr(&MenuItems[1]));
Ср янв 19, 2022 19:57:01
я здесь на форуме выкладывал свой проект с активным использованием __flash, и как раз для меню FlexMenuRoman Solovey писал(а):а для __flash не особо
// вот так строка помещается в память программ
const __flash char str[] = "string";
// вот так создается тип-структра, которую затем будем помещать в памяти программ
typedef const __flash struct{
int data;
const __flash char *fstr; // а это указатель на строку во flash
} flash_data;
// вот массив в памяти программ, наполненный теми структурами:
const __flash flash_data array[] = {
{.data=1, .fstr = str},
{/* и так далее*/}
};
// вот так выводится строка из памяти программ
printf("%S\n", str); // как видите, никаких pgm_read_xxxx
// вот собственная функция перебора символов подобной строки
int flash_strlen(const __flash char *s){
int result = 0;
while(*s++)
result++;
return result;
}
i = flash_strlen(str);
Ср янв 19, 2022 20:14:08
Ср янв 19, 2022 20:15:35
ну, успехов в раскопкахRoman Solovey писал(а):я такой человек который хочет докопаться до истины
Ср янв 19, 2022 20:42:34
#include <avr/io.h>
#include <stdint.h>
#include <util/delay.h>
#include <avr/pgmspace.h>
int led = 5; // In port B
uint8_t (*pStateFunc) (uint8_t);
typedef uint8_t (*StateFunc) (uint8_t);
uint8_t input;
volatile uint8_t nextstate;
uint8_t doSomething(uint8_t input);
enum MENUSTATES {STATE1, STATE2};
typedef struct {
unsigned char state;
uint16_t someNumber; // Just arbitrary information
uint8_t (*pFunc) (uint8_t input);
} MENU_STATE;
const MENU_STATE menu_state[] PROGMEM = {
// state someNumber pFunc
{STATE1, 2, NULL},
{STATE2, 4, doSomething},
{0, 0, NULL}
};
uint8_t doSomething(uint8_t input) {
PORTB = PORTB | 1 << led; // Take PB5 high
_delay_ms(1000); // Wait for a second
PORTB = PORTB & ~(1 << led); // Take PB5 low
_delay_ms(1000); // Wait for a second
return STATE1;
}
void setup()
{
DDRB = DDRB | 1 << led; // Define PB5 as an output
}
void loop() {
// Get the Function
pStateFunc = (StateFunc) pgm_read_ptr(&menu_state[1].pFunc);
// Execute the Function and save the returned state
nextstate = pStateFunc(input);
}
Чт янв 20, 2022 00:14:21
Чт янв 20, 2022 08:14:03
typedef struct data_buffer {
int16_t setspeedLeft; // 2
int16_t setspeedRight; // 2
int16_t RealSpeedLeft; // 2
int16_t RealSpeedRight; // 2
int32_t StepsLeft; // 4
int32_t StepsRight; // 4
uint32_t Time; // 4
uint8_t vbat;
uint8_t sensors;
uint8_t whereami;
} __attribute__((packed)) data_buffer_t;
typedef struct slow_data {
int coordX;
int coordY;
uint segmentLength;
int nodeNum;
}
Чт янв 20, 2022 08:29:39
typedef struct data_buffer {
union{
struct {
int16_t setspeedLeft; // 2
int16_t setspeedRight; // 2
int16_t RealSpeedLeft; // 2
int16_t RealSpeedRight; // 2
};
struct{
int coordX; //2
int coordY; // 2
uint segmentLength; // 2
int nodeNum; // 2
};
};
int32_t StepsLeft; // 4
int32_t StepsRight; // 4
uint32_t Time; // 4
uint8_t vbat;
uint8_t sensors;
uint8_t whereami;
} __attribute__((packed)) data_buffer_t;