Klaas, Wilfried 6 anni fa
parent
commit
93f9404da0
7 ha cambiato i file con 173 aggiunte e 62 eliminazioni
  1. 12 9
      Beispiele/SimpleServo.tps
  2. 7 0
      Beispiele/blink.tps
  3. 12 0
      Beispiele/examples.json
  4. 12 0
      Beispiele/servo.tps
  5. 0 9
      Beispiele/simple_blink.tps
  6. 36 20
      ugui.lfm
  7. 94 24
      ugui.pas

+ 12 - 9
Beispiele/SimpleServo.tps

@@ -1,9 +1,12 @@
-#TPS:Willies SPS Arduino
-0x00,1,F,""
-0x01,2,8,""
-0x02,1,0,""
-0x03,2,7,""
-0x04,3,4,""
-0x05,0,0,""
-0x06,0,0,""
-0x07,0,0,""
+#TPS:Willies SPS Arduino 
+0x00,4,4,"" 
+0x01,5,1,"" 
+0x02,4,F,"" 
+0x03,7,C,"" 
+0x04,F,8,"" 
+0x05,4,0,"" 
+0x06,F,8,"" 
+0x07,2,0,"" 
+0x08,3,6,"" 
+0x09,F,F,"" 
+0x0A,0,,"" 

+ 7 - 0
Beispiele/blink.tps

@@ -0,0 +1,7 @@
+#TPS:Willies SPS Arduino
+0x00,1,5,""
+0x01,2,8,""
+0x02,1,A,""
+0x03,2,8,""
+0x04,3,4,""
+0x05,0,0,""

+ 12 - 0
Beispiele/examples.json

@@ -0,0 +1,12 @@
+{
+	"examples": [{
+			"name": "Blink",
+			"index": 1,
+			"file": "blink.tps"
+		}, {
+			"name": "Servo",
+			"index": 2,
+			"file": "servo.tps"
+		}
+	]
+}

+ 12 - 0
Beispiele/servo.tps

@@ -0,0 +1,12 @@
+#TPS:Willies SPS Arduino 
+0x00,4,4,"" 
+0x01,5,1,"" 
+0x02,4,F,"" 
+0x03,7,C,"" 
+0x04,F,8,"" 
+0x05,4,0,"" 
+0x06,F,8,"" 
+0x07,2,0,"" 
+0x08,3,6,"" 
+0x09,F,F,"" 
+0x0A,0,,"" 

+ 0 - 9
Beispiele/simple_blink.tps

@@ -1,9 +0,0 @@
-#TPS:Willies SPS Arduino
-0x00,4,0,""
-0x01,1,5,""
-0x02,2,8,""
-0x03,1,A,""
-0x04,2,8,""
-0x05,3,4,""
-0x06,0,0,""
-0x07,0,0,""

+ 36 - 20
ugui.lfm

@@ -720,43 +720,43 @@ object Form1: TForm1
       ShowHint = True
     end
     object ToolButton2: TToolButton
-      Left = 49
+      Left = 71
       Top = 2
       Action = acFileOpen
     end
     object ToolButton3: TToolButton
-      Left = 73
+      Left = 95
       Top = 2
       Action = acFileSave
       Caption = 'ID_SAVE'
     end
     object ToolButton4: TToolButton
-      Left = 233
+      Left = 255
       Height = 22
       Top = 2
       Caption = 'ToolButton4'
       Style = tbsSeparator
     end
     object ToolButton6: TToolButton
-      Left = 265
+      Left = 287
       Top = 2
       Action = acNextStep
       Caption = 'ID_EXEC_NEXT'
     end
     object ToolButton7: TToolButton
-      Left = 289
+      Left = 311
       Top = 2
       Action = acStop
       Caption = 'ID_EXEC_STOP'
     end
     object ToolButton5: TToolButton
-      Left = 313
+      Left = 335
       Top = 2
       Action = acDebug
       Caption = 'ID_EXEC_DEBUG'
     end
     object cbTPSVersion: TComboBox
-      Left = 433
+      Left = 455
       Height = 23
       Top = 2
       Width = 125
@@ -772,7 +772,7 @@ object Form1: TForm1
       TabOrder = 0
     end
     object Label3: TLabel
-      Left = 345
+      Left = 367
       Height = 15
       Top = 2
       Width = 88
