kopia lustrzana https://github.com/ahmetkotan/restpi
added change_value function
rodzic
dbeb8387e4
commit
602f34a340
|
@ -11,6 +11,9 @@ def pin_physical_control(physical):
|
||||||
if physical > 40 and physical < 1:
|
if physical > 40 and physical < 1:
|
||||||
raise ValidationError({"physical": "Wrong pin number."})
|
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):
|
def get_pin(physical):
|
||||||
pins = settings.PINS
|
pins = settings.PINS
|
||||||
|
|
||||||
|
@ -60,7 +63,11 @@ def write_pin_mode(physical, mode):
|
||||||
raise ValidationError({"mode": "Wrong mode."})
|
raise ValidationError({"mode": "Wrong mode."})
|
||||||
|
|
||||||
gpio.setup(physical, new_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):
|
def write_pin_value(physical, value):
|
||||||
|
|
|
@ -46,6 +46,7 @@ class PinView(PaginationAPIView):
|
||||||
if not pin:
|
if not pin:
|
||||||
return Response({"physical": "No pin number."})
|
return Response({"physical": "No pin number."})
|
||||||
|
|
||||||
|
|
||||||
serializer = self.serializer_class(data=request.data)
|
serializer = self.serializer_class(data=request.data)
|
||||||
serializer.is_valid(raise_exception=True)
|
serializer.is_valid(raise_exception=True)
|
||||||
|
|
||||||
|
|
|
@ -24,6 +24,22 @@ app.controller('pinTableController', function($scope, $http) {
|
||||||
$scope.change_mode = function (physical, mode_code) {
|
$scope.change_mode = function (physical, mode_code) {
|
||||||
var url = "/pins/api/" + physical;
|
var url = "/pins/api/" + physical;
|
||||||
$http.post(url, {mode: mode_code}, {headers: {'Content-Type': 'application/json'}})
|
$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) {
|
.then(function (response) {
|
||||||
if(response.status == 200 && response.data.operation){
|
if(response.status == 200 && response.data.operation){
|
||||||
$scope.pinlist[physical-1] = response.data.pin;
|
$scope.pinlist[physical-1] = response.data.pin;
|
||||||
|
|
|
@ -49,6 +49,7 @@
|
||||||
ng-checked="pin[0].value"
|
ng-checked="pin[0].value"
|
||||||
ng-disabled="pin[0].mode != 0"
|
ng-disabled="pin[0].mode != 0"
|
||||||
ng-show="pin[0].value != null"
|
ng-show="pin[0].value != null"
|
||||||
|
ng-click="change_value(pin[0].physical)"
|
||||||
>
|
>
|
||||||
</td>
|
</td>
|
||||||
<th scope="row" class="text-right">{{ pin[0].physical }}</th>
|
<th scope="row" class="text-right">{{ pin[0].physical }}</th>
|
||||||
|
@ -59,6 +60,7 @@
|
||||||
ng-checked="pin[1].value"
|
ng-checked="pin[1].value"
|
||||||
ng-disabled="pin[1].mode != 0"
|
ng-disabled="pin[1].mode != 0"
|
||||||
ng-show="pin[1].value != null"
|
ng-show="pin[1].value != null"
|
||||||
|
ng-click="change_value(pin[1].physical)"
|
||||||
>
|
>
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
|
|
Ładowanie…
Reference in New Issue