kopia lustrzana https://github.com/ahmetkotan/restpi
added mode selectbox and change_mode function
rodzic
ccdfc294c4
commit
dbeb8387e4
|
@ -5,4 +5,6 @@ dist/
|
|||
.DS_Store
|
||||
*.pyc
|
||||
*.sqlite3
|
||||
*.db
|
||||
*.db
|
||||
static_root/
|
||||
test.html
|
|
@ -44,3 +44,8 @@ class PinSerializer(serializers.Serializer):
|
|||
read_only=True,
|
||||
allow_null=True
|
||||
)
|
||||
|
||||
is_gpio = serializers.BooleanField(
|
||||
read_only=True,
|
||||
label="Is pin gpio?"
|
||||
)
|
||||
|
|
|
@ -1,46 +1,46 @@
|
|||
from RPi.GPIO import *
|
||||
|
||||
PINS = [
|
||||
{"physical": 1, "name": "3.3v", "mode": None, "value": None, "BCM": None},
|
||||
{"physical": 2, "name": "5v", "mode": None, "value": None, "BCM": None},
|
||||
{"physical": 3, "name": "SDA.1", "mode": None, "value": None, "BCM": 2},
|
||||
{"physical": 4, "name": "5v", "mode": None, "value": None, "BCM": None},
|
||||
{"physical": 5, "name": "SCL.1", "mode": None, "value": None, "BCM": 3},
|
||||
{"physical": 6, "name": "0v", "mode": None, "value": None, "BCM": None},
|
||||
{"physical": 7, "name": "GPIO.7", "mode": None, "value": None, "BCM": 4},
|
||||
{"physical": 8, "name": "TxD", "mode": "ALT0", "value": None, "BCM": 14},
|
||||
{"physical": 9, "name": "0v", "mode": None, "value": None, "BCM": None},
|
||||
{"physical": 10, "name": "RxD", "mode": "ALT0", "value": None, "BCM": 15},
|
||||
{"physical": 11, "name": "GPIO.0", "mode": None, "value": None, "BCM": 17},
|
||||
{"physical": 12, "name": "GPIO.1", "mode": None, "value": None, "BCM": 18},
|
||||
{"physical": 13, "name": "GPIO.2", "mode": None, "value": None, "BCM": 27},
|
||||
{"physical": 14, "name": "0v", "mode": None, "value": None, "BCM": None},
|
||||
{"physical": 15, "name": "GPIO.3", "mode": None, "value": None, "BCM": 22},
|
||||
{"physical": 16, "name": "GPIO.4", "mode": None, "value": None, "BCM": 23},
|
||||
{"physical": 17, "name": "3.3v", "mode": None, "value": None, "BCM": None},
|
||||
{"physical": 18, "name": "GPIO.5", "mode": None, "value": None, "BCM": 24},
|
||||
{"physical": 19, "name": "MOSI", "mode": None, "value": None, "BCM": 10},
|
||||
{"physical": 20, "name": "0v", "mode": None, "value": None, "BCM": None},
|
||||
{"physical": 21, "name": "MISO", "mode": None, "value": None, "BCM": 9},
|
||||
{"physical": 22, "name": "GPIO.6", "mode": None, "value": None, "BCM": 25},
|
||||
{"physical": 23, "name": "SCLK", "mode": None, "value": None, "BCM": 11},
|
||||
{"physical": 24, "name": "CE0", "mode": None, "value": None, "BCM": 8},
|
||||
{"physical": 25, "name": "0v", "mode": None, "value": None, "BCM": None},
|
||||
{"physical": 26, "name": "CE1", "mode": None, "value": None, "BCM": 7},
|
||||
{"physical": 27, "name": "SDA.0", "mode": None, "value": None, "BCM": 0},
|
||||
{"physical": 28, "name": "SCL.0", "mode": None, "value": None, "BCM": 1},
|
||||
{"physical": 29, "name": "GPIO.21", "mode": None, "value": None, "BCM": 5},
|
||||
{"physical": 30, "name": "0v", "mode": None, "value": None, "BCM": None},
|
||||
{"physical": 31, "name": "GPIO.22", "mode": None, "value": None, "BCM": 6},
|
||||
{"physical": 32, "name": "GPIO.26", "mode": None, "value": None, "BCM": 12},
|
||||
{"physical": 33, "name": "GPIO.23", "mode": None, "value": None, "BCM": 13},
|
||||
{"physical": 34, "name": "0v", "mode": None, "value": None, "BCM": None},
|
||||
{"physical": 35, "name": "GPIO.24", "mode": None, "value": None, "BCM": 19},
|
||||
{"physical": 36, "name": "GPIO.27", "mode": None, "value": None, "BCM": 16},
|
||||
{"physical": 37, "name": "GPIO.25", "mode": None, "value": None, "BCM": 26},
|
||||
{"physical": 38, "name": "GPIO.28", "mode": None, "value": None, "BCM": 20},
|
||||
{"physical": 39, "name": "0v", "mode": None, "value": None, "BCM": None},
|
||||
{"physical": 40, "name": "GPIO.29", "mode": None, "value": None, "BCM": 21},
|
||||
{"physical": 1, "name": "3.3v", "mode": None, "value": None, "BCM": None, "is_gpio": False},
|
||||
{"physical": 2, "name": "5v", "mode": None, "value": None, "BCM": None, "is_gpio": False},
|
||||
{"physical": 3, "name": "SDA.1", "mode": None, "value": None, "BCM": 2, "is_gpio": False},
|
||||
{"physical": 4, "name": "5v", "mode": None, "value": None, "BCM": None, "is_gpio": False},
|
||||
{"physical": 5, "name": "SCL.1", "mode": None, "value": None, "BCM": 3, "is_gpio": False},
|
||||
{"physical": 6, "name": "0v", "mode": None, "value": None, "BCM": None, "is_gpio": False},
|
||||
{"physical": 7, "name": "GPIO.7", "mode": None, "value": None, "BCM": 4, "is_gpio": True},
|
||||
{"physical": 8, "name": "TxD", "mode": "ALT0", "value": None, "BCM": 14, "is_gpio": False},
|
||||
{"physical": 9, "name": "0v", "mode": None, "value": None, "BCM": None, "is_gpio": False},
|
||||
{"physical": 10, "name": "RxD", "mode": "ALT0", "value": None, "BCM": 15, "is_gpio": False},
|
||||
{"physical": 11, "name": "GPIO.0", "mode": None, "value": None, "BCM": 17, "is_gpio": True},
|
||||
{"physical": 12, "name": "GPIO.1", "mode": None, "value": None, "BCM": 18, "is_gpio": True},
|
||||
{"physical": 13, "name": "GPIO.2", "mode": None, "value": None, "BCM": 27, "is_gpio": True},
|
||||
{"physical": 14, "name": "0v", "mode": None, "value": None, "BCM": None, "is_gpio": False},
|
||||
{"physical": 15, "name": "GPIO.3", "mode": None, "value": None, "BCM": 22, "is_gpio": True},
|
||||
{"physical": 16, "name": "GPIO.4", "mode": None, "value": None, "BCM": 23, "is_gpio": True},
|
||||
{"physical": 17, "name": "3.3v", "mode": None, "value": None, "BCM": None, "is_gpio": False},
|
||||
{"physical": 18, "name": "GPIO.5", "mode": None, "value": None, "BCM": 24, "is_gpio": True},
|
||||
{"physical": 19, "name": "MOSI", "mode": None, "value": None, "BCM": 10, "is_gpio": False},
|
||||
{"physical": 20, "name": "0v", "mode": None, "value": None, "BCM": None, "is_gpio": False},
|
||||
{"physical": 21, "name": "MISO", "mode": None, "value": None, "BCM": 9, "is_gpio": False},
|
||||
{"physical": 22, "name": "GPIO.6", "mode": None, "value": None, "BCM": 25, "is_gpio": True},
|
||||
{"physical": 23, "name": "SCLK", "mode": None, "value": None, "BCM": 11, "is_gpio": False},
|
||||
{"physical": 24, "name": "CE0", "mode": None, "value": None, "BCM": 8, "is_gpio": False},
|
||||
{"physical": 25, "name": "0v", "mode": None, "value": None, "BCM": None, "is_gpio": False},
|
||||
{"physical": 26, "name": "CE1", "mode": None, "value": None, "BCM": 7, "is_gpio": False},
|
||||
{"physical": 27, "name": "SDA.0", "mode": None, "value": None, "BCM": 0, "is_gpio": False},
|
||||
{"physical": 28, "name": "SCL.0", "mode": None, "value": None, "BCM": 1, "is_gpio": False},
|
||||
{"physical": 29, "name": "GPIO.21", "mode": None, "value": None, "BCM": 5, "is_gpio": True},
|
||||
{"physical": 30, "name": "0v", "mode": None, "value": None, "BCM": None, "is_gpio": False},
|
||||
{"physical": 31, "name": "GPIO.22", "mode": None, "value": None, "BCM": 6, "is_gpio": True},
|
||||
{"physical": 32, "name": "GPIO.26", "mode": None, "value": None, "BCM": 12, "is_gpio": True},
|
||||
{"physical": 33, "name": "GPIO.23", "mode": None, "value": None, "BCM": 13, "is_gpio": True},
|
||||
{"physical": 34, "name": "0v", "mode": None, "value": None, "BCM": None, "is_gpio": False},
|
||||
{"physical": 35, "name": "GPIO.24", "mode": None, "value": None, "BCM": 19, "is_gpio": True},
|
||||
{"physical": 36, "name": "GPIO.27", "mode": None, "value": None, "BCM": 16, "is_gpio": True},
|
||||
{"physical": 37, "name": "GPIO.25", "mode": None, "value": None, "BCM": 26, "is_gpio": True},
|
||||
{"physical": 38, "name": "GPIO.28", "mode": None, "value": None, "BCM": 20, "is_gpio": True},
|
||||
{"physical": 39, "name": "0v", "mode": None, "value": None, "BCM": None, "is_gpio": False},
|
||||
{"physical": 40, "name": "GPIO.29", "mode": None, "value": None, "BCM": 21, "is_gpio": True},
|
||||
]
|
||||
|
||||
BOARD_PORTS = [3, 5, 7, 8, 10, 11, 12, 13, 15, 16, 18, 19, 21, 22, 23, 24, 26, 29, 31, 32, 33, 35, 36, 37, 38, 40]
|
||||
|
|
|
@ -38,17 +38,19 @@ INSTALLED_APPS = [
|
|||
|
||||
# 3rd party
|
||||
'rest_framework',
|
||||
'tokenauth'
|
||||
'tokenauth',
|
||||
'corsheaders'
|
||||
]
|
||||
|
||||
MIDDLEWARE = [
|
||||
'django.middleware.security.SecurityMiddleware',
|
||||
'django.contrib.sessions.middleware.SessionMiddleware',
|
||||
'corsheaders.middleware.CorsMiddleware',
|
||||
'django.middleware.common.CommonMiddleware',
|
||||
'django.middleware.csrf.CsrfViewMiddleware',
|
||||
'django.contrib.auth.middleware.AuthenticationMiddleware',
|
||||
'django.contrib.messages.middleware.MessageMiddleware',
|
||||
'django.middleware.clickjacking.XFrameOptionsMiddleware',
|
||||
'django.middleware.clickjacking.XFrameOptionsMiddleware'
|
||||
]
|
||||
|
||||
ROOT_URLCONF = 'restpi.urls'
|
||||
|
@ -145,3 +147,10 @@ REST_FRAMEWORK = {
|
|||
'DEFAULT_PAGINATION_CLASS': 'rest_framework.pagination.PageNumberPagination',
|
||||
'PAGE_SIZE': 40,
|
||||
}
|
||||
|
||||
CORS_ALLOW_CREDENTIALS = True
|
||||
CORS_ORIGIN_ALLOW_ALL = True
|
||||
CORS_ORIGIN_WHITELIST = (
|
||||
'localhost',
|
||||
'http//:localhost:63342'
|
||||
)
|
|
@ -51,7 +51,7 @@ input[type="checkbox"].switch_1{
|
|||
}
|
||||
|
||||
input[type="checkbox"].switch_1:checked{
|
||||
background: #0ebeff;
|
||||
background: #0062cc;
|
||||
}
|
||||
|
||||
input[type="checkbox"].switch_1:after{
|
||||
|
@ -344,4 +344,5 @@ svg.checkbox .is_unchecked{
|
|||
transform: translateX(-190%) translateY(-30%) scale(0);
|
||||
}
|
||||
/* REF: https://bootsnipp.com/snippets/xrnNM */
|
||||
/* Switch 4 Specific Style End */
|
||||
/* Switch 4 Specific Style End */
|
||||
|
||||
|
|
|
@ -49,7 +49,22 @@ table{
|
|||
th[scope="row"]:nth-child(2n){
|
||||
border-left: 0.75rem solid black;
|
||||
}
|
||||
.table-left{
|
||||
text-align: right;
|
||||
}
|
||||
|
||||
input[type="checkbox"].switch_1 {
|
||||
font-size: 0.75rem;
|
||||
-webkit-border-radius: 0.1rem;
|
||||
-moz-border-radius: 0.1rem;
|
||||
border-radius: 0.1rem;
|
||||
}
|
||||
|
||||
.radioBtn .notActive{
|
||||
color: #3276b1;
|
||||
background-color: #fff;
|
||||
}
|
||||
.radioBtn a.btn{
|
||||
font-size: 0.5rem;
|
||||
border: 0px;
|
||||
}
|
|
@ -1,19 +1,48 @@
|
|||
var app = angular.module('pinTableApp', []);
|
||||
app.controller('pinTableController', function($scope, $http) {
|
||||
$http.get("/pins/api/")
|
||||
.then(function(response) {
|
||||
var pins = response.data.results;
|
||||
var new_pinlist = [];
|
||||
var temp_pinlist = [];
|
||||
pins.forEach(function (item, index) {
|
||||
if(index % 2 == 0){
|
||||
temp_pinlist.push(item);
|
||||
}else{
|
||||
temp_pinlist.push(item);
|
||||
new_pinlist.push(temp_pinlist);
|
||||
temp_pinlist = []
|
||||
}
|
||||
});
|
||||
$scope.pins = new_pinlist;
|
||||
});
|
||||
});
|
||||
app.controller('pinTableController', function($scope, $http) {
|
||||
$scope.refresh_list = function(pin_list){
|
||||
var new_pinlist = [];
|
||||
var temp_pinlist = [];
|
||||
$scope.pinlist.forEach(function (item, index) {
|
||||
if(index % 2 == 0){
|
||||
temp_pinlist.push(item);
|
||||
}else{
|
||||
temp_pinlist.push(item);
|
||||
new_pinlist.push(temp_pinlist);
|
||||
temp_pinlist = []
|
||||
}
|
||||
});
|
||||
return new_pinlist;
|
||||
};
|
||||
|
||||
$http.get("/pins/api/")
|
||||
.then(function(response) {
|
||||
$scope.pinlist = response.data.results;
|
||||
$scope.pins = $scope.refresh_list($scope.pinlist);
|
||||
});
|
||||
|
||||
$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){
|
||||
$scope.pinlist[physical-1] = response.data.pin;
|
||||
$scope.pins = $scope.refresh_list($scope.pinlist);
|
||||
}
|
||||
})
|
||||
.catch((err) => {
|
||||
$scope.pins = $scope.refresh_list($scope.pinlist);
|
||||
})
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
$(document).ready(function() {
|
||||
$('.container').on('click', '.radioBtn a', function() {
|
||||
var sel = $(this).data('title');
|
||||
var tog = $(this).data('toggle');
|
||||
$(this).parent().next('.' + tog).prop('value', sel);
|
||||
$(this).parent().find('a[data-toggle="' + tog + '"]').not('[data-title="' + sel + '"]').removeClass('active').addClass('notActive');
|
||||
$(this).parent().find('a[data-toggle="' + tog + '"][data-title="' + sel + '"]').removeClass('notActive').addClass('active');
|
||||
});
|
||||
});
|
|
@ -5,9 +5,7 @@
|
|||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
|
||||
|
||||
<link rel="dns-prefetch" href="https://fonts.gstatic.com">
|
||||
<link href="https://fonts.googleapis.com/css?family=Raleway:300,400,600" rel="stylesheet" type="text/css">
|
||||
|
||||
<link rel="stylesheet" href="{% static 'css/bootstrap.min.css' %}">
|
||||
<link rel="stylesheet" href="{% static 'css/checkbox.css' %}">
|
||||
<link rel="stylesheet" href="{% static 'css/style.css' %}">
|
||||
|
@ -26,5 +24,6 @@
|
|||
<script src="{% static 'js/jquery-3.3.1.slim.min.js' %}"></script>
|
||||
<script src="{% static 'js/popper.min.js' %}"></script>
|
||||
<script src="{% static 'js/bootstrap.min.js' %}"></script>
|
||||
{% block extraFoot %}{% endblock %}
|
||||
</body>
|
||||
</html>
|
|
@ -1,6 +1,6 @@
|
|||
{% extends 'base.html' %}
|
||||
{% load staticfiles %}
|
||||
{% block title %}Login{% endblock %}
|
||||
{% block title %}Pins{% endblock %}
|
||||
|
||||
{% block mainarea %}
|
||||
<main class="main-bar">
|
||||
|
@ -27,12 +27,56 @@
|
|||
<tr ng-repeat="pin in pins">
|
||||
<td>{{ pin[0].BCM }}</td>
|
||||
<td>{{ pin[0].name }}</td>
|
||||
<td>{{ pin[0].hr_mode }}</td>
|
||||
<td><input type="checkbox" class="switch_1" ng-checked="pin[0].value"></td>
|
||||
<td>
|
||||
<div class="input-group">
|
||||
<div class="radioBtn btn-group" ng-show="pin[0].is_gpio">
|
||||
<a class="btn btn-primary {{ pin[0].mode == 1 ? 'active' : 'notActive' }}"
|
||||
data-toggle="happy"
|
||||
data-title="I"
|
||||
ng-click="change_mode(pin[0].physical, 1)"
|
||||
>IN</a>
|
||||
|
||||
<a class="btn btn-primary {{ pin[0].mode == 0 ? 'active' : 'notActive' }}"
|
||||
data-toggle="happy"
|
||||
data-title="O"
|
||||
ng-click="change_mode(pin[0].physical, 0)"
|
||||
>OUT</a>
|
||||
</div>
|
||||
</div>
|
||||
</td>
|
||||
<td>
|
||||
<input type="checkbox" class="switch_1"
|
||||
ng-checked="pin[0].value"
|
||||
ng-disabled="pin[0].mode != 0"
|
||||
ng-show="pin[0].value != null"
|
||||
>
|
||||
</td>
|
||||
<th scope="row" class="text-right">{{ pin[0].physical }}</th>
|
||||
|
||||
<th scope="row">{{ pin[1].physical }}</th>
|
||||
<td><input type="checkbox" class="switch_1" ng-checked="pin[1].value"></td>
|
||||
<td>{{ pin[1].hr_mode }}</td>
|
||||
<td>
|
||||
<input type="checkbox" class="switch_1"
|
||||
ng-checked="pin[1].value"
|
||||
ng-disabled="pin[1].mode != 0"
|
||||
ng-show="pin[1].value != null"
|
||||
>
|
||||
</td>
|
||||
<td>
|
||||
<div class="radioBtn btn-group" ng-show="pin[1].is_gpio">
|
||||
<a class="btn btn-primary {{ pin[1].mode == 1 ? 'active' : 'notActive' }}"
|
||||
data-toggle="happy"
|
||||
data-title="I"
|
||||
ng-click="change_mode(pin[1].physical, 1)"
|
||||
>IN</a>
|
||||
|
||||
<a class="btn btn-primary {{ pin[1].mode == 0 ? 'active' : 'notActive' }}"
|
||||
data-toggle="happy"
|
||||
data-title="O"
|
||||
ng-click="change_mode(pin[1].physical, 0)"
|
||||
>OUT</a>
|
||||
</div>
|
||||
</div>
|
||||
</td>
|
||||
<td>{{ pin[1].name }}</td>
|
||||
<td>{{ pin[1].BCM }}</td>
|
||||
</tr>
|
||||
|
@ -43,5 +87,9 @@
|
|||
</div>
|
||||
</div>
|
||||
</main>
|
||||
|
||||
|
||||
{% endblock %}
|
||||
{% block extraFoot %}
|
||||
<script src="{% static 'js/pintable.js' %}"></script>
|
||||
{% endblock %}
|
Ładowanie…
Reference in New Issue