@@ -782,33 +782,33 @@ object Form1: TForm1
       ParentColor = False
     end
     object ToolButton8: TToolButton
-      Left = 337
+      Left = 359
       Height = 22
       Top = 2
       Caption = 'ToolButton8'
       Style = tbsSeparator
     end
     object ToolButton9: TToolButton
-      Left = 241
+      Left = 263
       Top = 2
       Action = acThisStep
       Caption = 'ID_EXEC_STATEMENT'
     end
     object ToolButton10: TToolButton
-      Left = 161
+      Left = 183
       Top = 2
       Action = acShowHexFile
       Caption = 'ID_PRGFILE'
     end
     object ToolButton11: TToolButton
-      Left = 153
+      Left = 175
       Height = 22
       Top = 2
       Caption = 'ToolButton11'
       Style = tbsSeparator
     end
     object ToolButton12: TToolButton
-      Left = 185
+      Left = 207
       Top = 2
       Action = acUpload
       Caption = 'ID_PRGULOAD'
@@ -819,38 +819,38 @@ object Form1: TForm1
       Action = acNew
     end
     object ToolButton14: TToolButton
-      Left = 97
+      Left = 119
       Height = 22
       Top = 2
       Caption = 'ToolButton14'
       Style = tbsSeparator
     end
     object ToolButton15: TToolButton
-      Left = 105
+      Left = 127
       Top = 2
       Action = acNewRow
       Caption = 'ID_NEWLINE'
     end
     object ToolButton16: TToolButton
-      Left = 129
+      Left = 151
       Top = 2
       Action = acDeleteRow
       Caption = 'ID_DELLINE'
     end
     object ToolButton17: TToolButton
-      Left = 558
+      Left = 580
       Height = 22
       Top = 2
       Caption = 'ToolButton17'
       Style = tbsDivider
     end
     object ToolButton18: TToolButton
-      Left = 563
+      Left = 585
       Top = 2
       Action = acHelpAbout
     end
     object MCSLabel: TLabel
-      Left = 587
+      Left = 609
       Height = 22
       Top = 2
       Width = 20
@@ -861,11 +861,18 @@ object Form1: TForm1
       OnClick = MCSLabelClick
     end
     object ToolButton19: TToolButton
-      Left = 209
+      Left = 231
       Top = 2
       Action = acHexFile
       Caption = 'ID_HEXFILE'
     end
+    object ToolButton20: TToolButton
+      Left = 49
+      Top = 2
+      Caption = 'ToolButton20'
+      DropdownMenu = pmExamples
+      ImageIndex = 75
+    end
   end
   object StatusBar1: TStatusBar
     Left = 0
@@ -51922,4 +51929,13 @@ object Form1: TForm1
     left = 656
     top = 496
   end
+  object pmExamples: TPopupMenu
+    OnPopup = pmExamplesPopup
+    left = 432
+    top = 528
+    object MenuItem1: TMenuItem
+      Caption = '01-Blink'
+      OnClick = MenuItem1Click
+    end
+  end
 end

+ 94 - 24
ugui.pas

@@ -9,7 +9,8 @@ interface
 uses
   Windows, Classes, SysUtils, FileUtil, SdpoSerial, Forms, Controls, Graphics, Dialogs,
   Grids, ExtCtrls, Menus, ComCtrls, ActnList, StdActns, LCLProc, StdCtrls, Spin,
-  XMLPropStorage, uSPS, LCLType, Buttons, types, MCSWINAPI, Math, fpjson, jsonparser, Midi;
+  XMLPropStorage, uSPS, LCLType, Buttons, types, MCSWINAPI, Math,
+  fpjson, jsonparser, Midi;
 
 type
 
@@ -49,6 +50,8 @@ type
     Label5: TLabel;
     lbStack: TListBox;
     MCSLabel: TLabel;
+    MenuItem1: TMenuItem;
+    pmExamples: TPopupMenu;
     RC1: TSpinEdit;
     RC2: TSpinEdit;
     cbCommand: TComboBox;
@@ -127,6 +130,7 @@ type
     tbPreset6: TToolButton;
     tbPreset7: TToolButton;
     tbPreset8: TToolButton;
