RBE1001Lib
WebPage.h
Go to the documentation of this file.
1 #pragma once
2 #include <Arduino.h>
3 #include <WebServer.h>
4 #include "Motor.h"
5 #define labelbuflen 256
6 #define valbuflen (sizeof(float)*3)
7 typedef struct _JoyData {
8  float xpos;
9  float ypos;
10  float angle;
11  float mag;
12 } JoyData;
13 
14 
15 
16 typedef struct _telemetryValue {
17  String name;
18  float value; // the value
19  bool used; // Slot in use flag
20  bool valueDirty; // Slot has new data flag
21  bool labelDirty;
22  uint8_t *buffer;
24 
25 #define numSliders 4
26 #define numValues 30
27 #define labelBufferSize 512
28 
29 class WebPage{
30 public:
31  WebPage();
32  void initalize();
33 
34  bool updatePID=true;
35  float getSliderValue(uint32_t number);
36  JoyData *getJoystickData();
37  float getJoystickAngle();
38  float getJoystickMagnitude();
39  float getJoystickX();
40  float getJoystickY();
41  void setSliderValue(uint32_t number, float value);
42  void setJoystickValue(float xpos, float ypos, float angle, float mag);
43  void setValue(String name, float data);
44  void newButton(String url, void (*handler)(String), String label,
45  String description);
46 
47  bool SendAllValues();
48  bool SendAllLabels();
49  float sliders[numSliders];
51  int numValuesUsed=0;
52 
53  void valueChanged(String name, float value);
54 
55 
57  uint32_t txPacketCount = 0;
58  uint32_t rxPacketCount = 0;
59  TaskHandle_t updateTaskHandle;
60  TaskHandle_t packetTaskHandle;
61  uint32_t motor_count;
62  void sendValueUpdate(uint32_t index,uint8_t *buffer);
63  void sendLabelUpdate(uint32_t index,uint8_t *buffer);
64 
65 
66  void printToWebConsole(String data);
67  void markAllDirty();
68  bool dirtyLabels();
69  bool dirtyValues();
70 
71  bool sendHeartbeat();
72  void setHeartbeatUUID(uint32_t uuid);
73 
74  void UpdatePIDValues(uint32_t motor,float p, float i, float d);
75  void UpdateSetpoint(uint32_t motor, float setpoint);
76 
77  bool SendPIDValues(uint32_t motor);
78  bool SendSetpoint(uint32_t motor);
79 
80  bool sendPacket(unsigned char* packet, uint32_t length);
81 
82  SemaphoreHandle_t valuesSem;
83 
84  /*
85  uint8_t * packetBuffer;
86  uint8_t * labelBuffer;
87  uint8_t * heartbeatBuffer;
88  uint8_t * consoleBuffer;
89  uint8_t * pidsetBuffer;
90  uint8_t * setpointsetBuffer;
91  */
92 private:
93  //int valueToSendThisLoop=0;
94  uint32_t _heartbeat_uuid=0;
95 
96 };
97 
98 
struct _telemetryValue telemetryValue
String name
Definition: WebPage.h:17
float value
Definition: WebPage.h:18
uint8_t * buffer
Definition: WebPage.h:22
float angle
Definition: WebPage.h:10
JoyData joystick
Definition: WebPage.h:56
TaskHandle_t updateTaskHandle
Definition: WebPage.h:59
float xpos
Definition: WebPage.h:8
#define numValues
Definition: WebPage.h:26
TaskHandle_t packetTaskHandle
Definition: WebPage.h:60
SemaphoreHandle_t valuesSem
Definition: WebPage.h:82
bool labelDirty
Definition: WebPage.h:21
#define numSliders
Definition: WebPage.h:25
float ypos
Definition: WebPage.h:9
uint32_t motor_count
Definition: WebPage.h:61
float mag
Definition: WebPage.h:11
bool valueDirty
Definition: WebPage.h:20
struct _JoyData JoyData