Skip to content

Commit c4c6813

Browse files
author
Matthew Matz
committed
Add GPS date/time block
1 parent e98b852 commit c4c6813

File tree

2 files changed

+121
-2
lines changed

2 files changed

+121
-2
lines changed

src/main/webapp/cdn/blockly/generators/propc/sensors.js

Lines changed: 115 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1236,6 +1236,120 @@ Blockly.propc.GPS_velocity = function () {
12361236
return [code, Blockly.propc.ORDER_ATOMIC];
12371237
};
12381238

1239+
Blockly.Blocks.GPS_date_time = {
1240+
helpUrl: Blockly.MSG_GPS_HELPURL,
1241+
init: function () {
1242+
this.setTooltip(Blockly.MSG_GPS_VELOCITY_TOOLTIP);
1243+
this.setColour(colorPalette.getColor('input'));
1244+
this.appendDummyInput()
1245+
.appendField("GPS current ")
1246+
.appendField(new Blockly.FieldDropdown([
1247+
["year", "GPS_UNIT_YEAR"],
1248+
["month", "GPS_UNIT_MONTH"],
1249+
["day", "GPS_UNIT_DAY"],
1250+
["hour", "GPS_UNIT_HOUR"],
1251+
["minute", "GPS_UNIT_MINUTE"],
1252+
["second", "GPS_UNIT_SECOND"]
1253+
], function (unit) {
1254+
var zone_label = this.sourceBlock_.getField('ZONE_LABEL');
1255+
var zone_value = this.sourceBlock_.getField('ZONE_VALUE');
1256+
if (unit === 'GPS_UNIT_HOUR') {
1257+
zone_label.setVisible(true);
1258+
zone_value.setVisible(true);
1259+
} else {
1260+
zone_label.setVisible(false);
1261+
zone_value.setVisible(false);
1262+
}
1263+
this.sourceBlock_.render();
1264+
}), "TIME_UNIT")
1265+
.appendField("time zone", 'ZONE_LABEL')
1266+
.appendField(new Blockly.FieldDropdown([
1267+
['UTC+0', '0'],
1268+
['UTC-1', '-1'],
1269+
['UTC-2', '-2'],
1270+
['UTC-3', '-3'],
1271+
['UTC-4', '-4'],
1272+
['UTC-5', '-5'],
1273+
['UTC-6', '-6'],
1274+
['UTC-7', '-7'],
1275+
['UTC-8', '-8'],
1276+
['UTC-9', '-9'],
1277+
['UTC-10', '-10'],
1278+
['UTC-11', '-11'],
1279+
['UTC-12', '-12'],
1280+
['UTC+14', '14'],
1281+
['UTC+13', '13'],
1282+
['UTC+12', '12'],
1283+
['UTC+11', '11'],
1284+
['UTC+10', '10'],
1285+
['UTC+9', '9'],
1286+
['UTC+8', '8'],
1287+
['UTC+7', '7'],
1288+
['UTC+6', '6'],
1289+
['UTC+5', '5'],
1290+
['UTC+4', '4'],
1291+
['UTC+3', '3'],
1292+
['UTC+2', '2'],
1293+
['UTC+1', '1']
1294+
]), "ZONE_VALUE");
1295+
this.setOutput(true, 'Number');
1296+
this.setNextStatement(false, null);
1297+
this.setPreviousStatement(false, null);
1298+
this.getField('ZONE_LABEL').setVisible(false);
1299+
this.getField('ZONE_VALUE').setVisible(false);
1300+
},
1301+
mutationToDom: function () {
1302+
var container = document.createElement('mutation');
1303+
container.setAttribute('unit', this.getFieldValue('TIME_UNIT'));
1304+
return container;
1305+
},
1306+
domToMutation: function (xmlElement) {
1307+
if (xmlElement.getAttribute('unit') === 'GPS_UNIT_HOUR') {
1308+
this.getField('ZONE_LABEL').setVisible(true);
1309+
this.getField('ZONE_VALUE').setVisible(true);
1310+
} else {
1311+
this.getField('ZONE_LABEL').setVisible(false);
1312+
this.getField('ZONE_VALUE').setVisible(false);
1313+
}
1314+
}
1315+
};
1316+
1317+
Blockly.propc.GPS_date_time = function () {
1318+
var time_unit = this.getFieldValue('TIME_UNIT');
1319+
var zone_unit = '0';
1320+
if(time_unit === 'GPS_UNIT_HOUR')
1321+
zone_unit = this.getFieldValue('ZONE_VALUE');
1322+
1323+
Blockly.propc.definitions_["include GPS"] = '#include "gps.h"';
1324+
1325+
var dt_defines = '#define GPS_UNIT_YEAR 1\n';
1326+
dt_defines += '#define GPS_UNIT_DAY 2\n';
1327+
dt_defines += '#define GPS_UNIT_MONTH 3\n';
1328+
dt_defines += '#define GPS_UNIT_HOUR 4\n';
1329+
dt_defines += '#define GPS_UNIT_MINUTE 5\n';
1330+
dt_defines += '#define GPS_UNIT_SECOND 6\n';
1331+
Blockly.propc.definitions_["GPS_dateTime_units"] = dt_defines;
1332+
1333+
var dt_declare = 'int gps_dateTimeByUnit(char __u, int __z);\n';
1334+
var dt_function = 'int gps_dateTimeByUnit(char __u, int __z){int __gpsTime = gps_rawTime();\n';
1335+
dt_function += 'int __gpsDate = gps_rawDate();\n';
1336+
dt_function += 'int __gpsHour = __gpsTime/10000 + __z;\nif(__gpsHour < 0) __gpsHour += 24;\n';
1337+
dt_function += 'if(__gpsHour > 23) __gpsHour -= 24;\n\nswitch (__u) {\n';
1338+
dt_function += 'case GPS_UNIT_YEAR:\nreturn __gpsDate/10000;\n';
1339+
dt_function += 'break;\ncase GPS_UNIT_MONTH:\nreturn __gpsDate/100 - (__gpsDate/10000)*100;\n';
1340+
dt_function += 'break;\ncase GPS_UNIT_DAY:\nreturn __gpsDate - (__gpsDate/100)*100;\n';
1341+
dt_function += 'break;\ncase GPS_UNIT_HOUR:\nreturn __gpsHour;\nbreak;\ncase GPS_UNIT_MINUTE:\n';
1342+
dt_function += 'return __gpsTime/100 - (__gpsTime/10000)*100;\nbreak;\ncase GPS_UNIT_SECOND:\n';
1343+
dt_function += 'return __gpsTime - (__gpsTime/100)*100;\nbreak;\ndefault:\nreturn -1;\nbreak;}}';
1344+
Blockly.propc.methods_["gps_time_func"] = dt_function;
1345+
Blockly.propc.method_declarations_["gps_time_func"] = dt_declare;
1346+
1347+
var code = 'gps_dateTimeByUnit(' + time_unit + ', ' + zone_unit + ')';
1348+
return [code, Blockly.propc.ORDER_ATOMIC];
1349+
};
1350+
1351+
1352+
12391353
// ------------------ RFID Reader Blocks ---------------------------------------
12401354
Blockly.Blocks.rfid_get = {
12411355
helpUrl: Blockly.MSG_RFID_HELPURL,
@@ -1422,7 +1536,7 @@ Blockly.propc.keypad_initialize = function () {
14221536
keyFunc += 'for(__j = 0; __j < 4; __j++) low(__keypad[__j]);\n';
14231537
keyFunc += 'high(__keypad[__k]);\nfor(__j = 4; __j < 8; __j++) {';
14241538
keyFunc += '__press = input(__keypad[__j]);\nif(__press) break;}';
1425-
keyFunc += 'if(__press) return __keyval[__k | ((__j - 4) << 2)];}}';
1539+
keyFunc += 'if(__press) return __keyval[__k | ((__j - 4) << 2)];}}';
14261540
keyFunc += 'return -1;}';
14271541

14281542
Blockly.propc.global_vars_["4x4keypad"] = keyFunc;

src/main/webapp/frame/framec.jsp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1051,7 +1051,12 @@
10511051
<block type="GPS_altitude"></block>
10521052
<block type="GPS_velocity"></block>
10531053
<block type="GPS_satsTracked"></block>
1054-
</category>
1054+
<c:choose>
1055+
<c:when test="${experimental == true}">
1056+
<block type="GPS_date_time"></block>
1057+
</c:when>
1058+
</c:choose>
1059+
</category>
10551060
<category name="<fmt:message key="category.sensor-input.fingerprint" />">
10561061
<block type="fp_scanner_init"></block>
10571062
<block type="fp_scanner_add">

0 commit comments

Comments
 (0)