aotrautils 0.0.1056 → 0.0.1058

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
 
2
2
 
3
- /*utils COMMONS library associated with aotra version : «1_29072022-2359 (12/10/2024-21:06:16)»*/
3
+ /*utils COMMONS library associated with aotra version : «1_29072022-2359 (12/10/2024-22:19:16)»*/
4
4
  /*-----------------------------------------------------------------------------*/
5
5
 
6
6
 
@@ -5259,7 +5259,7 @@ AOTRAUTILS_LIB_IS_LOADED=true;
5259
5259
 
5260
5260
 
5261
5261
 
5262
- /*utils CLIENT library associated with aotra version : «1_29072022-2359 (12/10/2024-21:06:16)»*/
5262
+ /*utils CLIENT library associated with aotra version : «1_29072022-2359 (12/10/2024-22:19:16)»*/
5263
5263
  /*-----------------------------------------------------------------------------*/
5264
5264
  /* ## Utility global methods in a browser (htmljs) client environment.
5265
5265
  *
@@ -12624,6 +12624,154 @@ window.createOritaMainClient=function(
12624
12624
 
12625
12625
 
12626
12626
 
12627
+
12628
+
12629
+ // SEE http://codefoster.com/pi-basicgpio/
12630
+
12631
+ const GPIO_BASE_PATH = "/sys/class/gpio";
12632
+ window.gpioUtils = {
12633
+ open: (gpioNumber, mode, doOnSuccess = null) => {
12634
+
12635
+ if (!isNumber(gpioNumber) || !contains(["in", "out"], mode)) {
12636
+ // TRACE
12637
+ lognow("ERROR : Invalid parameters : " + gpioNumber + " ; " + mode + ". Aborting.");
12638
+ return;
12639
+ }
12640
+
12641
+ const gpioFilePath = GPIO_BASE_PATH + "/gpio" + gpioNumber;
12642
+ const setDirection = () => {
12643
+ fs.writeFile(gpioFilePath + "/direction", mode + "", (error) => {
12644
+ if (error) {
12645
+ // TRACE
12646
+ lognow("ERROR : Could not set mode «" + mode + "» on pin «" + gpioNumber + "». Abording setup.", error);
12647
+ return;
12648
+ }
12649
+ if (doOnSuccess) doOnSuccess();
12650
+ });
12651
+ };
12652
+ fs.access(gpioFilePath, fs.constants.F_OK, (error) => {
12653
+ if (error) {
12654
+ // Case export file does not exists
12655
+ // In this case we export the gpio pin :
12656
+ fs.writeFile(GPIO_BASE_PATH + "/export", gpioNumber + "", (error) => {
12657
+ if (error) {
12658
+ // TRACE
12659
+ lognow("ERROR : Could not export pin «" + gpioNumber + "». Abording setup.", error);
12660
+ return;
12661
+ }
12662
+ setDirection(gpioNumber, mode, doOnSuccess);
12663
+ });
12664
+ return;
12665
+ }
12666
+ // Case export file already exists
12667
+ setDirection(gpioNumber, mode, doOnSuccess);
12668
+ });
12669
+ },
12670
+
12671
+ close: (gpioNumber, doOnSuccess = null) => {
12672
+ if (!isNumber(gpioNumber)) {
12673
+ // TRACE
12674
+ lognow("ERROR : Invalid parameter : " + gpioNumber + ". Aborting.");
12675
+ return;
12676
+ }
12677
+
12678
+ const gpioFilePath = GPIO_BASE_PATH + "/gpio" + gpioNumber;
12679
+ fs.access(gpioFilePath, fs.constants.F_OK, (error) => {
12680
+ if (error) {
12681
+ // Case export file does not exists
12682
+ // TRACE
12683
+ lognow("ERROR : Export file does not exist, could not unexport pin «" + gpioNumber + "».", error);
12684
+ return;
12685
+ }
12686
+ // Case export file already exists
12687
+ // In this case we export the gpio pin :
12688
+ fs.writeFile(GPIO_BASE_PATH + "/unexport", gpioNumber + "", (error) => {
12689
+ if (error) {
12690
+ // TRACE
12691
+ lognow("ERROR : Could not unexport pin «" + gpioNumber + "».", error);
12692
+ return;
12693
+ }
12694
+ if (doOnSuccess) doOnSuccess();
12695
+ });
12696
+ });
12697
+ },
12698
+
12699
+ write: (gpioNumber, stateNumber, doOnSuccess = null) => {
12700
+
12701
+ if (!isNumber(gpioNumber) || !contains([0, 1], stateNumber)) {
12702
+ // TRACE
12703
+ lognow("ERROR : Invalid parameter : " + gpioNumber + " ; " + stateNumber + ". Aborting.");
12704
+ return;
12705
+ }
12706
+
12707
+
12708
+ const gpioFilePath = GPIO_BASE_PATH + "/gpio" + gpioNumber;
12709
+ fs.access(gpioFilePath, fs.constants.F_OK, (error) => {
12710
+ if (error) {
12711
+ // Case export file does not exists
12712
+ // TRACE
12713
+ lognow("ERROR : Export file does not exist, cannot write «" + stateNumber + "» on pin «" + gpioNumber + "».", error);
12714
+ return;
12715
+ }
12716
+
12717
+ // DBG
12718
+ lognow("Attempting to write " + stateNumber + " on pin BCM " + gpioNumber);
12719
+
12720
+ // Case export file already exists
12721
+ // In this case we export the gpio pin :
12722
+ fs.writeFile(gpioFilePath + "/value", stateNumber + "", (error) => {
12723
+ if (error) {
12724
+ // TRACE
12725
+ lognow("ERROR : Could not write «" + stateNumber + "» on pin «" + gpioNumber + "».", error);
12726
+ return;
12727
+ }
12728
+ if (doOnSuccess) doOnSuccess();
12729
+ });
12730
+ });
12731
+ },
12732
+
12733
+ read: (gpioNumber, doOnSuccess) => {
12734
+
12735
+ if (!isNumber(gpioNumber)) {
12736
+ // TRACE
12737
+ lognow("ERROR : Invalid parameter : " + gpioNumber + ". Aborting.");
12738
+ return;
12739
+ }
12740
+
12741
+ const gpioFilePath = GPIO_BASE_PATH + "/gpio" + gpioNumber;
12742
+ fs.access(gpioFilePath, fs.constants.F_OK, (error) => {
12743
+ if (error) {
12744
+ // Case export file does not exists
12745
+ // TRACE
12746
+ lognow("ERROR : Export file does not exist, cannot read value of pin «" + gpioNumber + "».", error);
12747
+ return;
12748
+ }
12749
+
12750
+ // Case export file already exists
12751
+ // In this case we export the gpio pin :
12752
+ fs.readFile(gpioFilePath + "/value", "utf-8", (error, data) => {
12753
+
12754
+ // // DBG
12755
+ // lognow("DEBUG : read value:"+data);
12756
+
12757
+ if (error) {
12758
+ // TRACE
12759
+ lognow("ERROR : Could not write «" + stateNumber + "» on pin «" + gpioNumber + "».", error);
12760
+ return;
12761
+ }
12762
+ const value = (data + "").trim() || "0";
12763
+ doOnSuccess((value == "1"));
12764
+ });
12765
+ });
12766
+ },
12767
+
12768
+ };
12769
+
12770
+
12771
+
12772
+
12773
+
12774
+
12627
12775
  // const REFRESHING_RATE_MILLIS_AUDIO:100,
12628
12776
 
12629
12777
 
@@ -13478,7 +13626,7 @@ createOritaMicroClient=function(url, port, isNode=false, staticMicroClientIdPara
13478
13626
 
13479
13627
 
13480
13628
 
13481
- /*utils GEOMETRY library associated with aotra version : «1_29072022-2359 (12/10/2024-21:06:16)»*/
13629
+ /*utils GEOMETRY library associated with aotra version : «1_29072022-2359 (12/10/2024-22:19:16)»*/
13482
13630
  /*-----------------------------------------------------------------------------*/