+    ToolButton20: TToolButton;
     ToolButton3: TToolButton;
     ToolButton4: TToolButton;
     ToolButton5: TToolButton;
@@ -163,13 +167,16 @@ type
     procedure FormCreate(Sender: TObject);
     procedure FormDropFiles(Sender: TObject; const FileNames: array of string);
     procedure MCSLabelClick(Sender: TObject);
+    procedure MenuItem1Click(Sender: TObject);
     procedure mnSaveClick(Sender: TObject);
+    procedure pmExamplesPopup(Sender: TObject);
     procedure Shape1Paint(Sender: TObject);
     procedure Shape2Paint(Sender: TObject);
     procedure StringGrid1EditingDone(Sender: TObject);
     procedure StringGrid1Selection(Sender: TObject; aCol, aRow: integer);
     procedure tbPreset1Click(Sender: TObject);
-    procedure tbPreset1ContextPopup(Sender: TObject; MousePos: TPoint; var Handled: boolean);
+    procedure tbPreset1ContextPopup(Sender: TObject; MousePos: TPoint;
+      var Handled: boolean);
     procedure tbResetClick(Sender: TObject);
     procedure Timer1Timer(Sender: TObject);
   private
@@ -179,6 +186,7 @@ type
     activeFile: string;
     dirty: boolean;
     lastNote: byte;
+    Examples : TStringList;
     procedure initMidi;
     procedure playNote(note: byte);
     function readString(var line: string): boolean;
@@ -214,7 +222,7 @@ var
 implementation
 
 uses MCSAbout, uTextUi, uSelectCom, MCSTools, MCSStrings, synaser,
-  MCSIO, mcsintelhex, MCSLSU, MCSIniFiles;
+  MCSIO, mcsintelhex, MCSLSU, MCSIniFiles, MCSWinHttp, luijsonutils;
 
 {$R *.lfm}
 
@@ -259,6 +267,7 @@ begin
   Timer1.Enabled := True;
   MCSLSU.MakeForm('form1', 'ID_', form1);
   initMidi;
+  Examples := TStringList.Create;
 end;
 
 procedure TForm1.initMidi;
@@ -306,11 +315,57 @@ begin
   ShExec2(self.Handle, InfoBox.AppURL);
 end;
 
+procedure TForm1.MenuItem1Click(Sender: TObject);
+var i : integer;
+begin
+  // todo
+  if (Sender is TMenuItem) then begin
+    i := TMenuItem(Sender).Tag;
+  end;
+end;
+
 procedure TForm1.mnSaveClick(Sender: TObject);
 begin
   Statusbar1.SimpleText := Sender.ClassName;
 end;
 
+procedure TForm1.pmExamplesPopup(Sender: TObject);
+var
+  i: integer;
+  myName: string;
+  myMenu: TMenuItem;
+  jsonString: string;
+  Data, JArray: TJSONData;
+  JItem: TJSONData;
+begin
+  for i := pmExamples.Items.Count - 1 downto 0 do
+  begin
+    myMenu := pmExamples.Items[i];
+    myMenu.Free;
+  end;
+  pmExamples.Items.Clear;
+  Examples.Clear;
+
+  try
+    jsonString := DownloadFile('http://wkla.no-ip.biz/down/examples.json');
+    Data := StringToJSONData(jsonString);
+    JArray := GetJSONProp(TJSONObject(Data), 'examples');
+    for i := 1 to TJSONArray(JArray).Count do
+    begin
+      JItem := TJSONArray(JArray).Items[i-1];
+      myName := GetJsonProp(TJSONObject(JItem), 'name', '');
+      myName := format('%.2d - %s', [i, myName]);
+      myMenu := TMenuItem.Create(pmExamples);
+      myMenu.Caption := myName;
+      myMenu.Tag := i;
+      myMenu.OnClick := @MenuItem1Click;
+      pmExamples.Items.Add(myMenu);
+      Examples.Add(GetJsonProp(TJSONObject(JItem), 'file', ''));
+    end;
+  except
+  end;
+end;
+
 procedure TForm1.Shape1Paint(Sender: TObject);
 var
   radius: integer;
@@ -451,8 +506,8 @@ begin
     begin
       if (StringGrid1.Cells[1, x] <> '') then
       begin
