Newer
Older
import { Request, Response, NextFunction } from "express";
import { setLEDservice, getLEDservice } from "../services/gpio.service";
export function setLED(req: Request, res: Response, next: NextFunction) {
//Get wanted LED and wished value
const id: string = req.params.id;
const value = req.body["value"];
if(id != "4"){
res.status(401).json({"msg" :"LED does not exist"})
}
if(value == null || !(value === 0 || value === 1)){
res.status(401).json({"msg" : "invalid input"})
}
setLEDservice(id, value);
res.status(201).json({});
}
export function getLED(req: Request, res: Response, next: NextFunction) {
const id: string = req.params.id;
const value = getLEDservice(id);
if (value) {
res.status(200).json({ "led": "on" })
}
else {
res.status(200).json({ "led": "off" });
}
}