13483
13631
 
13484
13632
 
@@ -14717,7 +14865,7 @@ function rayVsUnitSphereClosestPoint(p, r) {
14717
14865
  // MUST REMAIN AT THE END OF THIS LIBRARY FILE !
14718
14866
 
14719
14867
  AOTRAUTILS_GEOMETRY_LIB_IS_LOADED=true;
14720
- /*utils AI library associated with aotra version : «1_29072022-2359 (12/10/2024-21:06:16)»*/
14868
+ /*utils AI library associated with aotra version : «1_29072022-2359 (12/10/2024-22:19:16)»*/
14721
14869
  /*-----------------------------------------------------------------------------*/
14722
14870
 
14723
14871
 
@@ -14861,7 +15009,7 @@ getOpenAIAPIClient=(modelName, apiURL, agentRole, defaultPrompt)=>{
14861
15009
 
14862
15010
 
14863
15011
 
14864
- /*utils SERVER library associated with aotra version : «1_29072022-2359 (12/10/2024-21:06:16)»*/
15012
+ /*utils SERVER library associated with aotra version : «1_29072022-2359 (12/10/2024-22:19:16)»*/
14865
15013
  /*-----------------------------------------------------------------------------*/
14866
15014
 
14867
15015
 
aotrautils/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "aotrautils",
3
- "version": "0.0.1056",
3
+ "version": "0.0.1058",
4
4
  "main": "aotrautils.build.js",
5
5
  "description": "A library for vanilla javascript utils (client-side) used in aotra javascript CMS",
6
6
  "author": "Jeremie Ratomposon <info@alqemia.com> (https://alqemia.com)",