added change_value function

master
ahmetkotan 2019-01-31 01:50:27 +03:00
rodzic dbeb8387e4
commit 602f34a340
4 zmienionych plików z 27 dodań i 1 usunięć

Wyświetl plik

@ -11,6 +11,9 @@ def pin_physical_control(physical):
if physical > 40 and physical < 1:
raise ValidationError({"physical": "Wrong pin number."})
if physical not in settings.BOARD_PORTS:
raise ValidationError({"physical": "This pin isn't a board pin."})
def get_pin(physical):
pins = settings.PINS
@ -60,7 +63,11 @@ def write_pin_mode(physical, mode):
raise ValidationError({"mode": "Wrong mode."})
gpio.setup(physical, new_mode)
return read_pin(physical)
pin = read_pin(physical)
if mode == gpio.IN:
pin["value"] = 0
pin["hr_value"] = settings.PORT_VALUES[0]
return pin
def write_pin_value(physical, value):

Wyświetl plik

@ -46,6 +46,7 @@ class PinView(PaginationAPIView):
if not pin:
return Response({"physical": "No pin number."})
serializer = self.serializer_class(data=request.data)
serializer.is_valid(raise_exception=True)

Wyświetl plik

@ -24,6 +24,22 @@ app.controller('pinTableController', function($scope, $http) {
$scope.change_mode = function (physical, mode_code) {
var url = "/pins/api/" + physical;
$http.post(url, {mode: mode_code}, {headers: {'Content-Type': 'application/json'}})
.then(function (response) {
if(response.status == 200 && response.data.operation){
console.log(response.data.pin);
$scope.pinlist[physical-1] = response.data.pin;
$scope.pins = $scope.refresh_list($scope.pinlist);
}
})
.catch((err) => {
$scope.pins = $scope.refresh_list($scope.pinlist);
})
};
$scope.change_value = function (physical) {
var url = "/pins/api/" + physical;
var new_value = ($scope.pinlist[physical-1].value) ? 0 : 1
$http.post(url, {value: new_value}, {headers: {'Content-Type': 'application/json'}})
.then(function (response) {
if(response.status == 200 && response.data.operation){
$scope.pinlist[physical-1] = response.data.pin;

Wyświetl plik

@ -49,6 +49,7 @@
ng-checked="pin[0].value"
ng-disabled="pin[0].mode != 0"
ng-show="pin[0].value != null"
ng-click="change_value(pin[0].physical)"
>
</td>
<th scope="row" class="text-right">{{ pin[0].physical }}</th>
@ -59,6 +60,7 @@
ng-checked="pin[1].value"
ng-disabled="pin[1].mode != 0"
ng-show="pin[1].value != null"
ng-click="change_value(pin[1].physical)"
>
</td>
<td>