Rick Watson
5 years ago
12 changed files with 180 additions and 32 deletions
-
3data/config/demoSettings.json
-
2interface/.env.development
-
57interface/src/components/LoadingNotification.js
-
5interface/src/components/RestComponent.js
-
8interface/src/containers/SecuritySettings.js
-
68interface/src/project/DemoController.js
-
1interface/src/project/DemoInformation.js
-
1interface/src/project/ProjectMenu.js
-
7platformio.ini
-
20src/DemoProject.cpp
-
26src/DemoProject.h
-
10src/main.cpp
@ -0,0 +1,3 @@ |
|||||
|
{ |
||||
|
"blink_speed": 100 |
||||
|
} |
@ -1 +1 @@ |
|||||
REACT_APP_ENDPOINT_ROOT=http://192.168.0.19/rest/ |
|
||||
|
REACT_APP_ENDPOINT_ROOT=http://192.168.0.20/rest/ |
@ -0,0 +1,57 @@ |
|||||
|
import React from 'react'; |
||||
|
import PropTypes from 'prop-types'; |
||||
|
|
||||
|
import { makeStyles } from '@material-ui/core/styles'; |
||||
|
import Button from '@material-ui/core/Button'; |
||||
|
import LinearProgress from '@material-ui/core/LinearProgress'; |
||||
|
import Typography from '@material-ui/core/Typography'; |
||||
|
|
||||
|
const useStyles = makeStyles(theme => ({ |
||||
|
loadingSettings: { |
||||
|
margin: theme.spacing(0.5), |
||||
|
}, |
||||
|
loadingSettingsDetails: { |
||||
|
margin: theme.spacing(4), |
||||
|
textAlign: "center" |
||||
|
}, |
||||
|
button: { |
||||
|
marginRight: theme.spacing(2), |
||||
|
marginTop: theme.spacing(2), |
||||
|
} |
||||
|
})); |
||||
|
|
||||
|
export default function LoadingNotification(props) { |
||||
|
const classes = useStyles(); |
||||
|
const { fetched, errorMessage, onReset, children } = props; |
||||
|
return ( |
||||
|
<div> |
||||
|
{ |
||||
|
fetched ? |
||||
|
errorMessage ? |
||||
|
<div className={classes.loadingSettings}> |
||||
|
<Typography variant="h4" className={classes.loadingSettingsDetails}> |
||||
|
{errorMessage} |
||||
|
</Typography> |
||||
|
<Button variant="contained" color="secondary" className={classes.button} onClick={onReset}> |
||||
|
Reset |
||||
|
</Button> |
||||
|
</div> |
||||
|
: |
||||
|
children |
||||
|
: |
||||
|
<div className={classes.loadingSettings}> |
||||
|
<LinearProgress className={classes.loadingSettingsDetails} /> |
||||
|
<Typography variant="h4" className={classes.loadingSettingsDetails}> |
||||
|
Loading... |
||||
|
</Typography> |
||||
|
</div> |
||||
|
} |
||||
|
</div> |
||||
|
); |
||||
|
} |
||||
|
|
||||
|
LoadingNotification.propTypes = { |
||||
|
fetched: PropTypes.bool.isRequired, |
||||
|
onReset: PropTypes.func.isRequired, |
||||
|
errorMessage: PropTypes.string |
||||
|
}; |
@ -1,22 +1,78 @@ |
|||||
import React, { Component } from 'react'; |
import React, { Component } from 'react'; |
||||
|
|
||||
import { withStyles } from '@material-ui/core/styles'; |
|
||||
import SectionContent from '../components/SectionContent'; |
import SectionContent from '../components/SectionContent'; |
||||
|
import { restComponent } from '../components/RestComponent'; |
||||
|
import LoadingNotification from '../components/LoadingNotification'; |
||||
|
|
||||
|
import Button from '@material-ui/core/Button'; |
||||
|
import Typography from '@material-ui/core/Typography'; |
||||
|
import Slider from '@material-ui/core/Slider'; |
||||
|
import { makeStyles } from '@material-ui/core/styles'; |
||||
|
import { ValidatorForm } from 'react-material-ui-form-validator'; |
||||
|
|
||||
const styles = theme => ({ |
|
||||
|
export const DEMO_SETTINGS_ENDPOINT = process.env.REACT_APP_ENDPOINT_ROOT + "demoSettings"; |
||||
|
|
||||
}); |
|
||||
|
const valueToPercentage = (value) => `${Math.round(value / 255 * 100)}%`; |
||||
|
|
||||
class DemoController extends Component { |
class DemoController extends Component { |
||||
|
componentDidMount() { |
||||
|
this.props.loadData(); |
||||
|
} |
||||
|
|
||||
render() { |
render() { |
||||
|
const { data, fetched, errorMessage, saveData, loadData, handleValueChange } = this.props; |
||||
return ( |
return ( |
||||
<SectionContent title="Controller" titleGutter> |
<SectionContent title="Controller" titleGutter> |
||||
TODO - This will contain a form which controls the speed of the built in LED. |
|
||||
|
<LoadingNotification |
||||
|
onReset={loadData} |
||||
|
fetched={fetched} |
||||
|
errorMessage={errorMessage}> |
||||
|
<DemoControllerForm |
||||
|
demoSettings={data} |
||||
|
onReset={loadData} |
||||
|
onSubmit={saveData} |
||||
|
handleValueChange={handleValueChange} |
||||
|
/> |
||||
|
</LoadingNotification> |
||||
</SectionContent> |
</SectionContent> |
||||
) |
) |
||||
} |
} |
||||
|
} |
||||
|
|
||||
|
const useStyles = makeStyles(theme => ({ |
||||
|
button: { |
||||
|
marginRight: theme.spacing(2), |
||||
|
marginTop: theme.spacing(2), |
||||
|
}, |
||||
|
blinkSpeedLabel:{ |
||||
|
marginBottom: theme.spacing(5), |
||||
|
} |
||||
|
})); |
||||
|
|
||||
|
function DemoControllerForm(props) { |
||||
|
const { demoSettings, onSubmit, onReset, handleValueChange } = props; |
||||
|
const classes = useStyles(); |
||||
|
return ( |
||||
|
<ValidatorForm onSubmit={onSubmit}> |
||||
|
<Typography id="blink-speed-slider" className={classes.blinkSpeedLabel}> |
||||
|
Blink Speed |
||||
|
</Typography> |
||||
|
<Slider |
||||
|
value={demoSettings.blink_speed} |
||||
|
valueLabelFormat={valueToPercentage} |
||||
|
aria-labelledby="blink-speed-slider" |
||||
|
valueLabelDisplay="on" |
||||
|
min={0} |
||||
|
max={255} |
||||
|
onChange={handleValueChange('blink_speed')} |
||||
|
/> |
||||
|
<Button variant="contained" color="primary" className={classes.button} type="submit"> |
||||
|
Save |
||||
|
</Button> |
||||
|
<Button variant="contained" color="secondary" className={classes.button} onClick={onReset}> |
||||
|
Reset |
||||
|
</Button> |
||||
|
</ValidatorForm> |
||||
|
); |
||||
} |
} |
||||
|
|
||||
export default withStyles(styles)(DemoController); |
|
||||
|
export default restComponent(DEMO_SETTINGS_ENDPOINT, DemoController); |
@ -1,9 +1,25 @@ |
|||||
#include <DemoProject.h>
|
#include <DemoProject.h>
|
||||
|
|
||||
void DemoProject::begin() { |
|
||||
|
|
||||
|
void DemoProject::init(AsyncWebServer* server) { |
||||
|
AdminSettingsService::init(server); |
||||
|
pinMode(BLINK_LED, OUTPUT); |
||||
} |
} |
||||
|
|
||||
void DemoProject::loop() { |
void DemoProject::loop() { |
||||
|
unsigned delay = MAX_DELAY / 255 * (255 - _blinkSpeed); |
||||
|
unsigned long currentMillis = millis(); |
||||
|
if (!_lastBlink || (unsigned long)(currentMillis - _lastBlink) >= delay) { |
||||
|
_lastBlink = currentMillis; |
||||
|
digitalWrite(BLINK_LED, !digitalRead(BLINK_LED)); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
void DemoProject::readFromJsonObject(JsonObject& root) { |
||||
|
_blinkSpeed = root["blink_speed"] | DEFAULT_BLINK_SPEED; |
||||
} |
} |
||||
|
|
||||
|
void DemoProject::writeToJsonObject(JsonObject& root) { |
||||
|
// connection settings
|
||||
|
root["blink_speed"] = _blinkSpeed; |
||||
|
} |
||||
|
|
@ -1,22 +1,34 @@ |
|||||
#ifndef DemoProject_h |
#ifndef DemoProject_h |
||||
#define DemoProject_h |
#define DemoProject_h |
||||
|
|
||||
#include <ESPAsyncWebServer.h> |
|
||||
#include <SecurityManager.h> |
|
||||
|
#include <SettingsService.h> |
||||
|
|
||||
class DemoProject { |
|
||||
|
#define BLINK_LED 2 |
||||
|
#define MAX_DELAY 1000 |
||||
|
|
||||
|
#define DEFAULT_BLINK_SPEED 100 |
||||
|
#define DEMO_SETTINGS_FILE "/config/demoSettings.json" |
||||
|
#define DEMO_SETTINGS_PATH "/rest/demoSettings" |
||||
|
|
||||
|
class DemoProject : public AdminSettingsService { |
||||
|
|
||||
public: |
public: |
||||
|
|
||||
DemoProject(AsyncWebServer *server, SecurityManager* securityManager) : _server(server), _securityManager(securityManager) {} |
|
||||
|
DemoProject(FS* fs, SecurityManager* securityManager) : AdminSettingsService(fs, securityManager, DEMO_SETTINGS_PATH, DEMO_SETTINGS_FILE) {} |
||||
|
~DemoProject() {} |
||||
|
|
||||
void begin(); |
|
||||
|
void init(AsyncWebServer* server); |
||||
void loop(); |
void loop(); |
||||
|
|
||||
private: |
private: |
||||
|
|
||||
AsyncWebServer* _server; |
|
||||
SecurityManager* _securityManager; |
|
||||
|
unsigned long _lastBlink = 0; |
||||
|
uint8_t _blinkSpeed = 255; |
||||
|
|
||||
|
protected: |
||||
|
|
||||
|
void readFromJsonObject(JsonObject& root); |
||||
|
void writeToJsonObject(JsonObject& root); |
||||
|
|
||||
}; |
}; |
||||
|
|
||||
|
Write
Preview
Loading…
Cancel
Save
Reference in new issue