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