-        line := StringGrid1.Cells[0, x] + ',' + StringGrid1.Cells[1, x] + ',' +
-          StringGrid1.Cells[2, x] + ',"' + StringGrid1.Cells[4, x] + '"';
+        line := StringGrid1.Cells[0, x] + ',' + StringGrid1.Cells[1, x] +
+          ',' + StringGrid1.Cells[2, x] + ',"' + StringGrid1.Cells[4, x] + '"';
         Writeln(f, line);
       end;
     end;
@@ -720,7 +775,8 @@ begin
         tmp := tmp + '0';
       line := line + tmp;
 
-      line := line + '      ' + StringGrid1.Cells[3, x] + '   ,"' + StringGrid1.Cells[4, x] + '"';
+      line := line + '      ' + StringGrid1.Cells[3, x] + '   ,"' +
+        StringGrid1.Cells[4, x] + '"';
       list.add(line);
     end;
   end;
@@ -873,7 +929,8 @@ begin
 
       if (error) then
       begin
-        Application.MessageBox('Arduino antwortet nicht. Evtl. Arduino nicht angeschlossen oder falsche Firmware?',
+        Application.MessageBox(
+          'Arduino antwortet nicht. Evtl. Arduino nicht angeschlossen oder falsche Firmware?',
           'Keine Antwort',
           MB_OK + MB_ICONEXCLAMATION);
       end;
@@ -929,7 +986,8 @@ var
 begin
   if (dirty) then
   begin
-    i := MCSLSU.LSUAutoMsgBox('Messages', 'SAVE_CHANGES', MB_ICONQUESTION or MB_YESNOCANCEL);
+    i := MCSLSU.LSUAutoMsgBox('Messages', 'SAVE_CHANGES', MB_ICONQUESTION or
+      MB_YESNOCANCEL);
     if (i = mrYes) then
     begin
       saveFile(activeFile);
@@ -1029,7 +1087,8 @@ begin
   end
   else
   begin
-    Caption := MCSLSU.GetLSUText('form1Captions', 'ID_CAPTION', lsuCode) + ':' + ExtractFileName(activeFile);
+    Caption := MCSLSU.GetLSUText('form1Captions', 'ID_CAPTION', lsuCode) +
+      ':' + ExtractFileName(activeFile);
   end;
 
 end;
@@ -1044,7 +1103,8 @@ begin
     StringGrid1.Columns[i].Title.Caption :=
       MCSLSU.GetLSUText('form1Captions', StringGrid1.Columns[i].Title.Caption, lsuCode);
   end;
-  StringGrid1.Cells[0, 0] := MCSLSU.GetLSUText('form1Captions', 'ID_GRID_STORAGE', lsuCode);
+  StringGrid1.Cells[0, 0] := MCSLSU.GetLSUText('form1Captions',
+    'ID_GRID_STORAGE', lsuCode);
   StringGrid1.Repaint;
 end;
 
@@ -1184,7 +1244,8 @@ begin
   begin
     x := StringGrid1.Row;
     StringGrid1.Cells[3, x] :=
-      sps.getCommandText(HexToInt(StringGrid1.Cells[1, x]), HexToInt(StringGrid1.Cells[2, x]));
+      sps.getCommandText(HexToInt(StringGrid1.Cells[1, x]),
+      HexToInt(StringGrid1.Cells[2, x]));
     setDirty(True);
   end;
 end;
@@ -1237,10 +1298,14 @@ begin
   WriteIniBool(key, 'set', XMLPropStorage1.ReadBoolean(key + '.set', False), filename);
   WriteIniBool(key, 'prg', XMLPropStorage1.ReadBoolean(key + '.prg', False), filename);
   WriteIniBool(key, 'sel', XMLPropStorage1.ReadBoolean(key + '.sel', False), filename);
-  WriteIniBool(key, 'input1', XMLPropStorage1.ReadBoolean(key + '.input1', False), filename);
-  WriteIniBool(key, 'input2', XMLPropStorage1.ReadBoolean(key + '.input2', False), filename);
-  WriteIniBool(key, 'input3', XMLPropStorage1.ReadBoolean(key + '.input3', False), filename);
-  WriteIniBool(key, 'input4', XMLPropStorage1.ReadBoolean(key + '.input4', False), filename);
+  WriteIniBool(key, 'input1', XMLPropStorage1.ReadBoolean(key + '.input1', False),
+    filename);
+  WriteIniBool(key, 'input2', XMLPropStorage1.ReadBoolean(key + '.input2', False),
+    filename);
+  WriteIniBool(key, 'input3', XMLPropStorage1.ReadBoolean(key + '.input3', False),
+    filename);
+  WriteIniBool(key, 'input4', XMLPropStorage1.ReadBoolean(key + '.input4', False),
+    filename);
   WriteIniInteger(key, 'adc1', XMLPropStorage1.ReadInteger(key + '.adc1', 0), filename);
   WriteIniInteger(key, 'adc2', XMLPropStorage1.ReadInteger(key + '.adc2', 0), filename);
   WriteIniInteger(key, 'rc1', XMLPropStorage1.ReadInteger(key + '.rc1', 0), filename);
@@ -1252,10 +1317,14 @@ begin
   XMLPropStorage1.WriteBoolean(key + '.set', ReadIniBool(key, 'set', False, filename));
   XMLPropStorage1.WriteBoolean(key + '.prg', ReadIniBool(key, 'prg', False, filename));
   XMLPropStorage1.WriteBoolean(key + '.sel', ReadIniBool(key, 'sel', False, filename));
-  XMLPropStorage1.WriteBoolean(key + '.input1', ReadIniBool(key, 'input1', False, filename));
-  XMLPropStorage1.WriteBoolean(key + '.input2', ReadIniBool(key, 'input2', False, filename));
-  XMLPropStorage1.WriteBoolean(key + '.input3', ReadIniBool(key, 'input3', False, filename));
-  XMLPropStorage1.WriteBoolean(key + '.input4', ReadIniBool(key, 'input4', False, filename));
+  XMLPropStorage1.WriteBoolean(key + '.input1', ReadIniBool(key,
+    'input1', False, filename));
+  XMLPropStorage1.WriteBoolean(key + '.input2', ReadIniBool(key,
+    'input2', False, filename));
+  XMLPropStorage1.WriteBoolean(key + '.input3', ReadIniBool(key,
+    'input3', False, filename));
+  XMLPropStorage1.WriteBoolean(key + '.input4', ReadIniBool(key,
+    'input4', False, filename));
   XMLPropStorage1.WriteInteger(key + '.adc1', ReadIniInteger(key, 'adc1', 0, filename));
   XMLPropStorage1.WriteInteger(key + '.adc2', ReadIniInteger(key, 'adc2', 0, filename));
   XMLPropStorage1.WriteInteger(key + '.rc1', ReadIniInteger(key, 'rc1', 0, filename));
@@ -1302,7 +1371,8 @@ begin
   RC2.Value := XMLPropStorage1.ReadInteger(key + '.rc2', RC2.Value);
 end;
 
-procedure TForm1.tbPreset1ContextPopup(Sender: TObject; MousePos: TPoint; var Handled: boolean);
+procedure TForm1.tbPreset1ContextPopup(Sender: TObject; MousePos: TPoint;
+  var Handled: boolean);
 var
   key: string;
 begin
@@ -1372,13 +1442,12 @@ begin
   if (InfoBox.newVersion) then
   begin
     MCSLabel.Font.Color := clred;
-    MCSLabel.Hint := InfoBox.versionHint + chr($0a) + chr($0d) + MCSLSU.GetLSUText(
-      'form1Captions', 'ID_CLICK_HERE', lsuCode);
+    MCSLabel.Hint := InfoBox.versionHint + chr($0a) + chr($0d) +
+      MCSLSU.GetLSUText('form1Captions', 'ID_CLICK_HERE', lsuCode);
   end;
   MCSLabel.Caption := InfoBox.versionText;
 end;
 
-
 procedure TForm1.renumberGrid;
 var
   x, i: integer;
@@ -1392,7 +1461,8 @@ begin
     if (StringGrid1.Cells[2, x] = '') then
       StringGrid1.Cells[2, x] := '0';
     StringGrid1.Cells[3, x] :=
-      sps.getCommandText(HexToInt(StringGrid1.Cells[1, x]), HexToInt(StringGrid1.Cells[2, x]));
+      sps.getCommandText(HexToInt(StringGrid1.Cells[1, x]),
+      HexToInt(StringGrid1.Cells[2, x]));
   end;
 end;